Class: Stackster::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/stackster/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.



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

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

Instance Attribute Details

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/stackster/entry.rb', line 5

def name
  @name
end

Class Method Details

.find(args) ⇒ Object



16
17
18
19
20
# File 'lib/stackster/entry.rb', line 16

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

Instance Method Details

#attributesObject



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

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



53
54
55
56
# File 'lib/stackster/entry.rb', line 53

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

#saveObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/stackster/entry.rb', line 37

def save
  set_default_attributes
  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



33
34
35
# File 'lib/stackster/entry.rb', line 33

def set_attributes(a)
  a.each { |attribute| set_attribute(attribute) }
end