Class: OpsWorks::Layer

Inherits:
Resource show all
Defined in:
lib/opsworks/layer.rb

Instance Attribute Summary collapse

Attributes inherited from Resource

#client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

account, #initialize

Constructor Details

This class inherits a constructor from OpsWorks::Resource

Instance Attribute Details

#custom_recipesObject

Returns the value of attribute custom_recipes.



3
4
5
# File 'lib/opsworks/layer.rb', line 3

def custom_recipes
  @custom_recipes
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/opsworks/layer.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/opsworks/layer.rb', line 3

def name
  @name
end

#shortnameObject

Returns the value of attribute shortname.



3
4
5
# File 'lib/opsworks/layer.rb', line 3

def shortname
  @shortname
end

Class Method Details

.from_collection_response(client, response) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/opsworks/layer.rb', line 5

def self.from_collection_response(client, response)
  response.data[:layers].map do |layer|
    hash = layer.to_h
    # Make custom_recipes accessible by string or symbol
    custom_recipes = Thor::CoreExt::HashWithIndifferentAccess.new(
      hash[:custom_recipes]
    )
    new(
      client,
      id: hash[:layer_id],
      name: hash[:name],
      shortname: hash[:shortname],
      custom_recipes: custom_recipes
    )
  end
end

Instance Method Details

#add_custom_recipe(event, recipe) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/opsworks/layer.rb', line 22

def add_custom_recipe(event, recipe)
  return if custom_recipes[event].include?(recipe)

  custom_recipes[event] ||= []
  custom_recipes[event].push recipe
  client.update_layer(
    layer_id: id,
    custom_recipes: custom_recipes
  )
end

#remove_custom_recipe(event, recipe) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/opsworks/layer.rb', line 33

def remove_custom_recipe(event, recipe)
  return unless custom_recipes[event].include?(recipe)

  custom_recipes[event].delete recipe
  client.update_layer(
    layer_id: id,
    custom_recipes: custom_recipes
  )
end