Module: Railjet::Repository::ActiveRecord
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/railjet/repository/active_record.rb
Instance Method Summary collapse
- #all ⇒ Object
- #build(args = {}, &block) ⇒ Object
- #destroy(object) ⇒ Object
- #duplicate(object, args = {}) ⇒ Object
- #find_by_ids(ids) ⇒ Object
- #initialize(registry, record = nil) ⇒ Object
- #persist(object) ⇒ Object
- #transaction(&block) ⇒ Object
Instance Method Details
#all ⇒ Object
15 16 17 |
# File 'lib/railjet/repository/active_record.rb', line 15 def all record.all end |
#build(args = {}, &block) ⇒ Object
23 24 25 |
# File 'lib/railjet/repository/active_record.rb', line 23 def build(args = {}, &block) record.new(args, &block) end |
#destroy(object) ⇒ Object
38 39 40 |
# File 'lib/railjet/repository/active_record.rb', line 38 def destroy(object) object.destroy! end |
#duplicate(object, args = {}) ⇒ Object
27 28 29 30 31 32 |
# File 'lib/railjet/repository/active_record.rb', line 27 def duplicate(object, args = {}) object.dup.tap do |new_object| new_object.assign_attributes(args) if args.present? yield(new_object) if block_given? end end |
#find_by_ids(ids) ⇒ Object
19 20 21 |
# File 'lib/railjet/repository/active_record.rb', line 19 def find_by_ids(ids) record.where(id: ids) end |
#initialize(registry, record = nil) ⇒ Object
10 11 12 13 |
# File 'lib/railjet/repository/active_record.rb', line 10 def initialize(registry, record = nil) @registry = registry @record = record end |
#persist(object) ⇒ Object
34 35 36 |
# File 'lib/railjet/repository/active_record.rb', line 34 def persist(object) object.save! end |
#transaction(&block) ⇒ Object
42 43 44 |
# File 'lib/railjet/repository/active_record.rb', line 42 def transaction(&block) record.transaction(&block) end |