serial_preference 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -68,8 +68,8 @@ Or install it yourself as:
68
68
  # something you can customize in your form perhaps?
69
69
  Company.preference_groups.each do |pg| # => returns an array of preference groups
70
70
  # pg.name => Name of Preference Group as specified in map e.g. Preferred Ledgers
71
- # pg.preferences => Hash of Preference Definitions keyed by Preference Name e.g. :taxable, :vat_no etc.
72
- pg.preferences.values.each do |preference|
71
+ # pg.preferences => Array of Preference Definitions
72
+ pg.preferences.each do |preference|
73
73
  # preference => PreferenceDefinition
74
74
  f.input preference.name, required: preference.required?, placeholder: preference.default, as: preference.field_type
75
75
  end
@@ -21,6 +21,10 @@ module SerialPreference
21
21
  build_preference_definitions
22
22
  end
23
23
 
24
+ def preference_definition(name)
25
+ _preference_map.definition_for(name)
26
+ end
27
+
24
28
  private
25
29
 
26
30
  def build_preference_definitions
@@ -30,12 +34,12 @@ module SerialPreference
30
34
 
31
35
  key = preference.name
32
36
  define_method("#{key}=") do |value|
33
- write_preference_attribute(_preferences_attribute,key,preference.value(value))
37
+ write_preference_attribute(_preferences_attribute,key,preference_definition(key).value(value))
34
38
  end
35
39
 
36
40
  define_method(key) do
37
41
  value = read_preference_attribute(_preferences_attribute,key)
38
- preference.value(value)
42
+ preference_definition(key).value(value)
39
43
  end
40
44
 
41
45
  if preference.boolean?
@@ -48,7 +48,7 @@ module SerialPreference
48
48
  end
49
49
 
50
50
  def all_preference_definitions
51
- preference_groups.map{|x|x.preferences.values}.flatten
51
+ @preference_names_cache.values
52
52
  end
53
53
 
54
54
  def all_preference_names
@@ -59,6 +59,10 @@ module SerialPreference
59
59
  @preference_groups.map{|x|x.name}
60
60
  end
61
61
 
62
+ def definition_for(name)
63
+ @preference_names_cache[name]
64
+ end
65
+
62
66
  private
63
67
 
64
68
  def activate_group(group_name = :base)
@@ -66,8 +70,8 @@ module SerialPreference
66
70
  end
67
71
 
68
72
  def push_preference(preference)
69
- @preference_names_cache[preference.name] = 1
70
- @current_group.preferences[preference.name] = preference
73
+ @preference_names_cache[preference.name] = preference
74
+ @current_group.preferences.push(preference)
71
75
  end
72
76
 
73
77
  def find_or_create_group(name)
@@ -79,7 +83,7 @@ module SerialPreference
79
83
  end
80
84
 
81
85
  def create_group(name = :base)
82
- PreferenceGroup.new(name,{}).tap do |pg|
86
+ PreferenceGroup.new(name,[]).tap do |pg|
83
87
  @preference_groups.push(pg)
84
88
  end
85
89
  end
@@ -1,3 +1,3 @@
1
1
  module SerialPreference
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe SerialPreference::Preferenzer do
4
4
 
5
5
  before(:each) do
6
- @base = described_class::PreferenceGroup.new(:base,{})
6
+ @base = described_class::PreferenceGroup.new(:base,[])
7
7
  @preferenzer = described_class.new
8
8
  end
9
9
 
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: 1.0.1
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -130,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
130
130
  version: '0'
131
131
  segments:
132
132
  - 0
133
- hash: 4069385045996576704
133
+ hash: -3242840560395450762
134
134
  required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  none: false
136
136
  requirements:
@@ -139,7 +139,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  version: '0'
140
140
  segments:
141
141
  - 0
142
- hash: 4069385045996576704
142
+ hash: -3242840560395450762
143
143
  requirements: []
144
144
  rubyforge_project:
145
145
  rubygems_version: 1.8.24