Class: EasySettings::ParamsWrapper
- Defined in:
- lib/redmine_extensions/easy_settings/params_wrapper.rb
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(raw_params, project, prefix) ⇒ ParamsWrapper
constructor
A new instance of ParamsWrapper.
- #save ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(raw_params, project, prefix) ⇒ ParamsWrapper
Returns a new instance of ParamsWrapper.
19 20 21 22 23 24 25 26 27 |
# File 'lib/redmine_extensions/easy_settings/params_wrapper.rb', line 19 def initialize(raw_params, project, prefix) @raw_params = raw_params @project_id = project.is_a?(Project) ? project.id : project @prefix = "#{prefix}_" if prefix.present? @errors = [] prepare_params prepare_easy_settings end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
4 5 6 |
# File 'lib/redmine_extensions/easy_settings/params_wrapper.rb', line 4 def errors @errors end |
Class Method Details
.from_params(raw_params, project: nil, prefix: nil) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/redmine_extensions/easy_settings/params_wrapper.rb', line 6 def self.from_params(raw_params, project: nil, prefix: nil) case raw_params when Hash # OK when ActionController::Parameters raw_params = raw_params.to_unsafe_h else raw_params = {} end new(raw_params, project, prefix) end |
Instance Method Details
#save ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/redmine_extensions/easy_settings/params_wrapper.rb', line 34 def save @errors.clear @easy_settings.each do |setting| # TO CONSIDER: Should this line exist? # This skip callbacks after saving # setting but is it desirable? next if !setting.changed? if setting.save # All good else @errors << [setting, setting.errors] end end @errors.empty? end |
#valid? ⇒ Boolean
29 30 31 32 |
# File 'lib/redmine_extensions/easy_settings/params_wrapper.rb', line 29 def valid? validate @errors.empty? end |