Class: Itamae::Resource::Base
- Inherits:
-
Object
- Object
- Itamae::Resource::Base
- Defined in:
- lib/itamae/resource/base.rb
Direct Known Subclasses
Definition, Directory, Execute, File, GemPackage, Git, Group, Link, LocalRubyBlock, Package, RemoteDirectory, Service, User
Defined Under Namespace
Classes: EvalContext
Class Attribute Summary collapse
-
.defined_attributes ⇒ Object
readonly
Returns the value of attribute defined_attributes.
-
.supported_oses ⇒ Object
readonly
Returns the value of attribute supported_oses.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#current_attributes ⇒ Object
(also: #current)
readonly
Returns the value of attribute current_attributes.
-
#notifications ⇒ Object
readonly
Returns the value of attribute notifications.
-
#recipe ⇒ Object
readonly
Returns the value of attribute recipe.
-
#resource_name ⇒ Object
readonly
Returns the value of attribute resource_name.
-
#subscriptions ⇒ Object
readonly
Returns the value of attribute subscriptions.
-
#updated ⇒ Object
readonly
Returns the value of attribute updated.
Class Method Summary collapse
Instance Method Summary collapse
- #action_nothing(options) ⇒ Object
-
#initialize(recipe, resource_name, &block) ⇒ Base
constructor
A new instance of Base.
- #resource_type ⇒ Object
- #run(specific_action = nil, options = {}) ⇒ Object
Constructor Details
#initialize(recipe, resource_name, &block) ⇒ Base
Returns a new instance of Base.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/itamae/resource/base.rb', line 92 def initialize(recipe, resource_name, &block) clear_current_attributes @recipe = recipe @resource_name = resource_name @updated = false EvalContext.new(self).tap do |context| context.instance_eval(&block) if block @attributes = context.attributes @notifications = context.notifications @subscriptions = context.subscriptions @only_if_command = context.only_if_command @not_if_command = context.not_if_command end process_attributes end |
Class Attribute Details
.defined_attributes ⇒ Object (readonly)
Returns the value of attribute defined_attributes.
65 66 67 |
# File 'lib/itamae/resource/base.rb', line 65 def defined_attributes @defined_attributes end |
.supported_oses ⇒ Object (readonly)
Returns the value of attribute supported_oses.
66 67 68 |
# File 'lib/itamae/resource/base.rb', line 66 def supported_oses @supported_oses end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
86 87 88 |
# File 'lib/itamae/resource/base.rb', line 86 def attributes @attributes end |
#current_attributes ⇒ Object (readonly) Also known as: current
Returns the value of attribute current_attributes.
87 88 89 |
# File 'lib/itamae/resource/base.rb', line 87 def current_attributes @current_attributes end |
#notifications ⇒ Object (readonly)
Returns the value of attribute notifications.
89 90 91 |
# File 'lib/itamae/resource/base.rb', line 89 def notifications @notifications end |
#recipe ⇒ Object (readonly)
Returns the value of attribute recipe.
84 85 86 |
# File 'lib/itamae/resource/base.rb', line 84 def recipe @recipe end |
#resource_name ⇒ Object (readonly)
Returns the value of attribute resource_name.
85 86 87 |
# File 'lib/itamae/resource/base.rb', line 85 def resource_name @resource_name end |
#subscriptions ⇒ Object (readonly)
Returns the value of attribute subscriptions.
88 89 90 |
# File 'lib/itamae/resource/base.rb', line 88 def subscriptions @subscriptions end |
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
90 91 92 |
# File 'lib/itamae/resource/base.rb', line 90 def updated @updated end |
Class Method Details
.define_attribute(name, options) ⇒ Object
75 76 77 78 |
# File 'lib/itamae/resource/base.rb', line 75 def define_attribute(name, ) current = @defined_attributes[name.to_sym] || {} @defined_attributes[name.to_sym] = current.merge() end |
.inherited(subclass) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/itamae/resource/base.rb', line 68 def inherited(subclass) subclass.instance_variable_set( :@defined_attributes, self.defined_attributes.dup ) end |
Instance Method Details
#action_nothing(options) ⇒ Object
133 134 135 |
# File 'lib/itamae/resource/base.rb', line 133 def action_nothing() # do nothing end |
#resource_type ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/itamae/resource/base.rb', line 137 def resource_type humps = [] self.class.name.split("::").last.each_char do |c| if "A" <= c && c <= "Z" humps << c.downcase else humps.last << c end end humps.join('_') end |
#run(specific_action = nil, options = {}) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/itamae/resource/base.rb', line 110 def run(specific_action = nil, = {}) Logger.info "#{resource_type}[#{resource_name}]" Logger.formatter.indent do if do_not_run_because_of_only_if? Logger.info "Execution skipped because of only_if attribute" return elsif do_not_run_because_of_not_if? Logger.info "Execution skipped because of not_if attribute" return end [specific_action || attributes.action].flatten.each do |action| run_action(action, ) end notify() if updated? end rescue Backend::CommandExecutionError Logger.error "Failed." exit 2 end |