Class: UserPlane::RouteConcerns::AbstractConcern

Inherits:
Object
  • Object
show all
Defined in:
lib/user_plane/route_concerns.rb

Direct Known Subclasses

AbstractNamespacedConcern, OAuthEndpoint

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AbstractConcern

Returns a new instance of AbstractConcern.



14
15
16
17
18
# File 'lib/user_plane/route_concerns.rb', line 14

def initialize(options = {})
  defaults = RouteConcerns::DEFAULTS.merge(options)
  @namespace = defaults[:namespace]
  @defaults = defaults.except(:namespace)
end

Instance Attribute Details

#concern_optionsObject

Returns the value of attribute concern_options.



11
12
13
# File 'lib/user_plane/route_concerns.rb', line 11

def concern_options
  @concern_options
end

#mapperObject

Returns the value of attribute mapper.



12
13
14
# File 'lib/user_plane/route_concerns.rb', line 12

def mapper
  @mapper
end

Instance Method Details

#call(mapper, concern_options = {}) ⇒ Object

The abstract concern should be able to handle resources having a preferred collection/resource target.



27
28
29
30
31
32
# File 'lib/user_plane/route_concerns.rb', line 27

def call(mapper, concern_options = {})
  @mapper = mapper
  @concern_options = concern_options

  build
end

#exists?(concern) ⇒ Boolean

Returns true if a particular concern exists

Returns:

  • (Boolean)


21
22
23
# File 'lib/user_plane/route_concerns.rb', line 21

def exists? concern 
  mapper.instance_variable_get('@concerns').include?(concern)
end

#options(custom_route_options = {}) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/user_plane/route_concerns.rb', line 34

def options custom_route_options={}
  resource_scope = mapper.send :resource_scope?

  if resource_scope
    @defaults.merge(@concern_options).merge(custom_route_options)
  else
    @defaults.merge(@concern_options).merge(custom_route_options).except(:on)
  end
end