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
- #can_generate_from_keys?(keys) ⇒ Boolean
- #can_generate_from_params?(params) ⇒ Boolean
- #dynamic? ⇒ Boolean
- #dynamic_indicies ⇒ Object
- #dynamic_keys ⇒ Object
- #dynamic_map ⇒ Object
- #dynamic_parts ⇒ Object
- #dynamic_required_keys ⇒ 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 |
# File 'lib/usher/route/path.rb', line 8 def initialize(route, parts) self.route = route self.parts = parts 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
#can_generate_from_keys?(keys) ⇒ Boolean
45 46 47 48 49 |
# File 'lib/usher/route/path.rb', line 45 def can_generate_from_keys?(keys) if dynamic? (dynamic_required_keys - keys).size.zero? ? keys : nil end end |
#can_generate_from_params?(params) ⇒ Boolean
51 52 53 54 55 56 |
# File 'lib/usher/route/path.rb', line 51 def can_generate_from_params?(params) if route.router.consider_destination_keys? route.destination.to_a - params.to_a (route.destination.to_a - params.to_a).size.zero? end end |
#dynamic? ⇒ Boolean
41 42 43 |
# File 'lib/usher/route/path.rb', line 41 def dynamic? @dynamic end |
#dynamic_indicies ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/usher/route/path.rb', line 13 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
33 34 35 |
# File 'lib/usher/route/path.rb', line 33 def dynamic_keys @dynamic_keys ||= dynamic_map.keys if dynamic? end |
#dynamic_map ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/usher/route/path.rb', line 25 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
21 22 23 |
# File 'lib/usher/route/path.rb', line 21 def dynamic_parts @dynamic_parts ||= parts.values_at(*dynamic_indicies) if dynamic? end |
#dynamic_required_keys ⇒ Object
37 38 39 |
# File 'lib/usher/route/path.rb', line 37 def dynamic_required_keys @dynamic_required_keys ||= dynamic_parts.select{|dp| !dp.default_value}.map{|dp| dp.name} if dynamic? end |