class PathBuilder
Public Class Methods
[](*args)
click to toggle source
# File lib/path-builder.rb, line 18 def [](*args) if @base_args @base_args += args else @base_args = args end self end
base_args()
click to toggle source
# File lib/path-builder.rb, line 29 def base_args @base_args ||= [] end
base_args=(v)
click to toggle source
# File lib/path-builder.rb, line 26 def base_args=(v) @base_args = v end
base_path()
click to toggle source
# File lib/path-builder.rb, line 15 def base_path @base_path ||= [] end
base_path=(path)
click to toggle source
# File lib/path-builder.rb, line 12 def base_path=(path) @base_path = path end
break_on_empty()
click to toggle source
# File lib/path-builder.rb, line 32 def break_on_empty @break_on_empty.nil? ? superclass.respond_to?(:break_on_empty) && superclass.break_on_empty : @break_on_empty end
break_on_empty=(v)
click to toggle source
# File lib/path-builder.rb, line 35 def break_on_empty=(v) @break_on_empty = v end
new(*segments)
click to toggle source
# File lib/path-builder.rb, line 2 def initialize(*segments) @path = self.class.base_path.dup @args = self.class.base_args.dup self.call(*segments) end
version()
click to toggle source
# File lib/path-builder.rb, line 9 def version "0.1.3" end
Public Instance Methods
+(other)
click to toggle source
# File lib/path-builder.rb, line 69 def +(other) @path += other.path! @args += other.args! self end
-(number)
click to toggle source
# File lib/path-builder.rb, line 65 def -(number) @path.pop number end
[](*args, break_on_empty: self.class.break_on_empty)
click to toggle source
# File lib/path-builder.rb, line 53 def [](*args, break_on_empty: self.class.break_on_empty) @args += args @path.map do |segment| if segment.is_a? Symbol @args.shift || (break_on_empty ? nil : segment) else segment end end.take_while{|i|i}.join('/') << '/' end
Also aliased as: to_s
args!()
click to toggle source
# File lib/path-builder.rb, line 79 def args! @args end
call(*segments)
click to toggle source
Add a segment (symbol: variable, string: static)
# File lib/path-builder.rb, line 48 def call(*segments) @path += segments.flat_map{ |s| s.split('/') } self end
inspect()
click to toggle source
# File lib/path-builder.rb, line 90 def inspect "#<#{self.class.name} /#{@path.map(&:inspect).join('/')}>" end
method_missing(segment, *args)
click to toggle source
Add a static segment (string)
# File lib/path-builder.rb, line 41 def method_missing(segment, *args) @path << segment.to_s @path += args.map{ |a| a.to_sym } self end
path!()
click to toggle source
# File lib/path-builder.rb, line 75 def path! @path end
save!(break_on_empty: nil)
click to toggle source
# File lib/path-builder.rb, line 83 def save!(break_on_empty: nil) klass = Class.new self.class klass.base_path = @path klass.break_on_empty = break_on_empty unless break_on_empty.nil? klass end