Class: Databound::Manager
- Inherits:
-
Object
- Object
- Databound::Manager
- Defined in:
- lib/databound/manager.rb
Instance Method Summary collapse
- #action_allowed?(method, record) ⇒ Boolean
- #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
#action_allowed?(method, record) ⇒ Boolean
53 54 55 56 57 58 59 |
# File 'lib/databound/manager.rb', line 53 def action_allowed?(method, record) permit_checks = @controller.databound_config.read(:permit) check = permit_checks[method] return true unless check @controller.instance_exec(params, record, &check) end |
#create_from_data ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/databound/manager.rb', line 26 def create_from_data check_params!(:create) record = model.new(params.to_h) check_permit!(:create, record) record.save record end |
#destroy_from_data ⇒ Object
47 48 49 50 51 |
# File 'lib/databound/manager.rb', line 47 def destroy_from_data record = model.find(params.id) check_permit!(:destroy, record) record.destroy end |
#find_scoped_records(only_extra_scopes: false) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/databound/manager.rb', line 15 def find_scoped_records(only_extra_scopes: false) records = model.where(or_query(@scope, *@extra_where_scopes)) unless only_extra_scopes records = filter_by_params!(records) check_permit!(:read, records) end records end |
#update_from_data ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/databound/manager.rb', line 35 def update_from_data attributes = params.to_h id = attributes.delete(:id) check_params!(:update) record = model.find(id) check_permit!(:update, record) record.update(attributes) record end |