Class: Serverkit::Resources::Base
- Inherits:
-
Object
- Object
- Serverkit::Resources::Base
- Includes:
- ActiveModel::Validations
- Defined in:
- lib/serverkit/resources/base.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#backend ⇒ Object
Returns the value of attribute backend.
-
#recipe ⇒ Object
readonly
Returns the value of attribute recipe.
Class Method Summary collapse
Instance Method Summary collapse
- #all_errors ⇒ Array<Serverkit::Errors::Base>
-
#initialize(recipe, attributes) ⇒ Base
constructor
A new instance of Base.
- #to_a ⇒ Array<Serverkit::Resources::Base>
- #type ⇒ String
Constructor Details
#initialize(recipe, attributes) ⇒ Base
Returns a new instance of Base.
31 32 33 34 |
# File 'lib/serverkit/resources/base.rb', line 31 def initialize(recipe, attributes) @attributes = attributes @recipe = recipe end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
25 26 27 |
# File 'lib/serverkit/resources/base.rb', line 25 def attributes @attributes end |
#backend ⇒ Object
Returns the value of attribute backend.
23 24 25 |
# File 'lib/serverkit/resources/base.rb', line 23 def backend @backend end |
#recipe ⇒ Object (readonly)
Returns the value of attribute recipe.
25 26 27 |
# File 'lib/serverkit/resources/base.rb', line 25 def recipe @recipe end |
Class Method Details
.attribute(name, options = {}) ⇒ Object
Note:
DSL method to define attribute with its validations
12 13 14 15 16 17 18 |
# File 'lib/serverkit/resources/base.rb', line 12 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>
Note:
For override use
38 39 40 |
# File 'lib/serverkit/resources/base.rb', line 38 def all_errors attribute_validation_errors end |
#to_a ⇒ Array<Serverkit::Resources::Base>
Note:
recipe resource will override to replace itself with multiple resources
44 45 46 |
# File 'lib/serverkit/resources/base.rb', line 44 def to_a [self] end |
#type ⇒ String
49 50 51 |
# File 'lib/serverkit/resources/base.rb', line 49 def type @attributes["type"] end |