fast_attributes 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/CHANGELOG.md +3 -0
- data/README.md +49 -49
- data/lib/fast_attributes/version.rb +1 -1
- data/lib/fast_attributes.rb +1 -1
- data/spec/fast_attributes_spec.rb +2 -0
- metadata +19 -19
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YTM0MjRmMDVkYmRhNDM4OTVlOTAwNGY5ZTVhNjZkMDQ3NGM4NDEwOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
MTNlOWM2NWI0ZTdiNjhjYWEwZmY4ZmYyY2M1MTFmODNjOTc3YjJhZg==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
Yjc2NjhjMDBlMTlhM2FjYTgzNjFkMDg3YzMxOWVmNjk1NTE2ZWE3MTg3ZTVh
|
10
|
+
ZWNlNzEyZTAxOGFhODRlODI5NjczNTc1ZjM5YzM3ZGQ1NmU1NjQwY2M5MmQz
|
11
|
+
ODc0ODNkMzRjMGIwOWE3ZWIzZmJmZGVjNjFmOGNkYjQzZGE4OTI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MTMyN2E5ODIyMzg4N2Y4NDFjYzNkNWNhZWU2MmY1MjQ4YjJkMWM0ZjZjOWVk
|
14
|
+
OWY3YzVhNjg3ZTkyMDlhNzJjZGMyYmJhMGFmZjA4MGZkZmFhNTZlMTk2NDhi
|
15
|
+
NTRjMWRlNzFhZDQyNzZiYzgwY2E2MjE1MjIwN2Q1MzZkZTU3YTU=
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -11,45 +11,6 @@ There are already a lot of good and flexible gems which solve the similar proble
|
|
11
11
|
This is [performance benchmark](https://github.com/applift/fast_attributes/blob/master/benchmarks/comparison.rb) of `fast_attributes` and other popular gems.
|
12
12
|
|
13
13
|
```
|
14
|
-
Calculating -------------------------------------
|
15
|
-
FastAttributes: without values
|
16
|
-
71131 i/100ms
|
17
|
-
FastAttributes: integer values for integer attributes
|
18
|
-
8410 i/100ms
|
19
|
-
FastAttributes: string values for integer attributes
|
20
|
-
6869 i/100ms
|
21
|
-
Attrio: without values
|
22
|
-
700 i/100ms
|
23
|
-
Attrio: integer values for integer attributes
|
24
|
-
1165 i/100ms
|
25
|
-
Attrio: string values for integer attributes
|
26
|
-
1073 i/100ms
|
27
|
-
Virtus: without values
|
28
|
-
898 i/100ms
|
29
|
-
Virtus: integer values for integer attributes
|
30
|
-
2123 i/100ms
|
31
|
-
Virtus: string values for integer attributes
|
32
|
-
306 i/100ms
|
33
|
-
-------------------------------------------------
|
34
|
-
FastAttributes: without values
|
35
|
-
1528209.4 (±16.2%) i/s - 1564882 in 1.045527s
|
36
|
-
FastAttributes: integer values for integer attributes
|
37
|
-
88794.2 (±16.0%) i/s - 92510 in 1.078912s
|
38
|
-
FastAttributes: string values for integer attributes
|
39
|
-
77673.3 (±4.7%) i/s - 82428 in 1.063921s
|
40
|
-
Attrio: without values
|
41
|
-
7164.3 (±2.6%) i/s - 7700 in 1.075560s
|
42
|
-
Attrio: integer values for integer attributes
|
43
|
-
11932.2 (±2.1%) i/s - 12815 in 1.074474s
|
44
|
-
Attrio: string values for integer attributes
|
45
|
-
11007.2 (±0.9%) i/s - 11803 in 1.072382s
|
46
|
-
Virtus: without values
|
47
|
-
10151.0 (±5.5%) i/s - 10776 in 1.065475s
|
48
|
-
Virtus: integer values for integer attributes
|
49
|
-
21104.7 (±10.4%) i/s - 21230 in 1.019115s
|
50
|
-
Virtus: string values for integer attributes
|
51
|
-
3195.6 (±1.7%) i/s - 3366 in 1.053637s
|
52
|
-
|
53
14
|
Comparison:
|
54
15
|
FastAttributes: without values : 1528209.4 i/s
|
55
16
|
FastAttributes: integer values for integer attributes: 88794.2 i/s - 17.21x slower
|
@@ -136,20 +97,59 @@ book = Book.new(
|
|
136
97
|
finished: '1937-08-20 12:35'
|
137
98
|
)
|
138
99
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
100
|
+
book.attributes
|
101
|
+
{"title"=>"There and Back Again",
|
102
|
+
"name"=>"The Hobbit",
|
103
|
+
"pages"=>200,
|
104
|
+
"authors"=>["Tolkien"],
|
105
|
+
"published"=>#<Date: 1937-09-21 ((2428798j,0s,0n),+0s,2299161j)>,
|
106
|
+
"sold"=>2014-06-25 13:45:00 +0200,
|
107
|
+
"finished"=>
|
108
|
+
#<DateTime: 1937-08-20T12:35:00+00:00 ((2428766j,45300s,0n),+0s,2299161j)>}
|
148
109
|
```
|
110
|
+
## Custom Type
|
111
|
+
It's easy to add a custom attribute type.
|
112
|
+
```ruby
|
113
|
+
FastAttributes.set_type_casting(OpenStruct, 'OpenStruct.new(name: %s)')
|
114
|
+
|
115
|
+
class Book
|
116
|
+
extend FastAttributes
|
117
|
+
attribute :author, OpenStruct
|
118
|
+
end
|
119
|
+
|
120
|
+
book = Book.new
|
121
|
+
book.author = 'Rowling'
|
122
|
+
book.author
|
123
|
+
# => #<OpenStruct name="Rowling">
|
124
|
+
```
|
125
|
+
|
126
|
+
Notice, that second parameter is a string. It's necessary because this code is compiled into ruby method in runtime. Placeholder `%s` represents a value which this method accepts.
|
127
|
+
|
128
|
+
If you need to refer to a placeholder twice, use a temporary variable.
|
129
|
+
```ruby
|
130
|
+
Size = Class.new(Array)
|
131
|
+
FastAttributes.set_type_casting Size, <<-EOS
|
132
|
+
_value = %s
|
133
|
+
Size[_value, _value]
|
134
|
+
EOS
|
135
|
+
|
136
|
+
class Square
|
137
|
+
extend FastAttributes
|
138
|
+
attribute :size, Size
|
139
|
+
end
|
140
|
+
|
141
|
+
square = Square.new
|
142
|
+
square.size = 5
|
143
|
+
square.size
|
144
|
+
# => [5, 5]
|
145
|
+
```
|
146
|
+
|
147
|
+
## Extensions
|
148
|
+
* [fast_attributes-uuid](https://github.com/applift/fast_attributes-uuid) - adds support of `UUID` to `fast_attributes`
|
149
149
|
|
150
150
|
## Contributing
|
151
151
|
|
152
|
-
1. Fork it ( http://github.com
|
152
|
+
1. Fork it ( http://github.com/applift/fast_attributes/fork )
|
153
153
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
154
154
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
155
155
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/fast_attributes.rb
CHANGED
@@ -15,6 +15,8 @@ describe FastAttributes do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
describe '.get_type_casting' do
|
18
|
+
before { FastAttributes.send(:remove_instance_variable, :@type_casting) }
|
19
|
+
|
18
20
|
it 'returns type casting function' do
|
19
21
|
expect(FastAttributes.get_type_casting(String)).to eq('String(%s)')
|
20
22
|
expect(FastAttributes.get_type_casting(Time)).to eq('Time.parse(%s)')
|
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fast_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kostiantyn Stepaniuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ~>
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.5'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ! '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ! '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 3.0.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 3.0.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: coveralls
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 0.7.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 0.7.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: simplecov
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ~>
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 0.8.2
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ~>
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 0.8.2
|
83
83
|
description: Fast attributes with data types
|
@@ -87,10 +87,10 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
-
-
|
91
|
-
-
|
92
|
-
-
|
93
|
-
-
|
90
|
+
- .coveralls.yml
|
91
|
+
- .gitignore
|
92
|
+
- .rspec
|
93
|
+
- .travis.yml
|
94
94
|
- CHANGELOG.md
|
95
95
|
- Gemfile
|
96
96
|
- LICENSE.txt
|
@@ -115,17 +115,17 @@ require_paths:
|
|
115
115
|
- lib
|
116
116
|
required_ruby_version: !ruby/object:Gem::Requirement
|
117
117
|
requirements:
|
118
|
-
- -
|
118
|
+
- - ! '>='
|
119
119
|
- !ruby/object:Gem::Version
|
120
120
|
version: 1.9.2
|
121
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
|
-
- -
|
123
|
+
- - ! '>='
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
127
|
rubyforge_project:
|
128
|
-
rubygems_version: 2.
|
128
|
+
rubygems_version: 2.1.11
|
129
129
|
signing_key:
|
130
130
|
specification_version: 4
|
131
131
|
summary: Fast attributes with data types
|