Module: Puffer::Extensions::Mapper::InstanceMethods

Defined in:
lib/puffer/extensions/mapper31.rb

Instance Method Summary collapse

Instance Method Details

#namespace_with_puffer(path, options = {}) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/puffer/extensions/mapper31.rb', line 43

def namespace_with_puffer path, options = {}
  namespace_without_puffer path, options do
    yield

    if ::Rails.application.routes.resources_tree.any? {|node| node.scope == @scope[:module].to_sym}
      old, @scope[:module] = @scope[:module], 'admin'
      root :to => 'dashboard#index'
      @scope[:module] = old
    end
  end
end

#resource_scope_with_puffer(resource, &block) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/puffer/extensions/mapper31.rb', line 55

def resource_scope_with_puffer resource, &block
  controller = "#{[@scope[:module], resource.controller].compact.join("/")}_controller".camelize.constantize rescue nil
  if controller && controller.puffer?
    singular = resource.is_a? ActionDispatch::Routing::Mapper::Resources::SingletonResource
    name = (singular ? resource.singular : resource.plural).to_sym

    resource_node = ::Rails.application.routes.resources_tree.append_node swallow_nil{@scope[:defaults][:puffer]},
      :name => name, :scope => @scope[:module].to_sym, :controller => controller, :singular => singular

    defaults :puffer => resource_node do
      resource_scope_without_puffer resource do
        block.call if block

        member do
          controller._members.each do |action|
            send *action.route
          end
        end

        collection do
          controller._collections.each do |action|
            send *action.route
          end
          get '/event/:fieldset/:field/:event(/:identifer)', :action => :event, :as => :event
        end
      end
    end
  else
    resource_scope_without_puffer resource, &block
  end
end