Class: MDWA::DSL::EntityActions
- Inherits:
-
Object
- Object
- MDWA::DSL::EntityActions
- Defined in:
- lib/mdwa/dsl/entity_actions.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#entity ⇒ Object
Returns the value of attribute entity.
Instance Method Summary collapse
- #clear_resource_actions ⇒ Object
-
#collection_action(name, method, request_type) ⇒ Object
Include a collection action Params: name, method = get, request_type = html.
- #collection_actions ⇒ Object
- #generate_controller ⇒ Object
- #generate_routes ⇒ Object
-
#initialize(entity) ⇒ EntityActions
constructor
A new instance of EntityActions.
- #member_action(name, method, request_type) ⇒ Object
- #member_actions ⇒ Object
-
#set_resource_actions ⇒ Object
Returns all resource actions.
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
#actions ⇒ Object
Returns the value of attribute actions.
7 8 9 |
# File 'lib/mdwa/dsl/entity_actions.rb', line 7 def actions @actions end |
#entity ⇒ Object
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_actions ⇒ Object
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_actions ⇒ Object
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_controller ⇒ Object
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_routes ⇒ Object
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_actions ⇒ Object
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_actions ⇒ Object
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 |