serial_preference 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,42 +1,44 @@
1
- class Preference
1
+ module SerialPreference
2
+ class Preference
2
3
 
3
- SUPPORTED_TYPES = [:string,:integer,:real,:float,:boolean,:password]
4
+ SUPPORTED_TYPES = [:string,:integer,:real,:float,:boolean,:password]
4
5
 
5
- attr_accessor :data_type, :name, :default, :required, :label, :hint
6
+ attr_accessor :data_type, :name, :default, :required, :label, :hint
6
7
 
7
- def initialize(name,opts = {})
8
- self.data_type = opts[:data_type] || :string
9
- self.name = name
10
- self.default = opts[:default]
11
- self.required = !!opts[:required]
12
- self.label = opts[:label]
13
- self.hint = opts[:hint]
14
- end
8
+ def initialize(name,opts = {})
9
+ self.data_type = opts[:data_type] || :string
10
+ self.name = name
11
+ self.default = opts[:default]
12
+ self.required = !!opts[:required]
13
+ self.label = opts[:label]
14
+ self.hint = opts[:hint]
15
+ end
15
16
 
16
- def required?
17
- required
18
- end
17
+ def required?
18
+ required
19
+ end
19
20
 
20
- def numerical?
21
- [:integer,:float,:real].include?(data_type)
22
- end
21
+ def numerical?
22
+ [:integer,:float,:real].include?(data_type)
23
+ end
23
24
 
24
- def value(value)
25
- value = value.presence || default
26
- if !value.nil?
27
- case data_type
28
- when :string, :password
29
- value.to_s
30
- when :integer
31
- value.to_i
32
- when :float, :real
33
- value.to_f
34
- when :boolean
35
- !!value
36
- else
37
- nil
25
+ def value(value)
26
+ value = value.presence || default
27
+ if !value.nil?
28
+ case data_type
29
+ when :string, :password
30
+ value.to_s
31
+ when :integer
32
+ value.to_i
33
+ when :float, :real
34
+ value.to_f
35
+ when :boolean
36
+ !!value
37
+ else
38
+ nil
39
+ end
38
40
  end
39
41
  end
40
- end
41
42
 
42
- end
43
+ end
44
+ end
@@ -1,41 +1,43 @@
1
- class PreferenceGroup
1
+ module SerialPreference
2
+ class PreferenceGroup
2
3
 
3
- attr_accessor :name, :label
4
+ attr_accessor :name, :label
4
5
 
5
- def initialize(name, opts = {})
6
- @preferences = {}
7
- @name = name
8
- @label = opts[:label]
9
- end
6
+ def initialize(name, opts = {})
7
+ @preferences = {}
8
+ @name = name
9
+ @label = opts[:label]
10
+ end
10
11
 
11
- def label
12
- @label.presence || name.to_s.titleize
13
- end
12
+ def label
13
+ @label.presence || name.to_s.titleize
14
+ end
14
15
 
15
- def preference_keys
16
- @preferences.keys
17
- end
16
+ def preference_keys
17
+ @preferences.keys
18
+ end
18
19
 
19
- def preferences
20
- @preferences.values
21
- end
20
+ def preferences
21
+ @preferences.values
22
+ end
22
23
 
23
- def pref(name,opts = {})
24
- @preferences[name] = Preference.new(name,opts)
25
- end
24
+ def pref(name,opts = {})
25
+ @preferences[name] = Preference.new(name,opts)
26
+ end
26
27
 
27
- Preference::SUPPORTED_TYPES.each do |dt|
28
- define_method dt do |name,opts = {}|
29
- pref(name,opts.merge!(:data_type => dt))
28
+ SerialPreference::Preference::SUPPORTED_TYPES.each do |dt|
29
+ define_method dt do |name,opts = {}|
30
+ pref(name,opts.merge!(:data_type => dt))
31
+ end
30
32
  end
31
- end
32
33
 
33
- def respond_to?(name,*opts)
34
- @preferences[name].present?
35
- end
34
+ def respond_to?(name,*opts)
35
+ @preferences[name].present?
36
+ end
36
37
 
37
- def method_missing(name,*opts,&block)
38
- pref(name,*opts)
39
- end
38
+ def method_missing(name,*opts,&block)
39
+ pref(name,*opts)
40
+ end
40
41
 
41
- end
42
+ end
43
+ end
@@ -1,3 +1,3 @@
1
1
  module SerialPreference
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -34,7 +34,7 @@ module SerialPreference
34
34
 
35
35
  def preference_group(name, opts={},&block)
36
36
  self.preference_groups[current_context] ||= {}
37
- self.preference_groups[current_context][name] ||= PreferenceGroup.new(name,opts)
37
+ self.preference_groups[current_context][name] ||= SerialPreference::PreferenceGroup.new(name,opts)
38
38
  self.preference_groups[current_context][name].instance_exec(&block)
39
39
  end
40
40
 
@@ -83,7 +83,7 @@ module SerialPreference
83
83
 
84
84
  def base_group
85
85
  @base_group ||= begin
86
- pg = PreferenceGroup.new(:base,:label => current_context.to_s.titleize)
86
+ pg = SerialPreference::PreferenceGroup.new(:base,:label => current_context.to_s.titleize)
87
87
  self.preference_groups[current_context] ||= {}
88
88
  self.preference_groups[current_context][:base] = pg
89
89
  pg
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: serial_preference
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: