simple_model 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fad8b6e06b4a604873dfe174617170dce71277ab
4
- data.tar.gz: a9e8d432e3f3f7d1abff848bc6f022f186553e99
3
+ metadata.gz: 4a8ba23df5889853f9ad2166692f109b20091bfc
4
+ data.tar.gz: a8aee80ab3a098d528ba4b8028267edd4e34de5f
5
5
  SHA512:
6
- metadata.gz: 8e916c15d886c4c49530cf6ae29e66e93efde3532f3094cd654ff287a5b3ce8598c8947fdce2437f3b2dd5ebb16f9940c28070d595cb0f60f432bc9fc2b01e65
7
- data.tar.gz: 2eccebd37cf6fd8909296c83cb4c0c501205364c2f029942ec7d367a72d2af5c50e2d2db0bf979314f9e34542cbf496cabb3cfc5abc9856072771efc6d3a9d83
6
+ metadata.gz: a8968daba7cc06a8be4d3b98670fd15d9c857dfdc18dc16fedc2c3a6fe7c6f3ce1fdcc6f7e0e0fe9eb85ff64b47253c65c753bf2c05ffeca3e9060e261f6e07d
7
+ data.tar.gz: 83f31f449c53ea75bac4f14ba57a827c72130ae2eebd36675e6f9e84fa2bba6d8b13874aca613ae6283167411e357591c04fed95187d9e74c75b768cb48245d4
@@ -8,8 +8,6 @@ rvm:
8
8
  - jruby
9
9
  script: bundle exec rspec spec
10
10
  gemfile:
11
- - gemfiles/3.0.gemfile
12
- - gemfiles/3.1.gemfile
13
11
  - gemfiles/3.2.gemfile
14
12
  - gemfiles/4.0.gemfile
15
13
  - gemfiles/4.1.gemfile
@@ -19,8 +19,8 @@ module SimpleModel
19
19
  :has_time => {:cast_to => :to_time, :alias => :has_times}
20
20
  }.freeze
21
21
 
22
- def initialize(*attrs)
23
- attrs = attrs.extract_options!
22
+ def initialize(attrs={})
23
+ attrs ||= {}
24
24
  attrs = self.class.before_initialize.call(self,attrs) if self.class.before_initialize
25
25
  set(attrs)
26
26
  defaults = default_attributes_for_init
@@ -69,7 +69,7 @@ module SimpleModel
69
69
  ab = opts[:allow_blank]
70
70
  val = fetch_default_value(opts[:default]) unless skip_set_default?(attr,opts,val,ab)
71
71
  unless (opts[:boolean] ? (!ab && val.blank? && (val != false)) : (!ab && val.blank?))
72
- val = opts[:on_set].call(self,val) if opts.has_key?(:on_set)
72
+ val = process_on_set(opts[:on_set],val) if opts.has_key?(:on_set)
73
73
  send("#{attr}_will_change!") if initialized?(attr) && val != attributes[attr_key]
74
74
  attributes[attr_key] = val
75
75
  end
@@ -77,6 +77,14 @@ module SimpleModel
77
77
  end
78
78
  end
79
79
 
80
+ def process_on_set(on_set,val)
81
+ if on_set.is_a?(Symbol)
82
+ val.__send__(on_set)
83
+ else
84
+ on_set.call(self,val)
85
+ end
86
+ end
87
+
80
88
  # TODO: Returning just val in Rails 3 HashWithIndifferentAccess causes weird issue where if value is an array the array is reset,
81
89
  # revert to return to just val when Rails 3 support is dropped to improve performance
82
90
  def get_attribute(attr,opts=nil)
@@ -226,8 +234,8 @@ module SimpleModel
226
234
  options = attributes.extract_options!
227
235
  options = method_options[:options].merge(options) if method_options[:options]
228
236
  options = default_attribute_settings.merge(options)
229
- options[:on_set] = lambda {|obj,val| val.send(method_options[:cast_to]) } if method_options[:cast_to]
230
- create_attribute_methods(attributes,options)
237
+ options[:on_set] = method_options[:cast_to] if method_options[:cast_to]
238
+ create_attribute_methods(attributes,options.freeze)
231
239
  end
232
240
  module_eval("alias #{method_options[:alias]} #{method}") if method_options[:alias]
233
241
  end
@@ -395,23 +403,13 @@ module SimpleModel
395
403
  end
396
404
 
397
405
  # Must inherit super's defined_attributes and alias_attributes
398
- # Rails 3.0 does some weird stuff with ActiveModel::Dirty so we need a
399
- # hack to keep things working when a class inherits from a super that
400
- # has ActiveModel::Dirty included
401
406
  def inherited(base)
402
407
  base.defined_attributes = defined_attributes.merge(base.defined_attributes)
403
408
  base.alias_attributes = alias_attributes.merge(base.alias_attributes)
404
409
  super
405
- # Rails 3.0 Hack
406
- if (ActiveModel::VERSION::MAJOR == 3 && ActiveModel::VERSION::MINOR < 1)
407
- base.attribute_method_suffix '_changed?', '_change', '_will_change!', '_was'
408
- base.attribute_method_affix :prefix => 'reset_', :suffix => '!'
409
- end
410
410
  end
411
411
  end # end ClassMethods
412
412
 
413
- # Rails 3.0 does some weird stuff with ActiveModel::Dirty so we need a
414
- # hack to keep things working when a class includes a module that has
415
413
  # ActiveModel::Dirty included
416
414
  def self.included(base)
417
415
  base.extend(Attributes::ClassMethods)
@@ -420,12 +418,6 @@ module SimpleModel
420
418
  base.extend ActiveModel::Naming
421
419
  base.extend ActiveModel::Callbacks
422
420
  base.send(:include, ActiveModel::Validations::Callbacks)
423
-
424
- # Rails 3.0 Hack
425
- if (ActiveModel::VERSION::MAJOR == 3 && ActiveModel::VERSION::MINOR < 1)
426
- base.attribute_method_suffix '_changed?', '_change', '_will_change!', '_was'
427
- base.attribute_method_affix :prefix => 'reset_', :suffix => '!'
428
- end
429
421
  end
430
422
  end
431
423
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleModel
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
@@ -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','>= 3.0', '< 5.0'
16
- s.add_runtime_dependency 'activemodel','>= 3.0', '< 5.0'
15
+ s.add_runtime_dependency 'activesupport','>= 3.2', '< 5.0'
16
+ s.add_runtime_dependency 'activemodel','>= 3.2', '< 5.0'
17
17
 
18
18
  s.add_development_dependency 'rspec'
19
19
  s.add_development_dependency 'rspec-autotest'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
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: 2015-01-25 00:00:00.000000000 Z
11
+ date: 2015-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,7 +16,7 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.0'
19
+ version: '3.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '5.0'
@@ -26,7 +26,7 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '3.0'
29
+ version: '3.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '5.0'
@@ -36,7 +36,7 @@ dependencies:
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '3.0'
39
+ version: '3.2'
40
40
  - - "<"
41
41
  - !ruby/object:Gem::Version
42
42
  version: '5.0'
@@ -46,7 +46,7 @@ dependencies:
46
46
  requirements:
47
47
  - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: '3.0'
49
+ version: '3.2'
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '5.0'
@@ -108,8 +108,6 @@ files:
108
108
  - README.md
109
109
  - Rakefile
110
110
  - benchmarks/simple_model.rb
111
- - gemfiles/3.0.gemfile
112
- - gemfiles/3.1.gemfile
113
111
  - gemfiles/3.2.gemfile
114
112
  - gemfiles/4.0.gemfile
115
113
  - gemfiles/4.1.gemfile
@@ -149,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
147
  version: '0'
150
148
  requirements: []
151
149
  rubyforge_project: simple_model
152
- rubygems_version: 2.4.3
150
+ rubygems_version: 2.4.6
153
151
  signing_key:
154
152
  specification_version: 4
155
153
  summary: Simpifies building tableless models or models backed by webservices
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem 'activesupport','~> 3.0.1'
4
- gem 'activemodel','~> 3.0.1'
5
-
6
- gemspec :path => "../"
@@ -1,6 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem 'activesupport','~> 3.1.1'
4
- gem 'activemodel','~> 3.1.1'
5
-
6
- gemspec :path => "../"