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

Returns a new instance of 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



58
59
60
61
# File 'lib/simple_deploy/entry.rb', line 58

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

#saveObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/simple_deploy/entry.rb', line 36

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

  current_attributes = attributes.reject do |key,value|
    if value == 'nil'
      @logger.info "Removing attribute set to nil '#{key}'."
      sdb_connect.delete_items 'stacks', name, key => nil
      true
    end
  end

  current_attributes.each_pair {|k,v| @logger.debug "Setting attribute #{k}=#{v}"}

  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
33
34
# File 'lib/simple_deploy/entry.rb', line 30

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