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.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/databound/manager.rb', line 6 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
55 56 57 58 59 60 61 |
# File 'lib/databound/manager.rb', line 55 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
28 29 30 31 32 33 34 35 |
# File 'lib/databound/manager.rb', line 28 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
49 50 51 52 53 |
# File 'lib/databound/manager.rb', line 49 def destroy_from_data record = model.find(params.id) check_permit!(:destroy, record) record.destroy end |
#find_scoped_records(only_extra_scopes: false) ⇒ Object
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/databound/manager.rb', line 17 def find_scoped_records(only_extra_scopes: false) records = 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
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/databound/manager.rb', line 37 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 |