Class: BulletTrain::Api::StrongParametersReporter
- Inherits:
-
Object
- Object
- BulletTrain::Api::StrongParametersReporter
- Defined in:
- lib/bullet_train/api/strong_parameters_reporter.rb
Instance Method Summary collapse
-
#initialize(model, strong_params_module) ⇒ StrongParametersReporter
constructor
A new instance of StrongParametersReporter.
- #params ⇒ Object
- #permit(*filters) ⇒ Object
- #permitted_arrays ⇒ Object
- #permitted_fields ⇒ Object
- #process_params(params) ⇒ Object
-
#report(method_type = nil) ⇒ Object
def method_missing(method_name, *args) if method_name.match?(/^assign_/) # It’s typically the second argument that represents the parameter that would be set.
- #require(namespace) ⇒ Object
Constructor Details
#initialize(model, strong_params_module) ⇒ StrongParametersReporter
Returns a new instance of StrongParametersReporter.
4 5 6 7 8 9 |
# File 'lib/bullet_train/api/strong_parameters_reporter.rb', line 4 def initialize(model, strong_params_module) @model = model @module = strong_params_module @filters = [] extend @module end |
Instance Method Details
#params ⇒ Object
20 21 22 |
# File 'lib/bullet_train/api/strong_parameters_reporter.rb', line 20 def params self end |
#permit(*filters) ⇒ Object
16 17 18 |
# File 'lib/bullet_train/api/strong_parameters_reporter.rb', line 16 def permit(*filters) @filters = filters end |
#permitted_arrays ⇒ Object
28 29 30 |
# File 'lib/bullet_train/api/strong_parameters_reporter.rb', line 28 def permitted_arrays defined?(super) ? super : {} end |
#permitted_fields ⇒ Object
24 25 26 |
# File 'lib/bullet_train/api/strong_parameters_reporter.rb', line 24 def permitted_fields defined?(super) ? super : [] end |
#process_params(params) ⇒ Object
32 33 |
# File 'lib/bullet_train/api/strong_parameters_reporter.rb', line 32 def process_params(params) end |
#report(method_type = nil) ⇒ Object
def method_missing(method_name, *args)
if method_name.match?(/^assign_/)
# It's typically the second argument that represents the parameter that would be set.
@filters << args[1]
else
raise NoMethodError,
end
end
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/bullet_train/api/strong_parameters_reporter.rb', line 44 def report(method_type = nil) method_type = ["create", "update"].include?(method_type) ? method_type : nil base_method_name = @model.name.split("::").last.underscore # if available in the controller, it will use the 'update' strong params instead of the default strong params. @filters = if method_type == "update" && respond_to?("#{base_method_name}_#{method_type}_params".to_sym, true) send(:"#{base_method_name}_#{method_type}_params") else send(:"#{base_method_name}_params") end # There's a reason I'm doing it this way. @filters end |
#require(namespace) ⇒ Object
11 12 13 14 |
# File 'lib/bullet_train/api/strong_parameters_reporter.rb', line 11 def require(namespace) @namespace = namespace self end |