Module: Smash::CloudPowers::Creatable::AfterHooks

Defined in:
lib/cloud_powers/creatable.rb

Instance Method Summary collapse

Instance Method Details

#linked?Boolean

Alternative to save!(). This predicate method is based off the @linked i-var and is set to true after it has been confirmed that this resource is a good map to the resource in the cloud.

Returns

  • Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/cloud_powers/creatable.rb', line 92

def linked?
  !!@linked
end

#save!Object

An after_hook style method that sends a reqeust to your custom implementation of the create_resource methodallows you to do things after you create the resource, in the cloud. This method relies on you having a create_resource method that can handle every aspect of creating your resource. If this piece of the contract isn’t obeyed, you will receive a NoMethodError.

Returns Boolean - true if the resource

Notes:

  • This method relies on you implementing a method called create_resource in your class. If you don’t, this code will still execute without errors but @saved will remain false



110
111
112
113
114
# File 'lib/cloud_powers/creatable.rb', line 110

def save!
  resp = create_resource if self.respond_to? :create_resource
  @saved = !resp.nil?
  resp
end

#saved?Boolean

Find out if the resource was created

Returns Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/cloud_powers/creatable.rb', line 120

def saved?
  !!@saved
end