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.
- #method_missing(name, *args) ⇒ Object
- #original_method_missing ⇒ Object
Methods inherited from BaseObject
#add_addresses!, #add_authentication!, #add_blob!, #add_collection!, #add_hwp_property!, #add_link!, #add_provider!, #add_text!
Constructor Details
#initialize(opts = {}, &block) ⇒ ActionObject
Returns a new instance of ActionObject.
190 191 192 193 194 |
# File 'lib/base_object.rb', line 190 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
#method_missing(name, *args) ⇒ Object
244 245 246 247 248 249 |
# File 'lib/base_object.rb', line 244 def method_missing(name, *args) if name.to_s =~ /^has_(\w+)\?$/ return actions.any? { |a| a[0] == $1 } end original_method_missing(name, args) end |
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
199 200 |
# File 'lib/base_object.rb', line 199 def action_trigger(action) end |
#action_urls ⇒ Object
223 224 225 |
# File 'lib/base_object.rb', line 223 def action_urls actions.collect { |a| a.last } end |
#actions ⇒ Object
216 217 218 219 220 221 |
# File 'lib/base_object.rb', line 216 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
202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/base_object.rb', line 202 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
227 |
# File 'lib/base_object.rb', line 227 alias :base_method_handler :method_handler |
#method_handler(m, args = []) ⇒ Object
First call BaseObject method handler, then, if not method found try ActionObject handler
231 232 233 234 235 236 237 238 239 240 |
# File 'lib/base_object.rb', line 231 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 |
#original_method_missing ⇒ Object
242 |
# File 'lib/base_object.rb', line 242 alias :original_method_missing :method_missing |