Class: Artery::Routing::URI

Inherits:
Object
  • Object
show all
Defined in:
lib/artery/routing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arg) ⇒ URI

Returns a new instance of URI.

Raises:

  • (ArgumentError)


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

#actionObject

Returns the value of attribute action.



6
7
8
# File 'lib/artery/routing.rb', line 6

def action
  @action
end

#modelObject

Returns the value of attribute model.



6
7
8
# File 'lib/artery/routing.rb', line 6

def model
  @model
end

#pluralObject

Returns the value of attribute plural.



6
7
8
# File 'lib/artery/routing.rb', line 6

def plural
  @plural
end

#serviceObject

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

Returns:

  • (Boolean)


48
49
50
# File 'lib/artery/routing.rb', line 48

def eql?(other)
  self == other
end

#hashObject



52
53
54
# File 'lib/artery/routing.rb', line 52

def hash
  to_s.hash
end

#plural?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/artery/routing.rb', line 35

def plural?
  @plural
end

#route_modelObject



39
40
41
# File 'lib/artery/routing.rb', line 39

def route_model
  (plural? ? model.to_s.pluralize : model)
end

#to_routeObject Also known as: to_s



30
31
32
# File 'lib/artery/routing.rb', line 30

def to_route
  [@service, route_model, @action].join('.')
end