Class: EasySettings::Mapper

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

Instance Method Summary collapse

Constructor Details

#initializeMapper

Returns a new instance of Mapper.



4
5
6
# File 'lib/redmine_extensions/easy_settings/mapper.rb', line 4

def initialize
  @all_keys = {}
end

Instance Method Details

#after_save(easy_setting) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/redmine_extensions/easy_settings/mapper.rb', line 54

def after_save(easy_setting)
  if @all_keys.has_key?(easy_setting.name)
    @all_keys[easy_setting.name].after_save(easy_setting)
  else
    true
  end
end

#boolean_keys(*names) ⇒ Object

Shortcust due to frequent usage



32
33
34
35
36
# File 'lib/redmine_extensions/easy_settings/mapper.rb', line 32

def boolean_keys(*names)
  names.each do |name|
    key(name, type: 'boolean')
  end
end

#default_valuesObject



38
39
40
41
42
43
44
# File 'lib/redmine_extensions/easy_settings/mapper.rb', line 38

def default_values
  values = {}
  @all_keys.each do |name, key|
    values[name] = key.default
  end
  values
end

#disabled_from_params?(easy_setting) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
73
74
75
76
# File 'lib/redmine_extensions/easy_settings/mapper.rb', line 70

def disabled_from_params?(easy_setting)
  if @all_keys.has_key?(easy_setting.name)
    @all_keys[easy_setting.name].disabled_from_params?
  else
    false
  end
end

#from_params(easy_setting, value) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/redmine_extensions/easy_settings/mapper.rb', line 62

def from_params(easy_setting, value)
  if @all_keys.has_key?(easy_setting.name)
    @all_keys[easy_setting.name].from_params(easy_setting, value)
  else
    value
  end
end

#key(name, **options, &block) ⇒ Object Also known as: add_key

Be careful for double definition of the same key Last definition wins



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

def key(name, **options, &block)
  name = name.to_s

  if block
    key_dsl = EasySettings::KeyDSL.new
    key_dsl.instance_eval(&block)
    options = options.merge(key_dsl.options)
  end

  EasySetting.mapper_clear_caches
  @all_keys[name] = EasySettings::Key.init(name, **options)
end

#keys(*names, **options, &block) ⇒ Object Also known as: add_keys



24
25
26
27
28
# File 'lib/redmine_extensions/easy_settings/mapper.rb', line 24

def keys(*names, **options, &block)
  names.each do |name|
    key(name, **options, &block)
  end
end

#skip_blank_params?(easy_setting) ⇒ Boolean

Returns:

  • (Boolean)


78
79
80
81
82
83
84
# File 'lib/redmine_extensions/easy_settings/mapper.rb', line 78

def skip_blank_params?(easy_setting)
  if @all_keys.has_key?(easy_setting.name)
    @all_keys[easy_setting.name].skip_blank_params?
  else
    false
  end
end

#validate(easy_setting) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/redmine_extensions/easy_settings/mapper.rb', line 46

def validate(easy_setting)
  if @all_keys.has_key?(easy_setting.name)
    @all_keys[easy_setting.name].validate(easy_setting)
  else
    true
  end
end