Module: Smash::CloudPowers::Creatable::BeforeHooks
- Defined in:
- lib/cloud_powers/creatable.rb
Instance Attribute Summary collapse
-
#saved ⇒ Object
Boolean
- tells if this resource is mapped to a resource in the cloud.
Instance Method Summary collapse
-
#build(name:, **config) {|new_resource| ... } ⇒ Object
A
before_hook
style method that allows you to do things after you instantiate the resource’s object but before you create the resource, in the cloud. -
#create!(name:, **config) {|new_resource| ... } ⇒ Object
An
after_hook
style method that allows you to do things after you instantiate the resource’s object, but before you create the resource, in the cloud.
Instance Attribute Details
#saved ⇒ Object
Boolean
- tells if this resource is mapped to a resource in the cloud
26 27 28 |
# File 'lib/cloud_powers/creatable.rb', line 26 def saved @saved end |
Instance Method Details
#build(name:, **config) {|new_resource| ... } ⇒ Object
A before_hook
style method that allows you to do things after you instantiate the resource’s object but before you create the resource, in the cloud. Because we’re likely to be in the middle of requesting a resource be requested, in the cloud, this method gives us a means to do some checking, linking and/or setup before we make a request.
Parameters
-
Hash
or keyword argument(s) - configuration -
Block
(optional) - your optional before_hook that runs before you’ve
instantiated your object, yielding the new instance to you, to run in your block.
Returns Object
- a new instance of the class that extended this module
42 43 44 45 46 |
# File 'lib/cloud_powers/creatable.rb', line 42 def build(name:, **config) new_resource = self.new(name: name, **config) yield new_resource if block_given? new_resource end |
#create!(name:, **config) {|new_resource| ... } ⇒ Object
An after_hook
style method that allows you to do things after you instantiate the resource’s object, but before you create the resource, in the cloud. Because we’re likely to be in the middle of requesting to create a resource, in the cloud, this method gives us a means to do some checking or setup after we make a request.
Parameters
-
Hash
or keyword argument(s) - configuration -
Block
(optional) - your optional after_hook that runs after you’ve
created your resource(s) in the cloud, yielding the new instance to you, to run in your block.
Returns Object
- a new instance of the class that extended this module
Notes
-
See
#build
-
See
#save!
-
See
CloudPowers::Helpers::LogicHelp#instance_attr_accessor
-
See
CloudPowers::Helpers::LogicHelp#attr_map
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/cloud_powers/creatable.rb', line 69 def create!(name:, **config) new_resource = self.build(name: name, **config) new_resource.attr_map(config) do |config_key, config_value| new_resource.instance_attr_accessor new_resource.to_snake(config_key) config_value end new_resource.save! yield new_resource if block_given? new_resource end |