Class: OrmAdapterAws::SimpleDB
- Inherits:
-
OrmAdapter::Base
- Object
- OrmAdapter::Base
- OrmAdapterAws::SimpleDB
- Defined in:
- lib/orm_adapter_aws/adapters/simple_db.rb
Instance Method Summary collapse
-
#column_names ⇒ Object
Return list of column/property names.
- #create!(attributes = {}) ⇒ Object
- #destroy(object) ⇒ Object
- #find_all(options = {}) ⇒ Object
- #find_first(options = {}) ⇒ Object
- #get(id) ⇒ Object
- #get!(id) ⇒ Object
Instance Method Details
#column_names ⇒ Object
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
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
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
37 38 39 40 41 42 43 44 |
# File 'lib/orm_adapter_aws/adapters/simple_db.rb', line 37 def find_all( = {}) conditions, order, limit, offset = extract_conditions!() 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
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( = {}) conditions, order = extract_conditions!() 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
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
10 11 12 |
# File 'lib/orm_adapter_aws/adapters/simple_db.rb', line 10 def get!(id) klass.find(wrap_key(id)) end |