mod_factor 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.markdown CHANGED
@@ -19,22 +19,27 @@ Include ModFactor::Owner to owner:
19
19
  factors :financial_factors do
20
20
  factor :prop_one
21
21
  factor :prop_formula, :generate => true,
22
- :formula => proc {|owner|1 + 1}
22
+ :formula => proc {1 + 1}
23
23
  factor :prop_one_times_ten, :generate=>true,
24
- :formula => proc {|owner| (owner.prop_one||0) * 10}
24
+ :formula => proc {(owner.prop_one||0) * 10}
25
+ factor :prop_condition, :generate => true,
26
+ :condition => proc {|extra| prop_one},
27
+ :formula => proc {|extra| prop_one || raise("prop one is nil")}
28
+ factor :prop_default, :default=>10
25
29
  end
26
30
  end
27
31
 
28
32
 
29
- Some sample usage:
33
+ Sample usages:
30
34
 
31
35
  some_model = SomeModel.new
32
36
  some_model.prop_one # nil
33
37
  some_model.prop_one = 10 # 10
38
+ some_model.prop_default # 10
34
39
  some_model.calculate
35
40
  some_model.prop_one_times_ten # 100
36
41
 
37
- Include some math helper
42
+ Include Math helper:
38
43
 
39
44
  class SomeModel < ActiveRecord::Base
40
45
  include ModFactor::Math
@@ -43,6 +48,10 @@ Include some math helper
43
48
  Provides following:
44
49
 
45
50
  some_model.sigma_geometric # http://en.wikipedia.org/wiki/Geometric_progression
51
+
52
+ Use validates as normal:
53
+
54
+ validates :prop_one, :presence=>true
46
55
 
47
56
 
48
57
  Contributing to mod_factor
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
@@ -10,6 +10,12 @@ module ModFactor
10
10
  obj.instance_variable_set "@#{factor.key.to_sym}", factor.amount
11
11
  obj.factor_hash[factor.key.to_sym] = factor.amount
12
12
  end
13
+ base.factor_define.keys.each do |key|
14
+ if base.factor_define[key][:default] && obj.send(key).nil?
15
+ obj.instance_variable_set "@#{key}", base.factor_define[key][:default]
16
+ end
17
+ end
18
+
13
19
  end
14
20
  end
15
21
 
data/mod_factor.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "mod_factor"
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ryan Wong"]
12
- s.date = "2012-03-16"
12
+ s.date = "2012-03-20"
13
13
  s.description = "mod factor"
14
14
  s.email = "ryan@idolgo.com"
15
15
  s.extra_rdoc_files = [
@@ -26,6 +26,7 @@ describe ModFactor::Owner do
26
26
 
27
27
  factors :financial_factors do
28
28
  factor :prop_one
29
+ factor :prop_store
29
30
  factor :prop_formula, :generate => true,
30
31
  :formula => proc {|extra| 1 + 1}
31
32
  factor :prop_one_times_ten, :generate=>true,
@@ -34,9 +35,12 @@ describe ModFactor::Owner do
34
35
  :formula => proc {|extra| members.first.try :prop_member}
35
36
  factor :prop_extra, :generate => true,
36
37
  :formula => proc {|extra| extra[:extra_value]}
37
- factor :prop_condition, :generate => true, :condition => proc {|extra| prop_one},
38
+ factor :prop_condition, :generate => true, :condition => proc {|extra| prop_one == 10},
38
39
  :formula => proc {|extra| prop_one || raise("prop one is nil")}
40
+ factor :prop_default, :default=>10
39
41
  end
42
+
43
+ validates :prop_one, :presence=>true
40
44
  end
41
45
  end
42
46
 
@@ -66,7 +70,7 @@ describe ModFactor::Owner do
66
70
  end
67
71
  end
68
72
 
69
- subject { Family.create! }
73
+ subject { Family.create! :prop_one => 5 }
70
74
 
71
75
  it "should has define factors" do
72
76
  subject.respond_to? :financial_factors
@@ -79,7 +83,7 @@ describe ModFactor::Owner do
79
83
 
80
84
  it "should store factor in factors table" do
81
85
  expect {
82
- subject.prop_one = 10
86
+ subject.prop_store = 10
83
87
  subject.save!
84
88
  }.to change {subject.financial_factors.size}
85
89
  end
@@ -125,4 +129,13 @@ describe ModFactor::Owner do
125
129
  subject.prop_condition.should == 10
126
130
  end
127
131
 
132
+ it "should validate false when require factor blank" do
133
+ subject.prop_one = nil
134
+ subject.should_not be_valid
135
+ end
136
+
137
+ it "should have default value" do
138
+ subject.prop_default.should == 10
139
+ end
140
+
128
141
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mod_factor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-16 00:00:00.000000000Z
12
+ date: 2012-03-20 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n
16
- requirement: &81917520 !ruby/object:Gem::Requirement
16
+ requirement: &84473610 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 0.6.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *81917520
24
+ version_requirements: *84473610
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activerecord
27
- requirement: &81917130 !ruby/object:Gem::Requirement
27
+ requirement: &84473190 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.0.9
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *81917130
35
+ version_requirements: *84473190
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &81916800 !ruby/object:Gem::Requirement
38
+ requirement: &84437070 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *81916800
46
+ version_requirements: *84437070
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sqlite3
49
- requirement: &81916310 !ruby/object:Gem::Requirement
49
+ requirement: &84436750 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *81916310
57
+ version_requirements: *84436750
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
- requirement: &81911540 !ruby/object:Gem::Requirement
60
+ requirement: &84436400 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 2.8.0
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *81911540
68
+ version_requirements: *84436400
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sqlite3-ruby
71
- requirement: &81911220 !ruby/object:Gem::Requirement
71
+ requirement: &84436050 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *81911220
79
+ version_requirements: *84436050
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: with_model
82
- requirement: &81910880 !ruby/object:Gem::Requirement
82
+ requirement: &84435710 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 0.1.5
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *81910880
90
+ version_requirements: *84435710
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rdoc
93
- requirement: &81910590 !ruby/object:Gem::Requirement
93
+ requirement: &84435390 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '3.12'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *81910590
101
+ version_requirements: *84435390
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: cucumber
104
- requirement: &81910220 !ruby/object:Gem::Requirement
104
+ requirement: &84435030 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *81910220
112
+ version_requirements: *84435030
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: bundler
115
- requirement: &81909850 !ruby/object:Gem::Requirement
115
+ requirement: &84434670 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,10 @@ dependencies:
120
120
  version: 1.0.0
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *81909850
123
+ version_requirements: *84434670
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: jeweler
126
- requirement: &81909500 !ruby/object:Gem::Requirement
126
+ requirement: &84434250 !ruby/object:Gem::Requirement
127
127
  none: false
128
128
  requirements:
129
129
  - - ! '>='
@@ -131,10 +131,10 @@ dependencies:
131
131
  version: 1.8.3
132
132
  type: :development
133
133
  prerelease: false
134
- version_requirements: *81909500
134
+ version_requirements: *84434250
135
135
  - !ruby/object:Gem::Dependency
136
136
  name: simplecov
137
- requirement: &81909080 !ruby/object:Gem::Requirement
137
+ requirement: &84433890 !ruby/object:Gem::Requirement
138
138
  none: false
139
139
  requirements:
140
140
  - - ! '>='
@@ -142,7 +142,7 @@ dependencies:
142
142
  version: '0'
143
143
  type: :development
144
144
  prerelease: false
145
- version_requirements: *81909080
145
+ version_requirements: *84433890
146
146
  description: mod factor
147
147
  email: ryan@idolgo.com
148
148
  executables: []
@@ -183,7 +183,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
183
  version: '0'
184
184
  segments:
185
185
  - 0
186
- hash: -660223917
186
+ hash: 290821937
187
187
  required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  none: false
189
189
  requirements: