simple_model 1.2.21 → 1.2.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/benchmarks/simple_model.rb +39 -0
- data/lib/simple_model/attributes.rb +18 -15
- data/lib/simple_model/version.rb +1 -1
- metadata +23 -22
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YjQyN2Y0MzE5YjZkODA2MGIwOGYyNzRiNzk5NmUyMjYzYmEwNTExZg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YzVjNGU4MGI2ZDFlYmE5M2ExODYyZWZkODUwYTZlMzhhMGU4YWE5NQ==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MjAyM2JkMDRhMjdkMjc4NzRiMjE1OTI5MDlmNTJjMGMyNDQwM2E3ZjdhYTcz
|
10
|
+
YWQwY2RhMmVmNDliYzY0ZmQ5NjhlM2Y1MWVlMzljODQ4MWU5ZTc0OWRiZTgw
|
11
|
+
MTcwNmNmYjA5NWYyNzhmMjMwZDU0YTkzNGIzMmNlZGRkODU3ZTE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YWQ2M2MzYTRmNjI5NmQwZWFmNTQ0ODAzZjM1NDdkNGEwNThhMWFjMjRiMzBk
|
14
|
+
ZTA5ZDhlZjVjNDExYWY0ZTIwMDdmNTVjZDdjOTIzZTZkMmJmMjVkNGRkMjYz
|
15
|
+
ZjYzY2QyYTI1NDg2OWEyODIzMDY3MGI4OTQzOTYwNzEyZWFiZWY=
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class BenchClass < SimpleModel::Base
|
2
|
+
has_int :num
|
3
|
+
has_date :date, :default => :today
|
4
|
+
has_decimal :dec
|
5
|
+
|
6
|
+
def today
|
7
|
+
Date.today
|
8
|
+
end
|
9
|
+
end
|
10
|
+
Benchmark.bm do |b|
|
11
|
+
b.report("initialize") do
|
12
|
+
30000.times.each do
|
13
|
+
BenchClass.new()
|
14
|
+
end
|
15
|
+
end
|
16
|
+
BenchClass.new()
|
17
|
+
b.report("initialize with attrs") do
|
18
|
+
30000.times.each do
|
19
|
+
BenchClass.new(:num => 1, :dec => "12.4")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
b.report("get") do
|
23
|
+
30000.times.each do
|
24
|
+
klass = BenchClass.new
|
25
|
+
klass.num
|
26
|
+
klass.dec
|
27
|
+
klass.date
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
b.report("set") do
|
32
|
+
30000.times.each do
|
33
|
+
klass = BenchClass.new
|
34
|
+
klass.num = 1
|
35
|
+
klass.dec = '12.4'
|
36
|
+
klass.date = "2014-12-25"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -40,9 +40,8 @@ module SimpleModel
|
|
40
40
|
options = self.class.defined_attributes[attr] || {}
|
41
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
|
-
val = options[:on_set].call(self,val)
|
44
|
-
|
45
|
-
self.send(will_change) if (initialized?(attr) && val != self.attributes[attr])
|
43
|
+
val = options[:on_set].call(self,val) if options[:on_set] #(!options.key?(:on_set) || (val.blank? && !options[:allow_blank]) )
|
44
|
+
self.send("#{attr}_will_change!") if (initialized?(attr) && val != self.attributes[attr])
|
46
45
|
self.attributes[attr] = val
|
47
46
|
options[:after_set].call(self,val) if options[:after_set]
|
48
47
|
end
|
@@ -98,7 +97,7 @@ module SimpleModel
|
|
98
97
|
# Only set default if there is a default value, initializing is allow and
|
99
98
|
# new attributes do not have a value to set and
|
100
99
|
def allow_init_default?(d,k,v)
|
101
|
-
(v[:default] &&
|
100
|
+
(v[:default] && v[:initialize] && (!d.key?(k) && !attributes_have_alias?(d,k)))
|
102
101
|
end
|
103
102
|
|
104
103
|
def attributes_have_alias?(attrs,attr)
|
@@ -106,24 +105,28 @@ module SimpleModel
|
|
106
105
|
end
|
107
106
|
|
108
107
|
def allow_attribute_action?(val,options)
|
109
|
-
return true
|
108
|
+
return true unless (options[:if] || options[:unless])
|
110
109
|
b = true
|
111
|
-
|
112
|
-
|
113
|
-
|
110
|
+
opt = options[:if]
|
111
|
+
if opt.is_a?(Symbol)
|
112
|
+
if opt == :blank
|
113
|
+
b = val.blank?
|
114
114
|
else
|
115
|
-
b =
|
115
|
+
b = send(opt)
|
116
116
|
end
|
117
|
+
elsif opt.is_a?(Proc)
|
118
|
+
b = opt.call(self,val)
|
117
119
|
end
|
118
|
-
|
119
|
-
if
|
120
|
-
if
|
121
|
-
b =
|
120
|
+
opt = options[:unless]
|
121
|
+
if opt.is_a?(Symbol)
|
122
|
+
if opt == :blank
|
123
|
+
b = !val.blank?
|
122
124
|
else
|
123
|
-
b =
|
125
|
+
b = !send(opt)
|
124
126
|
end
|
127
|
+
elsif opt.is_a?(Proc)
|
128
|
+
b = !opt.call(self,val)
|
125
129
|
end
|
126
|
-
b = (b && !options[:unless].call(self,val)) if options[:unless].is_a?(Proc)
|
127
130
|
b
|
128
131
|
end
|
129
132
|
|
data/lib/simple_model/version.rb
CHANGED
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.
|
4
|
+
version: 1.2.22
|
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-12-
|
11
|
+
date: 2014-12-10 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
|
-
- -
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
|
-
- -
|
20
|
+
- - <
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '5.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '3.0'
|
30
|
-
- -
|
30
|
+
- - <
|
31
31
|
- !ruby/object:Gem::Version
|
32
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
|
-
- -
|
37
|
+
- - ! '>='
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '3.0'
|
40
|
-
- -
|
40
|
+
- - <
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '5.0'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- -
|
47
|
+
- - ! '>='
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '3.0'
|
50
|
-
- -
|
50
|
+
- - <
|
51
51
|
- !ruby/object:Gem::Version
|
52
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,13 +100,14 @@ executables: []
|
|
100
100
|
extensions: []
|
101
101
|
extra_rdoc_files: []
|
102
102
|
files:
|
103
|
-
-
|
104
|
-
-
|
105
|
-
-
|
103
|
+
- .gitignore
|
104
|
+
- .rspec
|
105
|
+
- .travis.yml
|
106
106
|
- Gemfile
|
107
107
|
- LICENSE.txt
|
108
108
|
- README.md
|
109
109
|
- Rakefile
|
110
|
+
- benchmarks/simple_model.rb
|
110
111
|
- gemfiles/3.0.gemfile
|
111
112
|
- gemfiles/3.1.gemfile
|
112
113
|
- gemfiles/3.2.gemfile
|
@@ -137,17 +138,17 @@ require_paths:
|
|
137
138
|
- lib
|
138
139
|
required_ruby_version: !ruby/object:Gem::Requirement
|
139
140
|
requirements:
|
140
|
-
- -
|
141
|
+
- - ! '>='
|
141
142
|
- !ruby/object:Gem::Version
|
142
143
|
version: '0'
|
143
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
145
|
requirements:
|
145
|
-
- -
|
146
|
+
- - ! '>='
|
146
147
|
- !ruby/object:Gem::Version
|
147
148
|
version: '0'
|
148
149
|
requirements: []
|
149
150
|
rubyforge_project: simple_model
|
150
|
-
rubygems_version: 2.4.
|
151
|
+
rubygems_version: 2.4.2
|
151
152
|
signing_key:
|
152
153
|
specification_version: 4
|
153
154
|
summary: Simpifies building tableless models or models backed by webservices
|