Class: Databound::Manager
- Inherits:
-
Object
- Object
- Databound::Manager
- Defined in:
- lib/databound/manager.rb
Instance Method Summary collapse
- #create_from_data ⇒ Object
- #destroy_from_data ⇒ Object
- #find_scoped_records(only_extra_scopes: false) ⇒ Object
-
#initialize(controller) ⇒ Manager
constructor
A new instance of Manager.
- #update_from_data ⇒ Object
Constructor Details
#initialize(controller) ⇒ Manager
Returns a new instance of Manager.
4 5 6 7 8 9 10 11 12 13 |
# File 'lib/databound/manager.rb', line 4 def initialize(controller) @controller = controller @scope = Databound::Data.new(@controller, scope_js, model) @data = Databound::Data.new(@controller, data_js, model) @extra_where_scopes = JSON.parse(extra_where_scopes_js).map do |extra_scope| Databound::Data.new(@controller, extra_scope, model) end end |
Instance Method Details
#create_from_data ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/databound/manager.rb', line 23 def create_from_data check_params!(:create) record = model.new(params.to_h) check_permit!(:create, params, record) record.save record end |
#destroy_from_data ⇒ Object
44 45 46 47 48 |
# File 'lib/databound/manager.rb', line 44 def destroy_from_data record = model.find(params.id) check_permit!(:destroy, params, record) record.destroy end |
#find_scoped_records(only_extra_scopes: false) ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/databound/manager.rb', line 15 def find_scoped_records(only_extra_scopes: false) records = model.where(or_query(@scope, *@extra_where_scopes)) records = filter_by_params!(records) unless only_extra_scopes check_permit!(:read, params, records) records end |
#update_from_data ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/databound/manager.rb', line 32 def update_from_data attributes = params.to_h id = attributes.delete(:id) check_params!(:update) record = model.find(id) check_permit!(:update, params, record) record.update(attributes) record end |