Class: MDWA::DSL::EntityActions

Inherits:
Object
  • Object
show all
Defined in:
lib/mdwa/dsl/entity_actions.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(entity) ⇒ EntityActions

Returns a new instance of EntityActions.



9
10
11
12
# File 'lib/mdwa/dsl/entity_actions.rb', line 9

def initialize(entity)
  self.entity   = entity
  self.actions  = {}
end

Instance Attribute Details

#actionsObject

Returns the value of attribute actions.



7
8
9
# File 'lib/mdwa/dsl/entity_actions.rb', line 7

def actions
  @actions
end

#entityObject

Returns the value of attribute entity.



7
8
9
# File 'lib/mdwa/dsl/entity_actions.rb', line 7

def entity
  @entity
end

Instance Method Details

#clear_resource_actionsObject



60
61
62
63
64
65
66
67
68
# File 'lib/mdwa/dsl/entity_actions.rb', line 60

def clear_resource_actions
  self.actions.delete :index
  self.actions.delete :new
  self.actions.delete :edit
  self.actions.delete :show
  self.actions.delete :create
  self.actions.delete :update
  self.actions.delete :delete
end

#collection_action(name, method, request_type) ⇒ Object

Include a collection action Params: name, method = get, request_type = html



21
22
23
# File 'lib/mdwa/dsl/entity_actions.rb', line 21

def collection_action(name, method, request_type)
  self.actions[name.to_sym] = Action.new(self.entity, name.to_sym, :collection, :method => method, :request_type => request_type)
end

#collection_actionsObject



29
30
31
# File 'lib/mdwa/dsl/entity_actions.rb', line 29

def collection_actions
  actions.values.to_a.select{|a| a.collection? and !a.resource?}
end

#generate_controllerObject



41
42
43
44
45
46
47
# File 'lib/mdwa/dsl/entity_actions.rb', line 41

def generate_controller
  controller = {}
  self.actions.values.select {|a| !a.resource?}.each do |action|
    controller[action.name] = action.generate_controller
  end
  return controller
end

#generate_routesObject



33
34
35
36
37
38
39
# File 'lib/mdwa/dsl/entity_actions.rb', line 33

def generate_routes
  routes = {}
  self.actions.values.select {|a| !a.resource?}.each do |action|
    routes[action.name] = action.generate_route
  end
  return routes
end

#member_action(name, method, request_type) ⇒ Object



14
15
16
# File 'lib/mdwa/dsl/entity_actions.rb', line 14

def member_action(name, method, request_type)
  self.actions[name.to_sym] = Action.new(self.entity, name.to_sym, :member, :method => method, :request_type => request_type)
end

#member_actionsObject



25
26
27
# File 'lib/mdwa/dsl/entity_actions.rb', line 25

def member_actions
  actions.values.to_a.select{|a| a.member? and !a.resource?}
end

#set_resource_actionsObject

Returns all resource actions



50
51
52
53
54
55
56
57
58
# File 'lib/mdwa/dsl/entity_actions.rb', line 50

def set_resource_actions
  self.actions[:index]   = Action.new(self.entity, :index, :collection, :resource => true)
  self.actions[:new]     = Action.new(self.entity, :new, :collection, :resource => true)
  self.actions[:edit]    = Action.new(self.entity, :edit, :member, :resource => true)
  self.actions[:show]    = Action.new(self.entity, :show, :member, :resource => true)
  self.actions[:create]  = Action.new(self.entity, :create, :collection, :method => :post, :resource => true)
  self.actions[:update]  = Action.new(self.entity, :update, :member, :method => :put, :resource => true)
  self.actions[:delete]  = Action.new(self.entity, :delete, :member, :method => :delete, :resource => true)
end