simple_model 1.2.20 → 1.2.21

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.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZGE5MTUyZjlmNDkxYzE3MGU1MDFiNDE4YzM1NDBlNzEyYWE0MmUwNg==
5
- data.tar.gz: !binary |-
6
- NTc3ODA2NzI4YTZiNjE4YzQ0MGUzY2E3NzQ1ZTkxOWNjNjhkMDY4Yg==
2
+ SHA1:
3
+ metadata.gz: dd528898a8977c244515a34000104c0d80e4887f
4
+ data.tar.gz: 5619f6e8fe9c70f71eb0250091696911493facaf
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- ODNlYmRlZTkyMGUyODI4MTRjYTg2ZWRlMjYwMjY3ZTgzNzlkNTkxNTBkNzdm
10
- OWU0NTkxM2Q0YTdlYWViNjQ3NGM4NzIyMjliZDk2MzgxNzM4Y2U2Y2RmNDgy
11
- YTJkZWMyN2ViZGY5Mjk2YjhlZGVhZWVkZTNiMzFmMTY4NTk0Njc=
12
- data.tar.gz: !binary |-
13
- NGIwZTY1YmY5YjY4MWRmZWYxMDNhMzY4NjMwZGYxODkyODQzMjZiOGRlZDUw
14
- NjcwNGUzN2ZlZDQxMGQ4MzgxMzdlMDNhMmNhOGU3MTA3MGZkYWVmMWY0NjQw
15
- NTg4YzNhMDcxYmRjYjI2MWFhNDNjZDlmYjhjY2QyNjBhYzhiYTY=
6
+ metadata.gz: ef573fdf146f4904f3333b1ddbb3f8fdef76738bc57f1594f3e0babcd0743afd13d06c0cf4c1b63be0402fafbea11937dc92e407ea2fb130b0873414b601f065
7
+ data.tar.gz: 351e61b6f752ae47f52067e3efd33be7a315061aaaf166dbc019c570036d83bc16c706b5b683ea598f253a956af161fe8a598c19c809203ca2ad4251cc9bc4cc
data/gemfiles/4.2.gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'activesupport','~> 4.2.0.beta'
4
- gem 'activemodel','~> 4.2.0.beta'
3
+ gem 'activesupport','~> 4.2.0.rc1'
4
+ gem 'activemodel','~> 4.2.0.rc1'
5
5
 
6
6
  gemspec :path => "../"
@@ -38,7 +38,7 @@ module SimpleModel
38
38
 
39
39
  def set_attribute(attr,val)
40
40
  options = self.class.defined_attributes[attr] || {}
41
- if allow_attribute_action?(self,val,options)
41
+ if allow_attribute_action?(val,options)
42
42
  val = fetch_default_value(options[:default]) if (!options[:allow_blank] && options.key?(:default) && val.blank?)
43
43
  val = options[:on_set].call(self,val) unless (!options.key?(:on_set) || (val.blank? && !options[:allow_blank]) )
44
44
  will_change = "#{attr}_will_change!".to_sym
@@ -87,8 +87,9 @@ module SimpleModel
87
87
  def attributes_with_for_init(attrs)
88
88
  d = attrs.with_indifferent_access
89
89
  self.class.defined_attributes.each do |k,v|
90
- if allow_set_default?(d,k,v)
91
- d[k] = fetch_default_value(v[:default])
90
+ key = k.to_sym
91
+ if allow_init_default?(d,key,v)
92
+ d[key] = fetch_default_value(v[:default])
92
93
  end
93
94
  end
94
95
  d
@@ -96,11 +97,15 @@ module SimpleModel
96
97
 
97
98
  # Only set default if there is a default value, initializing is allow and
98
99
  # new attributes do not have a value to set and
99
- def allow_set_default?(d,k,v)
100
- (v[:default] && (v[:initialize] != false) && (!d.key?(k) && !d.key?(self.class.alias_attributes[k])))
100
+ def allow_init_default?(d,k,v)
101
+ (v[:default] && (v[:initialize] != false) && (!d.key?(k) && !attributes_have_alias?(d,k)))
101
102
  end
102
103
 
103
- def allow_attribute_action?(obj,val,options)
104
+ def attributes_have_alias?(attrs,attr)
105
+ !(self.class.alias_attributes.select{ |a, m| (m == attr && attrs.key?(a.to_sym)) }).empty?
106
+ end
107
+
108
+ def allow_attribute_action?(val,options)
104
109
  return true if (options[:if].blank? && options[:unless].blank?)
105
110
  b = true
106
111
  if options[:if].is_a?(Symbol)
@@ -110,7 +115,7 @@ module SimpleModel
110
115
  b = (b && send(options[:if]))
111
116
  end
112
117
  end
113
- b = (b && options[:if].call(obj,val)) if options[:if].is_a?(Proc)
118
+ b = (b && options[:if].call(self,val)) if options[:if].is_a?(Proc)
114
119
  if options[:unless].is_a?(Symbol)
115
120
  if options[:unless] == :blank
116
121
  b = (b && !val.blank?)
@@ -118,7 +123,7 @@ module SimpleModel
118
123
  b = (b && !send(options[:unless]))
119
124
  end
120
125
  end
121
- b = (b && !options[:unless].call(obj,val)) if options[:unless].is_a?(Proc)
126
+ b = (b && !options[:unless].call(self,val)) if options[:unless].is_a?(Proc)
122
127
  b
123
128
  end
124
129
 
@@ -256,16 +261,25 @@ module SimpleModel
256
261
 
257
262
  # Creates alias setter and getter for the supplied attribute using the supplied alias
258
263
  # See spec for example.
259
- def alias_attribute(new_alias,attribute)
260
- alias_attributes[attribute] = new_alias
264
+ def alias_attribute(new_alias,attr)
265
+
266
+ # get to the base attribute
267
+ while alias_attributes[attr]
268
+ attr = alias_attributes[attr]
269
+ end
270
+
271
+ raise UndefinedAttribute, "#{attr} is not a defined attribute so it cannot be aliased" unless defined_attributes[attr]
272
+
273
+ alias_attributes[new_alias] = attr
274
+
261
275
  define_method(new_alias) do
262
- self.send(attribute)
276
+ self.send(attr)
263
277
  end
264
278
  define_method("#{new_alias}?") do
265
- self.send("#{attribute}?")
279
+ self.send("#{attr}?")
266
280
  end
267
281
  define_method("#{new_alias.to_s}=") do |*args, &block|
268
- self.send("#{attribute.to_s}=",*args, &block)
282
+ self.send("#{attr.to_s}=",*args, &block)
269
283
  end
270
284
  end
271
285
 
@@ -305,8 +319,8 @@ module SimpleModel
305
319
  # hack to keep things working when a class inherits from a super that
306
320
  # has ActiveModel::Dirty included
307
321
  def inherited(base)
308
- base.defined_attributes = self.defined_attributes.dup
309
- base.alias_attributes = self.alias_attributes.dup
322
+ base.defined_attributes = self.defined_attributes.merge(base.defined_attributes)
323
+ base.alias_attributes = self.alias_attributes.merge(base.alias_attributes)
310
324
  super
311
325
  # Rails 3.0 Hack
312
326
  if (ActiveModel::VERSION::MAJOR == 3 && ActiveModel::VERSION::MINOR == 0)
@@ -1,4 +1,5 @@
1
1
  module SimpleModel
2
2
  class ActionError < StandardError; end
3
3
  class ValidationError < StandardError; end
4
+ class UndefinedAttribute < StandardError; end
4
5
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleModel
2
- VERSION = "1.2.20"
2
+ VERSION = "1.2.21"
3
3
  end
data/simple_model.gemspec CHANGED
@@ -12,8 +12,8 @@ Gem::Specification.new do |s|
12
12
  s.summary = %q{Simpifies building tableless models or models backed by webservices}
13
13
  s.description = %q{Simpifies building tableless models or models backed by webservices. Create data type specific attributes with default if values.}
14
14
 
15
- s.add_runtime_dependency 'activesupport','<= 4.2.0.beta4','>= 3.0'
16
- s.add_runtime_dependency 'activemodel','<= 4.2.0.beta4','>= 3.0'
15
+ s.add_runtime_dependency 'activesupport','>= 3.0', '< 5.0'
16
+ s.add_runtime_dependency 'activemodel','>= 3.0', '< 5.0'
17
17
 
18
18
  s.add_development_dependency 'rspec'
19
19
  s.add_development_dependency 'rspec-autotest'
@@ -232,9 +232,12 @@ describe SimpleModel::Attributes do
232
232
  class MyBase
233
233
  include SimpleModel::Attributes
234
234
  has_boolean :bar
235
- has_attribute :str
235
+ has_attribute :str, :stuff
236
+ has_currency :amount, :default => BigDecimal("0.0"), :initialize => false
236
237
  has_dates :some, :thing, :default => :fetch_date, :allow_blank => false, :initialize => false
237
238
  alias_attribute :other, :bar
239
+ alias_attribute :other_amount, :amount
240
+
238
241
  def fetch_date
239
242
  Date.today
240
243
  end
@@ -244,6 +247,11 @@ describe SimpleModel::Attributes do
244
247
  has_boolean :foo
245
248
  has_int :str
246
249
  end
250
+
251
+ class NewestBase < NewerBase
252
+ alias_attribute :some_amount, :other_amount
253
+ end
254
+
247
255
  end
248
256
  it "should merge defined attributes when class are inherited" do
249
257
  NewerBase.attribute_defined?(:bar).should eql(true)
@@ -267,6 +275,12 @@ describe SimpleModel::Attributes do
267
275
  MyBase.new(:other => true).bar?.should eql(true)
268
276
  NewerBase.new(:other => true).bar?.should eql(true)
269
277
  end
278
+
279
+ it "should properly alias attributes from parent class" do
280
+ nb = NewestBase.new(:some_amount => 1.0)
281
+ nb.other_amount.should eql(1.0.to_d)
282
+ nb.amount.should eql(1.0.to_d)
283
+ end
270
284
  end
271
285
 
272
286
  after(:all) do
metadata CHANGED
@@ -1,95 +1,95 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.20
4
+ version: 1.2.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua T Mckinney
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-18 00:00:00.000000000 Z
11
+ date: 2014-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - <=
18
- - !ruby/object:Gem::Version
19
- version: 4.2.0.beta4
20
- - - ! '>='
17
+ - - ">="
21
18
  - !ruby/object:Gem::Version
22
19
  version: '3.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - <=
28
- - !ruby/object:Gem::Version
29
- version: 4.2.0.beta4
30
- - - ! '>='
27
+ - - ">="
31
28
  - !ruby/object:Gem::Version
32
29
  version: '3.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: activemodel
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - <=
38
- - !ruby/object:Gem::Version
39
- version: 4.2.0.beta4
40
- - - ! '>='
37
+ - - ">="
41
38
  - !ruby/object:Gem::Version
42
39
  version: '3.0'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '5.0'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - <=
48
- - !ruby/object:Gem::Version
49
- version: 4.2.0.beta4
50
- - - ! '>='
47
+ - - ">="
51
48
  - !ruby/object:Gem::Version
52
49
  version: '3.0'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '5.0'
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: rspec
55
55
  requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
- - - ! '>='
57
+ - - ">="
58
58
  - !ruby/object:Gem::Version
59
59
  version: '0'
60
60
  type: :development
61
61
  prerelease: false
62
62
  version_requirements: !ruby/object:Gem::Requirement
63
63
  requirements:
64
- - - ! '>='
64
+ - - ">="
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0'
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: rspec-autotest
69
69
  requirement: !ruby/object:Gem::Requirement
70
70
  requirements:
71
- - - ! '>='
71
+ - - ">="
72
72
  - !ruby/object:Gem::Version
73
73
  version: '0'
74
74
  type: :development
75
75
  prerelease: false
76
76
  version_requirements: !ruby/object:Gem::Requirement
77
77
  requirements:
78
- - - ! '>='
78
+ - - ">="
79
79
  - !ruby/object:Gem::Version
80
80
  version: '0'
81
81
  - !ruby/object:Gem::Dependency
82
82
  name: autotest
83
83
  requirement: !ruby/object:Gem::Requirement
84
84
  requirements:
85
- - - ! '>='
85
+ - - ">="
86
86
  - !ruby/object:Gem::Version
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
90
  version_requirements: !ruby/object:Gem::Requirement
91
91
  requirements:
92
- - - ! '>='
92
+ - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: '0'
95
95
  description: Simpifies building tableless models or models backed by webservices.
@@ -100,9 +100,9 @@ executables: []
100
100
  extensions: []
101
101
  extra_rdoc_files: []
102
102
  files:
103
- - .gitignore
104
- - .rspec
105
- - .travis.yml
103
+ - ".gitignore"
104
+ - ".rspec"
105
+ - ".travis.yml"
106
106
  - Gemfile
107
107
  - LICENSE.txt
108
108
  - README.md
@@ -137,17 +137,17 @@ require_paths:
137
137
  - lib
138
138
  required_ruby_version: !ruby/object:Gem::Requirement
139
139
  requirements:
140
- - - ! '>='
140
+ - - ">="
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
143
  required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  requirements:
145
- - - ! '>='
145
+ - - ">="
146
146
  - !ruby/object:Gem::Version
147
147
  version: '0'
148
148
  requirements: []
149
149
  rubyforge_project: simple_model
150
- rubygems_version: 2.4.2
150
+ rubygems_version: 2.4.3
151
151
  signing_key:
152
152
  specification_version: 4
153
153
  summary: Simpifies building tableless models or models backed by webservices