Class: Wallaby::ActiveRecord::ModelServiceProvider::Permitter
- Inherits:
-
Object
- Object
- Wallaby::ActiveRecord::ModelServiceProvider::Permitter
- Defined in:
- lib/adapters/wallaby/active_record/model_service_provider/permitter.rb
Overview
Allowlist the params for mass-assignment
Instance Method Summary collapse
-
#compound_hashed_fields ⇒ Array<String>
A list of field names of range and association.
-
#initialize(model_decorator) ⇒ Permitter
constructor
A new instance of Permitter.
-
#simple_field_names ⇒ Array<String>
A list of field names of general types.
Constructor Details
#initialize(model_decorator) ⇒ Permitter
Returns a new instance of Permitter.
9 10 11 |
# File 'lib/adapters/wallaby/active_record/model_service_provider/permitter.rb', line 9 def initialize(model_decorator) @model_decorator = model_decorator end |
Instance Method Details
#compound_hashed_fields ⇒ Array<String>
Returns a list of field names of range and association.
25 26 27 28 29 30 |
# File 'lib/adapters/wallaby/active_record/model_service_provider/permitter.rb', line 25 def compound_hashed_fields field_names = range_fields.keys + many_association_fields.map { |_, | [:foreign_key] } field_names.each_with_object({}) { |name, hash| hash[name] = [] } end |
#simple_field_names ⇒ Array<String>
Returns a list of field names of general types.
14 15 16 17 18 19 20 21 22 |
# File 'lib/adapters/wallaby/active_record/model_service_provider/permitter.rb', line 14 def simple_field_names field_names = non_range_fields.keys + belongs_to_fields.flat_map do |_, | [[:foreign_key], [:polymorphic_type]] end.compact fields = [@model_decorator.primary_key, 'created_at', 'updated_at'] field_names.reject { |field_name| fields.include?(field_name) }.uniq end |