Class: Serverkit::Resources::Base
- Inherits:
-
Object
- Object
- Serverkit::Resources::Base
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/serverkit/resources/base.rb
Direct Known Subclasses
Command, File, Git, Missing, Nothing, Package, Recipe, Service, Symlink, Unknown, User
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#backend ⇒ Object
Returns the value of attribute backend.
-
#check_result ⇒ Object
readonly
Returns the value of attribute check_result.
-
#recheck_result ⇒ Object
readonly
Returns the value of attribute recheck_result.
-
#recipe ⇒ Object
readonly
Returns the value of attribute recipe.
Class Method Summary collapse
Instance Method Summary collapse
- #all_errors ⇒ Array<Serverkit::Errors::Base>
- #handlers ⇒ Array<Serverkit::Resource>
- #id ⇒ String
-
#initialize(recipe, attributes) ⇒ Base
constructor
A new instance of Base.
-
#notifiable? ⇒ true, false
True if this resource should call any handler.
- #run_apply ⇒ Object
- #run_check ⇒ true, false
- #successful? ⇒ Boolean
- #successful_on_check? ⇒ Boolean
- #successful_on_recheck? ⇒ Boolean
- #to_a ⇒ Array<Serverkit::Resources::Base>
Constructor Details
#initialize(recipe, attributes) ⇒ Base
Returns a new instance of Base.
46 47 48 49 |
# File 'lib/serverkit/resources/base.rb', line 46 def initialize(recipe, attributes) @attributes = attributes @recipe = recipe end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
26 27 28 |
# File 'lib/serverkit/resources/base.rb', line 26 def attributes @attributes end |
#backend ⇒ Object
Returns the value of attribute backend.
24 25 26 |
# File 'lib/serverkit/resources/base.rb', line 24 def backend @backend end |
#check_result ⇒ Object (readonly)
Returns the value of attribute check_result.
26 27 28 |
# File 'lib/serverkit/resources/base.rb', line 26 def check_result @check_result end |
#recheck_result ⇒ Object (readonly)
Returns the value of attribute recheck_result.
26 27 28 |
# File 'lib/serverkit/resources/base.rb', line 26 def recheck_result @recheck_result end |
#recipe ⇒ Object (readonly)
Returns the value of attribute recipe.
26 27 28 |
# File 'lib/serverkit/resources/base.rb', line 26 def recipe @recipe end |
Class Method Details
.attribute(name, options = {}) ⇒ Object
DSL method to define attribute with its validations
13 14 15 16 17 18 19 |
# File 'lib/serverkit/resources/base.rb', line 13 def attribute(name, = {}) default = .delete(:default) define_method(name) do @attributes[name.to_s] || default end validates name, unless .empty? end |
Instance Method Details
#all_errors ⇒ Array<Serverkit::Errors::Base>
For override
53 54 55 |
# File 'lib/serverkit/resources/base.rb', line 53 def all_errors attribute_validation_errors end |
#handlers ⇒ Array<Serverkit::Resource>
58 59 60 61 62 63 64 |
# File 'lib/serverkit/resources/base.rb', line 58 def handlers @handlers ||= Array(notify).map do |id| recipe.handlers.find do |handler| handler.id == id end end.compact end |
#id ⇒ String
For logging and notifying
68 69 70 |
# File 'lib/serverkit/resources/base.rb', line 68 def id @attributes["id"] || default_id end |
#notifiable? ⇒ true, false
Returns True if this resource should call any handler.
73 74 75 |
# File 'lib/serverkit/resources/base.rb', line 73 def notifiable? @recheck_result == true && !handlers.nil? end |
#run_apply ⇒ Object
#check and #apply wrapper
78 79 80 81 82 83 |
# File 'lib/serverkit/resources/base.rb', line 78 def run_apply unless run_check apply @recheck_result = !!recheck_with_script end end |
#run_check ⇒ true, false
#check wrapper
87 88 89 |
# File 'lib/serverkit/resources/base.rb', line 87 def run_check @check_result = !!check_with_script end |
#successful? ⇒ Boolean
91 92 93 |
# File 'lib/serverkit/resources/base.rb', line 91 def successful? successful_on_check? || successful_on_recheck? end |
#successful_on_check? ⇒ Boolean
95 96 97 |
# File 'lib/serverkit/resources/base.rb', line 95 def successful_on_check? @check_result == true end |
#successful_on_recheck? ⇒ Boolean
99 100 101 |
# File 'lib/serverkit/resources/base.rb', line 99 def successful_on_recheck? @check_result == true end |
#to_a ⇒ Array<Serverkit::Resources::Base>
recipe resource will override to replace itself with multiple resources
105 106 107 |
# File 'lib/serverkit/resources/base.rb', line 105 def to_a [self] end |