Class: EasySettings::Key
- Inherits:
-
Object
show all
- Defined in:
- lib/redmine_extensions/easy_settings/key.rb
Overview
EasySettings::Key
Definition of easy setting key
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, **options) ⇒ Key
Returns a new instance of Key.
27
28
29
30
|
# File 'lib/redmine_extensions/easy_settings/key.rb', line 27
def initialize(name, **options)
@name = name
@options = options
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
9
10
11
|
# File 'lib/redmine_extensions/easy_settings/key.rb', line 9
def name
@name
end
|
#options ⇒ Object
Returns the value of attribute options.
9
10
11
|
# File 'lib/redmine_extensions/easy_settings/key.rb', line 9
def options
@options
end
|
Class Method Details
.init(name, **options) ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/redmine_extensions/easy_settings/key.rb', line 11
def self.init(name, **options)
key_class =
case options[:type].to_s
when 'boolean', 'bool'
BooleanKey
when 'integer', 'int'
IntegerKey
when 'float'
FloatKey
else
Key
end
key_class.new(name, **options)
end
|
Instance Method Details
#after_save(easy_setting) ⇒ Object
42
43
44
45
46
|
# File 'lib/redmine_extensions/easy_settings/key.rb', line 42
def after_save(easy_setting)
if options[:after_save].is_a?(Proc)
easy_setting.instance_eval(&options[:after_save])
end
end
|
#default ⇒ Object
32
33
34
|
# File 'lib/redmine_extensions/easy_settings/key.rb', line 32
def default
@options[:default]
end
|
#disabled_from_params? ⇒ Boolean
56
57
58
|
# File 'lib/redmine_extensions/easy_settings/key.rb', line 56
def disabled_from_params?
!!options[:disabled_from_params]
end
|
#from_params(easy_setting, value) ⇒ Object
48
49
50
51
52
53
54
|
# File 'lib/redmine_extensions/easy_settings/key.rb', line 48
def from_params(easy_setting, value)
if options[:from_params].is_a?(Proc)
easy_setting.instance_exec(value, &options[:from_params])
else
value
end
end
|
#skip_blank_params? ⇒ Boolean
60
61
62
|
# File 'lib/redmine_extensions/easy_settings/key.rb', line 60
def skip_blank_params?
!!options[:skip_blank_params]
end
|
#validate(easy_setting) ⇒ Object
36
37
38
39
40
|
# File 'lib/redmine_extensions/easy_settings/key.rb', line 36
def validate(easy_setting)
if options[:validate].is_a?(Proc)
easy_setting.instance_eval(&options[:validate])
end
end
|