Module: Repositor::ActiveRecord
- Defined in:
- lib/repositor/active_record.rb
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #all ⇒ Object
- #create(record_params) ⇒ Object
- #destroy(record) ⇒ Object
- #find(record_id) ⇒ Object
- #initialize(model: nil) ⇒ Object
- #new ⇒ Object
- #update(record, record_params) ⇒ Object
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
3 4 5 |
# File 'lib/repositor/active_record.rb', line 3 def model @model end |
Instance Method Details
#all ⇒ Object
13 14 15 |
# File 'lib/repositor/active_record.rb', line 13 def all model.send :all end |
#create(record_params) ⇒ Object
21 22 23 |
# File 'lib/repositor/active_record.rb', line 21 def create(record_params) model.send :create, record_params end |
#destroy(record) ⇒ Object
30 31 32 |
# File 'lib/repositor/active_record.rb', line 30 def destroy(record) record.destroy end |
#find(record_id) ⇒ Object
9 10 11 |
# File 'lib/repositor/active_record.rb', line 9 def find(record_id) model.send :find, record_id end |
#initialize(model: nil) ⇒ Object
5 6 7 |
# File 'lib/repositor/active_record.rb', line 5 def initialize(model: nil) @model = model || self.class.to_s.chomp("Repo").singularize.constantize end |
#new ⇒ Object
17 18 19 |
# File 'lib/repositor/active_record.rb', line 17 def new model.send :new end |
#update(record, record_params) ⇒ Object
25 26 27 28 |
# File 'lib/repositor/active_record.rb', line 25 def update(record, record_params) record.update(record_params) record end |