Class: OrmAdapterAws::SimpleDB

Inherits:
OrmAdapter::Base
  • Object
show all
Defined in:
lib/orm_adapter_aws/adapters/simple_db.rb

Instance Method Summary collapse

Instance Method Details

#column_namesObject

Return list of column/property names



5
6
7
# File 'lib/orm_adapter_aws/adapters/simple_db.rb', line 5

def column_names
  klass.attributes.keys
end

#create!(attributes = {}) ⇒ Object

See Also:

  • OrmAdapter::Base#create!


47
48
49
50
51
52
53
54
# File 'lib/orm_adapter_aws/adapters/simple_db.rb', line 47

def create!(attributes = {})
  unless attributes.is_a?(Hash) || valid_object?(attributes)
    raise "#{attributes.class} is not a valid #{klass}."
  end
  obj = klass.new(attributes)
  obj.save
  obj
end

#destroy(object) ⇒ Object

See Also:

  • OrmAdapter::Base#destroy


57
58
59
# File 'lib/orm_adapter_aws/adapters/simple_db.rb', line 57

def destroy(object)
  object.destroy && true if valid_object?(object)
end

#find_all(options = {}) ⇒ Object

See Also:

  • OrmAdapter::Base#find_all


37
38
39
40
41
42
43
44
# File 'lib/orm_adapter_aws/adapters/simple_db.rb', line 37

def find_all(options = {})
  conditions, order, limit, offset = extract_conditions!(options)
  scope = klass.where(conditions_to_fields(conditions))
  scope = scope.order(*order_munge(order)) if !order.nil? && order.size > 0
  scope = scope.limit(limit) if !limit.nil?
  #.offset(offset).all
  scope.all.to_a
end

#find_first(options = {}) ⇒ Object

See Also:

  • OrmAdapter::Base#find_first


22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/orm_adapter_aws/adapters/simple_db.rb', line 22

def find_first(options = {})
  conditions, order = extract_conditions!(options)
  id = nil
  if conditions.keys.include? :id
    id = conditions.delete(:id)
    obj = get(id)
    compare_obj_to_conditions(obj,conditions)
  else
    scope = klass.where(conditions_to_fields(conditions))
    scope = scope.order(*order_munge(order)) if !order.nil? && order.size > 0
    obj = scope.first
  end
end

#get(id) ⇒ Object

See Also:

  • OrmAdapter::Base#get


15
16
17
18
19
# File 'lib/orm_adapter_aws/adapters/simple_db.rb', line 15

def get(id)
  klass.find(wrap_key(id))
rescue AWS::Record::RecordNotFound => rnf
  nil
end

#get!(id) ⇒ Object

See Also:

  • OrmAdapter::Base#get!


10
11
12
# File 'lib/orm_adapter_aws/adapters/simple_db.rb', line 10

def get!(id)
  klass.find(wrap_key(id))
end