Class: Serverkit::Resources::Base

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/serverkit/resources/base.rb

Direct Known Subclasses

File, Git, HomebrewCask, Package, Recipe, Service, Symlink, Unknown

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(recipe, attributes) ⇒ Base

Returns a new instance of Base.

Parameters:



31
32
33
34
# File 'lib/serverkit/resources/base.rb', line 31

def initialize(recipe, attributes)
  @attributes = attributes
  @recipe = recipe
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



25
26
27
# File 'lib/serverkit/resources/base.rb', line 25

def attributes
  @attributes
end

#backendObject

Returns the value of attribute backend.



23
24
25
# File 'lib/serverkit/resources/base.rb', line 23

def backend
  @backend
end

#recipeObject (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, options = {})
  default = options.delete(:default)
  define_method(name) do
    @attributes[name.to_s] || default
  end
  validates name, options unless options.empty?
end

Instance Method Details

#all_errorsArray<Serverkit::Errors::Base>

Note:

For override use

Returns:



38
39
40
# File 'lib/serverkit/resources/base.rb', line 38

def all_errors
  attribute_validation_errors
end

#to_aArray<Serverkit::Resources::Base>

Note:

recipe resource will override to replace itself with multiple resources

Returns:



44
45
46
# File 'lib/serverkit/resources/base.rb', line 44

def to_a
  [self]
end

#typeString

Returns:

  • (String)


49
50
51
# File 'lib/serverkit/resources/base.rb', line 49

def type
  @attributes["type"]
end