Class: SimpleDeploy::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_deploy/entry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Entry



6
7
8
9
10
11
12
13
# File 'lib/simple_deploy/entry.rb', line 6

def initialize(args)
  @domain = 'stacks'
  @config = SimpleDeploy.config
  @logger = SimpleDeploy.logger
  @custom_attributes = {}
  @name = region_specific_name args[:name]
  create_domain
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/simple_deploy/entry.rb', line 4

def name
  @name
end

Class Method Details

.find(args) ⇒ Object



15
16
17
# File 'lib/simple_deploy/entry.rb', line 15

def self.find(args)
  Entry.new :name => args[:name]
end

Instance Method Details

#attributesObject



19
20
21
22
23
24
25
26
27
28
# File 'lib/simple_deploy/entry.rb', line 19

def attributes
  u = {}

  attrs = sdb_connect.select "select * from stacks where itemName() = '#{name}'"
  if attrs.has_key? name
    u.merge! Hash[attrs[name].map { |k,v| [k, v.first] }]
  end

  u.merge @custom_attributes
end

#delete_attributesObject



51
52
53
54
# File 'lib/simple_deploy/entry.rb', line 51

def delete_attributes
  sdb_connect.delete('stacks', name)
  @logger.info "Delete from SimpleDB successful."
end

#saveObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/simple_deploy/entry.rb', line 34

def save
  @custom_attributes.merge! 'Name' => name,
                            'CreatedAt' => Time.now.utc.to_s

  current_attributes = attributes
  current_attributes.each_pair do |key,value|
    @logger.debug "Setting attribute #{key}=#{value}"
  end

  sdb_connect.put_attributes('stacks', 
                              name, 
                              current_attributes, 
                             :replace => current_attributes.keys )

  @logger.debug "Save to SimpleDB successful."
end

#set_attributes(a) ⇒ Object



30
31
32
# File 'lib/simple_deploy/entry.rb', line 30

def set_attributes(a)
  a.each { |attribute| @custom_attributes.merge! attribute }
end