Class: ActiveScaffold::Routing::Association

Inherits:
Object
  • Object
show all
Defined in:
lib/active_scaffold/extensions/routing_mapper.rb

Direct Known Subclasses

Basic

Instance Method Summary collapse

Instance Method Details

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



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/active_scaffold/extensions/routing_mapper.rb', line 28

def call(mapper, options = {})
  actions = get_actions(ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING, options)

  mapper.collection do
    ActiveScaffold::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:collection].each do |name, type|
      mapper.match(name, via: type) if actions.include? name
    end
  end

  mapper.member do
    ActiveScaffold::Routing::ACTIVE_SCAFFOLD_ASSOCIATION_ROUTING[:member].each do |name, type|
      mapper.match(name, via: type) if actions.include? name
    end
  end
end

#default_actions(actions_hash) ⇒ Object



13
14
15
# File 'lib/active_scaffold/extensions/routing_mapper.rb', line 13

def default_actions(actions_hash)
  (actions_hash[:collection].keys + actions_hash[:member].keys).uniq
end

#get_actions(actions_hash, options) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/active_scaffold/extensions/routing_mapper.rb', line 17

def get_actions(actions_hash, options)
  default_actions = default_actions(actions_hash)
  if (only = options[:only])
    Array(only).map(&:to_sym)
  elsif (except = options[:except])
    default_actions - Array(except).map(&:to_sym)
  else
    default_actions
  end
end