Class: Artery::Routing::URI
- Inherits:
-
Object
- Object
- Artery::Routing::URI
- Defined in:
- lib/artery/routing.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#model ⇒ Object
Returns the value of attribute model.
-
#plural ⇒ Object
Returns the value of attribute plural.
-
#service ⇒ Object
Returns the value of attribute service.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Make them identical for Hash if route is identical.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(arg) ⇒ URI
constructor
A new instance of URI.
- #plural? ⇒ Boolean
- #route_model ⇒ Object
- #to_route ⇒ Object (also: #to_s)
Constructor Details
#initialize(arg) ⇒ URI
Returns a new instance of URI.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/artery/routing.rb', line 8 def initialize(arg) case arg when URI @service = arg.service @model = arg.model @action = arg.action @plural = arg.plural when String @service, model, @action = arg.split('.').map(&:to_sym) @model = model.to_s.singularize.to_sym @plural = (@model != model) when Hash @service = arg[:service] || Artery.service_name @model = arg[:model].try(:to_sym) @action = arg[:action].try(:to_sym) @plural = arg[:plural] else raise ArgumentError, 'Unknown argument format' end raise(ArgumentError, 'service and model must be provided') if @service.blank? || @model.blank? end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
6 7 8 |
# File 'lib/artery/routing.rb', line 6 def action @action end |
#model ⇒ Object
Returns the value of attribute model.
6 7 8 |
# File 'lib/artery/routing.rb', line 6 def model @model end |
#plural ⇒ Object
Returns the value of attribute plural.
6 7 8 |
# File 'lib/artery/routing.rb', line 6 def plural @plural end |
#service ⇒ Object
Returns the value of attribute service.
6 7 8 |
# File 'lib/artery/routing.rb', line 6 def service @service end |
Instance Method Details
#==(other) ⇒ Object
Make them identical for Hash if route is identical
44 45 46 |
# File 'lib/artery/routing.rb', line 44 def ==(other) to_s == other.to_s end |
#eql?(other) ⇒ Boolean
48 49 50 |
# File 'lib/artery/routing.rb', line 48 def eql?(other) self == other end |
#hash ⇒ Object
52 53 54 |
# File 'lib/artery/routing.rb', line 52 def hash to_s.hash end |
#plural? ⇒ Boolean
35 36 37 |
# File 'lib/artery/routing.rb', line 35 def plural? @plural end |
#route_model ⇒ Object
39 40 41 |
# File 'lib/artery/routing.rb', line 39 def route_model (plural? ? model.to_s.pluralize : model) end |
#to_route ⇒ Object Also known as: to_s
30 31 32 |
# File 'lib/artery/routing.rb', line 30 def to_route [@service, route_model, @action].join('.') end |