Class: Usher::Route::Path
- Inherits:
-
Object
- Object
- Usher::Route::Path
- Defined in:
- lib/usher/route/path.rb
Instance Attribute Summary collapse
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
-
#route ⇒ Object
Returns the value of attribute route.
Instance Method Summary collapse
- #==(other_path) ⇒ Object
- #can_generate_from_keys?(keys) ⇒ Boolean
- #can_generate_from_params?(params) ⇒ Boolean
- #convert_params_array(ary) ⇒ Object
- #dynamic? ⇒ Boolean
- #dynamic_indicies ⇒ Object
- #dynamic_keys ⇒ Object
- #dynamic_map ⇒ Object
- #dynamic_parts ⇒ Object
- #dynamic_required_keys ⇒ Object
- #generate ⇒ Object
- #generate_from_hash(params = nil) ⇒ Object
-
#initialize(route, parts) ⇒ Path
constructor
A new instance of Path.
-
#merge(other_path) ⇒ Object
Merges paths for use in generation.
Constructor Details
#initialize(route, parts) ⇒ Path
Returns a new instance of Path.
8 9 10 11 12 |
# File 'lib/usher/route/path.rb', line 8 def initialize(route, parts) self.route = route self.parts = parts build_generator end |
Instance Attribute Details
#parts ⇒ Object
Returns the value of attribute parts.
6 7 8 |
# File 'lib/usher/route/path.rb', line 6 def parts @parts end |
#route ⇒ Object
Returns the value of attribute route.
5 6 7 |
# File 'lib/usher/route/path.rb', line 5 def route @route end |
Instance Method Details
#==(other_path) ⇒ Object
14 15 16 |
# File 'lib/usher/route/path.rb', line 14 def ==(other_path) other_path.is_a?(Path) ? route == other_path.route && parts == other_path.parts : nil end |
#can_generate_from_keys?(keys) ⇒ Boolean
54 55 56 57 58 |
# File 'lib/usher/route/path.rb', line 54 def can_generate_from_keys?(keys) if dynamic? (dynamic_required_keys - keys).size.zero? ? keys : nil end end |
#can_generate_from_params?(params) ⇒ Boolean
60 61 62 63 64 |
# File 'lib/usher/route/path.rb', line 60 def can_generate_from_params?(params) if route.router.consider_destination_keys? (route.destination.to_a - params.to_a).size.zero? end end |
#convert_params_array(ary) ⇒ Object
18 19 20 |
# File 'lib/usher/route/path.rb', line 18 def convert_params_array(ary) ary.empty? ? ary : dynamic_keys.zip(ary) end |
#dynamic? ⇒ Boolean
50 51 52 |
# File 'lib/usher/route/path.rb', line 50 def dynamic? @dynamic end |
#dynamic_indicies ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/usher/route/path.rb', line 22 def dynamic_indicies unless dynamic? && @dynamic_indicies @dynamic_indicies = [] parts.each_index{|i| @dynamic_indicies << i if parts[i].is_a?(Variable)} end @dynamic_indicies end |
#dynamic_keys ⇒ Object
42 43 44 |
# File 'lib/usher/route/path.rb', line 42 def dynamic_keys @dynamic_keys ||= dynamic_parts.map{|dp| dp.name} if dynamic? end |
#dynamic_map ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/usher/route/path.rb', line 34 def dynamic_map unless dynamic? && @dynamic_map @dynamic_map = {} dynamic_parts.each{|p| @dynamic_map[p.name] = p } end @dynamic_map end |
#dynamic_parts ⇒ Object
30 31 32 |
# File 'lib/usher/route/path.rb', line 30 def dynamic_parts @dynamic_parts ||= parts.values_at(*dynamic_indicies) if dynamic? end |
#dynamic_required_keys ⇒ Object
46 47 48 |
# File 'lib/usher/route/path.rb', line 46 def dynamic_required_keys @dynamic_required_keys ||= dynamic_parts.select{|dp| !dp.default_value}.map{|dp| dp.name} if dynamic? end |
#generate ⇒ Object
72 73 74 |
# File 'lib/usher/route/path.rb', line 72 def generate nil end |
#generate_from_hash(params = nil) ⇒ Object
76 77 78 |
# File 'lib/usher/route/path.rb', line 76 def generate_from_hash(params = nil) generate end |