Module: ORMivore::ArAdapter
- Included in:
- App::AccountStorageArAdapter, App::AddressStorageArAdapter
- Defined in:
- lib/ormivore/ar_adapter.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #create(attrs) ⇒ Object
- #find(conditions, attributes_to_load, options = {}) ⇒ Object
- #initialize(converter = nil) ⇒ Object
- #update(attrs, conditions) ⇒ Object
Class Method Details
.included(base) ⇒ Object
39 40 41 |
# File 'lib/ormivore/ar_adapter.rb', line 39 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#create(attrs) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/ormivore/ar_adapter.rb', line 57 def create(attrs) record = ar_class.create!( extend_with_defaults( converter.to_storage(attrs))) { |o| o.id = attrs[:id] } attrs.merge(id: record.id) rescue ActiveRecord::ActiveRecordError => e raise StorageError.new(e) end |
#find(conditions, attributes_to_load, options = {}) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/ormivore/ar_adapter.rb', line 47 def find(conditions, attributes_to_load, = {}) order = .fetch(:order, {}) ar_class.all( select: converter.attributes_list_to_storage(attributes_to_load), conditions: conditions, order: order_by_clause(order) ).map { |r| entity_attributes(r) } end |
#initialize(converter = nil) ⇒ Object
43 44 45 |
# File 'lib/ormivore/ar_adapter.rb', line 43 def initialize(converter = nil) @converter = converter || self.class.default_converter_class.new end |
#update(attrs, conditions) ⇒ Object
66 67 68 69 70 |
# File 'lib/ormivore/ar_adapter.rb', line 66 def update(attrs, conditions) ar_class.update_all(converter.to_storage(attrs), conditions) rescue ActiveRecord::ActiveRecordError => e raise StorageError.new(e) end |