Class: Aygabtu::RouteWrapper
- Inherits:
-
Object
- Object
- Aygabtu::RouteWrapper
- Defined in:
- lib/aygabtu/route_wrapper.rb
Instance Attribute Summary collapse
-
#journey_route ⇒ Object
readonly
Wraps a Journey route.
-
#marks ⇒ Object
readonly
Returns the value of attribute marks.
Instance Method Summary collapse
- #action ⇒ Object
- #conflicting_marks(mark) ⇒ Object
- #controller ⇒ Object
- #controller_basename ⇒ Object
- #controller_namespace ⇒ Object
- #format(visiting_data) ⇒ Object
-
#generate_url_with_proper_parameters(parameters) ⇒ Object
this assumes parameters.keys == required_parts.
- #get? ⇒ Boolean
-
#initialize(journey_route) ⇒ RouteWrapper
constructor
A new instance of RouteWrapper.
- #inspect ⇒ Object
- #internal? ⇒ Boolean
- #name ⇒ Object
- #really_required_keys ⇒ Object
-
#required_parts ⇒ Object
array of parameter names (symbols) required for generating URL.
Constructor Details
#initialize(journey_route) ⇒ RouteWrapper
Returns a new instance of RouteWrapper.
7 8 9 10 11 |
# File 'lib/aygabtu/route_wrapper.rb', line 7 def initialize(journey_route) @journey_route = journey_route @marks = [] end |
Instance Attribute Details
#journey_route ⇒ Object (readonly)
Wraps a Journey route
5 6 7 |
# File 'lib/aygabtu/route_wrapper.rb', line 5 def journey_route @journey_route end |
#marks ⇒ Object (readonly)
Returns the value of attribute marks.
17 18 19 |
# File 'lib/aygabtu/route_wrapper.rb', line 17 def marks @marks end |
Instance Method Details
#action ⇒ Object
50 51 52 53 |
# File 'lib/aygabtu/route_wrapper.rb', line 50 def action # sanity condition needed for Rails 4.1 @journey_route.requirements[:action] if controller end |
#conflicting_marks(mark) ⇒ Object
13 14 15 |
# File 'lib/aygabtu/route_wrapper.rb', line 13 def conflicting_marks(mark) @marks.select { |m| m.conflicting?(mark) } end |
#controller ⇒ Object
33 34 35 |
# File 'lib/aygabtu/route_wrapper.rb', line 33 def controller @journey_route.requirements[:controller] end |
#controller_basename ⇒ Object
46 47 48 |
# File 'lib/aygabtu/route_wrapper.rb', line 46 def controller_basename Pathname(controller).basename.to_s if controller end |
#controller_namespace ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/aygabtu/route_wrapper.rb', line 37 def controller_namespace return @controller_namespace if defined? @controller_namespace return @controller_namespace = nil unless controller @controller_namespace = Pathname('/').join(controller).dirname.to_s[1..-1] @controller_namespace = nil if @controller_namespace.empty? @controller_namespace end |
#format(visiting_data) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/aygabtu/route_wrapper.rb', line 76 def format(visiting_data) visiting_data = visiting_data.stringify_keys query_data = visiting_data.except(*@journey_route.parts.map(&:to_s)) visiting_data = visiting_data.except(*query_data.keys) visiting_data.symbolize_keys! # format expects symbols, but we deal with strings in all other places path = @journey_route.format(visiting_data) if query_data.empty? path else "#{path}?#{Rack::Utils.build_query(query_data)}" end end |
#generate_url_with_proper_parameters(parameters) ⇒ Object
this assumes parameters.keys == required_parts
64 65 66 |
# File 'lib/aygabtu/route_wrapper.rb', line 64 def generate_url_with_proper_parameters(parameters) @journey_route.format(parameters) end |
#get? ⇒ Boolean
19 20 21 |
# File 'lib/aygabtu/route_wrapper.rb', line 19 def get? @journey_route.verb.match('GET') end |
#inspect ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/aygabtu/route_wrapper.rb', line 68 def inspect if @journey_route.name "route named :#{@journey_route.name}" else "route matching #{@journey_route.path.to_regexp.inspect}" end end |
#internal? ⇒ Boolean
23 24 25 26 |
# File 'lib/aygabtu/route_wrapper.rb', line 23 def internal? # this particular route is hard to filter by any sensible criterion @journey_route.path.to_regexp == %r{\A/assets} end |
#name ⇒ Object
55 56 57 |
# File 'lib/aygabtu/route_wrapper.rb', line 55 def name @journey_route.name.to_s if @journey_route.name end |
#really_required_keys ⇒ Object
92 93 94 |
# File 'lib/aygabtu/route_wrapper.rb', line 92 def really_required_keys @journey_route.path.required_names end |
#required_parts ⇒ Object
array of parameter names (symbols) required for generating URL
29 30 31 |
# File 'lib/aygabtu/route_wrapper.rb', line 29 def required_parts @journey_route.required_parts end |