lean-attributes 0.2.0 → 0.3.0
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 +8 -8
- data/CHANGELOG.md +9 -1
- data/README.md +21 -12
- data/lib/lean-attributes/attributes/attribute.rb +2 -4
- data/lib/lean-attributes/attributes/coercion_helpers.rb +2 -1
- data/lib/lean-attributes/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YmE0YWM3ZjBjMDJhYzBkMzNmMmIxMjgyM2FjM2U2ZDhjYmVkMTIxZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YWIyODY5MTE5MTYxNzJkMDA0NDY1M2Q1ZTIwODU0Y2JkZDkwZGZmYQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
N2Q0ODkzNGVlNmZmZjMzMmM2OWY4YzM3MWQzYTRlMTg0ZGEyNGJiMTMwYmJh
|
10
|
+
ZjU3MDdmZjBhZjkyZDg0NzUwMDUyODU3YjNiNjI5MWU4NmYxYmI0M2FjMDNh
|
11
|
+
Yzg3MTJmNDhjMGM1Y2JiODBmNmFhZDkxOWE2YWFiMWZjODZiMWY=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWM5ZGIzYjM3MzU1OWNlYWNkYjg2ZmRhZDk4MjE3MTM3M2M0MzFiNTNkMmE1
|
14
|
+
YWQ3MDkxMTllNTNkNTM2ZDdiZGVhYWY3MGZmMzEwMTZlMjhhNDVhMzdhOWFk
|
15
|
+
MDI2YTAxNjU1ZThkN2Y1ZTg0MzBmNTViYmQxZTU2ZjBiOTc3YWQ=
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4
4
|
|
5
5
|
## [Unreleased][unreleased]
|
6
6
|
|
7
|
+
## [0.3.0] - 2016-03-07
|
8
|
+
### Added
|
9
|
+
- Adds benchmarks for ActiveAttr
|
10
|
+
- Adds benchmarks for ActiveRecord::Attributes
|
11
|
+
- Adds basic support for boolean attributes
|
12
|
+
|
7
13
|
## [0.2.0] - 2015-09-18
|
8
14
|
### Added
|
9
15
|
- Adds content to README.md
|
@@ -31,6 +37,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
31
37
|
### Added
|
32
38
|
- Initial release
|
33
39
|
|
34
|
-
[unreleased]: https://github.com/lleolin/lean-attributes/compare/v0.
|
40
|
+
[unreleased]: https://github.com/lleolin/lean-attributes/compare/v0.3.0...HEAD
|
41
|
+
[0.3.0]: https://github.com/lleolin/lean-attributes/compare/v0.2.0...v0.3.0
|
42
|
+
[0.2.0]: https://github.com/lleolin/lean-attributes/compare/v0.1.0...v0.2.0
|
35
43
|
[0.1.0]: https://github.com/lleolin/lean-attributes/compare/v0.0.2...v0.1.0
|
36
44
|
[0.0.2]: https://github.com/lleolin/lean-attributes/compare/v0.0.1...v0.0.2
|
data/README.md
CHANGED
@@ -92,6 +92,9 @@ class ReadingProgress
|
|
92
92
|
value
|
93
93
|
end
|
94
94
|
end
|
95
|
+
|
96
|
+
# progress = ReadingProgress.new(current_page: 0)
|
97
|
+
# progress.current_page # => 1
|
95
98
|
```
|
96
99
|
|
97
100
|
Another way to contain such behavior is to create a `CurrentPage` class to represent your attribute instead of an Integer. The power is yours.
|
@@ -100,18 +103,24 @@ Another way to contain such behavior is to create a `CurrentPage` class to repre
|
|
100
103
|
Lean::Attributes is meant to be relatively lightweight and fast.
|
101
104
|
|
102
105
|
```
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
Lean::Attributes: string values for integer attributes :
|
108
|
-
FastAttributes:
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
Virtus:
|
106
|
+
Lean::Attributes: without values : 3119783.8 i/s
|
107
|
+
FastAttributes: without values : 3055309.1 i/s - 1.02x slower
|
108
|
+
ActiveAttr: without values : 1554020.1 i/s - 2.01x slower
|
109
|
+
Lean::Attributes: integer values for integer attributes : 153202.6 i/s - 20.36x slower
|
110
|
+
Lean::Attributes: string values for integer attributes : 141380.5 i/s - 22.07x slower
|
111
|
+
FastAttributes: integer values for integer attributes : 121248.2 i/s - 25.73x slower
|
112
|
+
FastAttributes: string values for integer attributes : 116990.4 i/s - 26.67x slower
|
113
|
+
Virtus: integer values for integer attributes : 35510.1 i/s - 87.86x slower
|
114
|
+
ActiveRecord: without values : 33943.3 i/s - 91.91x slower
|
115
|
+
ActiveAttr: integer values for integer attributes : 23016.1 i/s - 135.55x slower
|
116
|
+
ActiveAttr: string values for integer attributes : 22838.5 i/s - 136.60x slower
|
117
|
+
Virtus: without values : 17894.9 i/s - 174.34x slower
|
118
|
+
Attrio: integer values for integer attributes : 16326.6 i/s - 191.09x slower
|
119
|
+
Attrio: string values for integer attributes : 15921.3 i/s - 195.95x slower
|
120
|
+
ActiveRecord: string values for integer attributes : 13286.4 i/s - 234.81x slower
|
121
|
+
ActiveRecord: integer values for integer attributes : 12595.4 i/s - 247.69x slower
|
122
|
+
Attrio: without values : 11723.0 i/s - 266.13x slower
|
123
|
+
Virtus: string values for integer attributes : 4925.7 i/s - 633.36x slower
|
115
124
|
```
|
116
125
|
|
117
126
|
## Versioning
|
@@ -157,8 +157,7 @@ module Lean
|
|
157
157
|
#
|
158
158
|
# # generated method:
|
159
159
|
# # def pages=(value)
|
160
|
-
# #
|
161
|
-
# # @pages = value
|
160
|
+
# # @pages = coerce_pages(value)
|
162
161
|
# # end
|
163
162
|
# end
|
164
163
|
#
|
@@ -166,8 +165,7 @@ module Lean
|
|
166
165
|
def setter_method
|
167
166
|
<<-EOS
|
168
167
|
def #{name}=(value)
|
169
|
-
|
170
|
-
@#{name} = value
|
168
|
+
@#{name} = #{coercion_method_name}(value)
|
171
169
|
end
|
172
170
|
EOS
|
173
171
|
end
|
@@ -16,6 +16,7 @@ module Lean
|
|
16
16
|
METHOD_BODIES = {
|
17
17
|
Array: 'Array(value)',
|
18
18
|
BigDecimal: 'BigDecimal.new(value, 0)',
|
19
|
+
Boolean: 'value ? true : false',
|
19
20
|
Date: 'Date.parse(value)',
|
20
21
|
DateTime: 'DateTime.parse(value)',
|
21
22
|
Float: 'value.to_f',
|
@@ -23,7 +24,7 @@ module Lean
|
|
23
24
|
String: 'value.to_s',
|
24
25
|
Symbol: 'value.to_s.to_sym',
|
25
26
|
Time: 'Time.parse(value).utc'
|
26
|
-
}
|
27
|
+
}.freeze
|
27
28
|
|
28
29
|
# Fetches or generates the method body for coercing a value to this type
|
29
30
|
#
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lean-attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- R. Elliott Mason
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-03-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|