Class: Cathode::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/cathode/resource.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_name, params = nil, &block) ⇒ Resource

Returns a new instance of Resource.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cathode/resource.rb', line 6

def initialize(resource_name, params = nil, &block)
  require_resource_constant! resource_name

  params ||= { actions: [] }

  @name = resource_name

  Cathode.const_set "#{resource_name.to_s.camelize}Controller", Class.new(Cathode::BaseController)

  @actions = {}
  actions_to_add = params[:actions] == [:all] ? [:index, :show, :create, :update, :destroy] : params[:actions]
  actions_to_add.each do |action_name|
    action action_name
  end
  self.instance_eval &block if block_given?
  actions = @actions

  Cathode::Engine.routes.draw do
    resources resource_name, only: actions.keys
  end
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



3
4
5
# File 'lib/cathode/resource.rb', line 3

def actions
  @actions
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/cathode/resource.rb', line 3

def name
  @name
end