Class: EasySettings::ParamsWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/redmine_extensions/easy_settings/params_wrapper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_params, project, prefix) ⇒ ParamsWrapper



13
14
15
16
17
18
19
20
21
# File 'lib/redmine_extensions/easy_settings/params_wrapper.rb', line 13

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

#errorsObject (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
# File 'lib/redmine_extensions/easy_settings/params_wrapper.rb', line 6

def self.from_params(raw_params, project: nil, prefix: nil)
  if !raw_params.is_a?(Hash) && !raw_params.is_a?(ActionController::Parameters)
    raw_params = {}
  end
  new(raw_params, project, prefix)
end

Instance Method Details

#saveObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/redmine_extensions/easy_settings/params_wrapper.rb', line 28

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



23
24
25
26
# File 'lib/redmine_extensions/easy_settings/params_wrapper.rb', line 23

def valid?
  validate
  @errors.empty?
end