Class: Objectify::Rails::Routing::ObjectifyMapper

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

Instance Method Summary collapse

Constructor Details

#initialize(rails_mapper, application = ::Rails.application, action_factory = Config::Action) ⇒ ObjectifyMapper

Returns a new instance of ObjectifyMapper.



12
13
14
15
16
17
18
# File 'lib/objectify/rails/routing.rb', line 12

def initialize(rails_mapper,
               application = ::Rails.application,
               action_factory = Config::Action)
  @rails_mapper = rails_mapper
  @application = application
  @action_factory = action_factory
end

Instance Method Details

#decorators(options) ⇒ Object



72
73
74
# File 'lib/objectify/rails/routing.rb', line 72

def decorators(options)
  @application.objectify.append_decorators(options)
end

#defaults(options) ⇒ Object



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

def defaults(options)
  @application.objectify.append_defaults(options)
end

#implementations(options) ⇒ Object



60
61
62
# File 'lib/objectify/rails/routing.rb', line 60

def implementations(options)
  @application.objectify.append_implementations(options)
end

#legacy_action(controller, actions, options) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/objectify/rails/routing.rb', line 76

def legacy_action(controller, actions, options)
  [*actions].each do |action_name|
    routing_opts = {:controller => controller,
                    :action     => action_name}
    append_action(routing_opts, controller, action_name, options)
  end
end

#match(options) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/objectify/rails/routing.rb', line 40

def match(options)
  from,to = options.detect { |k,v| k.is_a?(String) }
  resource,action = to.split("#").map(&:to_sym)
  controller = @application.objectify.objectify_controller
  objectify_options = extract_objectify_options(options)
  objectify_defaults = {"path" => from.dup}
  rails_options = merge_defaults(objectify_defaults, options)
  @rails_mapper.match rails_options.merge(from => "#{controller}#action")

  append_action(objectify_defaults, resource, action, objectify_options)
end

#policy_responders(options) ⇒ Object



56
57
58
# File 'lib/objectify/rails/routing.rb', line 56

def policy_responders(options)
  @application.objectify.append_policy_responders(options)
end

#resolvers(options) ⇒ Object



64
65
66
# File 'lib/objectify/rails/routing.rb', line 64

def resolvers(options)
  @application.objectify.append_resolvers(options)
end

#resources(*args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/objectify/rails/routing.rb', line 20

def resources(*args)
  options           = args.extract_options!
  objectify_options = extract_objectify_options(options)
  controller        = @application.objectify.objectify_controller
  rails_options     = options.merge(:controller => controller)

  args.each do |resource_name|
    objectify_defaults = {:resource => resource_name}
    merged_defaults = merge_defaults(objectify_defaults.merge(:append_action => true),
                                     rails_options)
    @rails_mapper.resources(resource_name, merged_defaults)
    RESOURCE_ACTIONS.each do |action_name|
      append_action(objectify_defaults.merge(:action => action_name),
                    resource_name,
                    action_name,
                    objectify_options)
    end
  end
end

#values(options) ⇒ Object



68
69
70
# File 'lib/objectify/rails/routing.rb', line 68

def values(options)
  @application.objectify.append_values(options)
end