Class: Wallaby::ActiveRecord::ModelServiceProvider::Permitter
- Inherits:
-
Object
- Object
- Wallaby::ActiveRecord::ModelServiceProvider::Permitter
- Defined in:
- lib/adaptors/wallaby/active_record/model_service_provider/permitter.rb
Overview
Filter the params
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.
8 9 10 |
# File 'lib/adaptors/wallaby/active_record/model_service_provider/permitter.rb', line 8 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.
24 25 26 27 28 29 |
# File 'lib/adaptors/wallaby/active_record/model_service_provider/permitter.rb', line 24 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.
13 14 15 16 17 18 19 20 21 |
# File 'lib/adaptors/wallaby/active_record/model_service_provider/permitter.rb', line 13 def simple_field_names field_names = non_range_fields.keys + belongs_to_fields.map do |_, | [[:foreign_key], [:polymorphic_type]] end.flatten.compact fields = [@model_decorator.primary_key, 'created_at', 'updated_at'] field_names.reject { |field_name| fields.include? field_name } end |