Class: Wright::Resource
- Inherits:
-
Object
- Object
- Wright::Resource
- Defined in:
- lib/wright/resource.rb,
lib/wright/resource/file.rb,
lib/wright/resource/user.rb,
lib/wright/resource/group.rb,
lib/wright/resource/package.rb,
lib/wright/resource/symlink.rb,
lib/wright/resource/directory.rb more...
Overview
Resource base class.
Defined Under Namespace
Classes: Directory, File, Group, Package, Symlink, User
Instance Attribute Summary collapse
-
#action ⇒ Symbol
The name of the method to be run by #run_action.
-
#ignore_failure ⇒ Bool
The ignore_failure attribute.
-
#name ⇒ String
The resource’s name attribute.
-
#on_update ⇒ void
writeonly
Sets an update action for a resource.
-
#resource_name ⇒ Symbol
readonly
A compact resource name.
Instance Method Summary collapse
-
#initialize(name = nil, args = {}) ⇒ Resource
constructor
Initializes a Resource.
-
#run_action ⇒ Object
Runs the resource’s current action.
Constructor Details
permalink #initialize(name = nil, args = {}) ⇒ Resource
Initializes a Resource.
12 13 14 15 16 17 18 19 |
# File 'lib/wright/resource.rb', line 12 def initialize(name = nil, args = {}) @name = name @action = args.fetch(:action, nil) @ignore_failure = args.fetch(:ignore_failure, false) self.on_update = args.fetch(:on_update, nil) @resource_name = Util.class_to_resource_name(self.class).to_sym @provider = provider_for_resource end |
Instance Attribute Details
permalink #action ⇒ Symbol
Returns the name of the method to be run by #run_action.
22 23 24 |
# File 'lib/wright/resource.rb', line 22 def action @action end |
permalink #ignore_failure ⇒ Bool
Returns the ignore_failure attribute.
25 26 27 |
# File 'lib/wright/resource.rb', line 25 def ignore_failure @ignore_failure end |
permalink #name ⇒ String
Returns the resource’s name attribute.
38 39 40 |
# File 'lib/wright/resource.rb', line 38 def name @name end |
permalink #on_update=(on_update) ⇒ void
This method returns an undefined value.
Sets an update action for a resource.
55 56 57 58 59 60 61 |
# File 'lib/wright/resource.rb', line 55 def on_update=(on_update) if on_update.respond_to?(:call) || on_update.nil? @on_update = on_update else fail ArgumentError, "#{on_update} is not callable" end end |
permalink #resource_name ⇒ Symbol (readonly)
Returns a compact resource name.
46 47 48 |
# File 'lib/wright/resource.rb', line 46 def resource_name @resource_name end |
Instance Method Details
permalink #run_action ⇒ Object
Runs the resource’s current action.
71 72 73 |
# File 'lib/wright/resource.rb', line 71 def run_action send action if action end |