Class: DeltaCloud::ActionObject
- Inherits:
-
BaseObject
- Object
- BaseObject
- DeltaCloud::ActionObject
- Defined in:
- lib/base_object.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from BaseObject
#base_name, #client, #id, #objects, #url
Instance Method Summary collapse
-
#action_trigger(action) ⇒ Object
This trigger is called right after action.
- #action_urls ⇒ Object
- #actions ⇒ Object
- #add_action_link!(id, link) ⇒ Object
- #base_method_handler ⇒ Object
-
#initialize(opts = {}, &block) ⇒ ActionObject
constructor
A new instance of ActionObject.
-
#method_handler(m, args = []) ⇒ Object
First call BaseObject method handler, then, if not method found try ActionObject handler.
Methods inherited from BaseObject
#add_collection!, #add_hwp_property!, #add_link!, #add_text!, #method_missing
Constructor Details
#initialize(opts = {}, &block) ⇒ ActionObject
Returns a new instance of ActionObject.
129 130 131 132 133 |
# File 'lib/base_object.rb', line 129 def initialize(opts={}, &block) super(opts) @action_urls = opts[:action_urls] || [] @actions = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class DeltaCloud::BaseObject
Instance Method Details
#action_trigger(action) ⇒ Object
This trigger is called right after action. This method does nothing inside ActionObject but it can be redifined and used in meta-programming
138 139 |
# File 'lib/base_object.rb', line 138 def action_trigger(action) end |
#action_urls ⇒ Object
162 163 164 |
# File 'lib/base_object.rb', line 162 def action_urls actions.collect { |a| a.last } end |
#actions ⇒ Object
155 156 157 158 159 160 |
# File 'lib/base_object.rb', line 155 def actions @objects.inject([]) do |result, item| result << [item[:rel], item[:href]] if item[:type].eql?(:action_link) result end end |
#add_action_link!(id, link) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/base_object.rb', line 141 def add_action_link!(id, link) m = { :type => :action_link, :method_name => "#{link['rel'].sanitize}!", :id => id, :href => link['href'], :rel => link['rel'].sanitize, :method => link['method'].sanitize } @objects << m @actions << [m[:rel], m[:href]] @action_urls << m[:href] end |
#base_method_handler ⇒ Object
166 |
# File 'lib/base_object.rb', line 166 alias :base_method_handler :method_handler |
#method_handler(m, args = []) ⇒ Object
First call BaseObject method handler, then, if not method found try ActionObject handler
170 171 172 173 174 175 176 177 178 179 |
# File 'lib/base_object.rb', line 170 def method_handler(m, args=[]) begin base_method_handler(m, args) rescue NoHandlerForMethod case m[:type] when :action_link then do_action(m, args) else raise NoHandlerForMethod end end end |