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 CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3741f7522d58f064ba1baa5ed8ab951d79937c34
4
- data.tar.gz: edccd37426c16b16e5b72e2edfbd4530f7fbc9dc
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YTM0MjRmMDVkYmRhNDM4OTVlOTAwNGY5ZTVhNjZkMDQ3NGM4NDEwOQ==
5
+ data.tar.gz: !binary |-
6
+ MTNlOWM2NWI0ZTdiNjhjYWEwZmY4ZmYyY2M1MTFmODNjOTc3YjJhZg==
5
7
  SHA512:
6
- metadata.gz: 78890db35dab5b46ffb2285235ee35bcb34c90795131dcaeca93a2b76d8a411c098aaa5ea3538574529e14a310b76b983dbee76a7e175a89afa1fb91e735856e
7
- data.tar.gz: f68831966a1291293bf34bfa506aaf38667b58084d8400dc65949876319381932db56cd0ca9fae89f7ee4734c69cb5412048cf60835455728080f8ec2d07a0e7
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
@@ -1,3 +1,6 @@
1
+ **0.2.2 (July 2, 2014)**
2
+ * Fix uninitialized `@type_casting` variable
3
+
1
4
  **0.2.1 (June 27, 2014)**
2
5
  * Set minimum ruby version to `1.9.2`
3
6
 
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
- #<Book:0x007f9a0110be20
140
- @authors=["Tolkien"],
141
- @finished=
142
- #<DateTime: 1937-08-20T12:35:00+00:00 ((2428766j,45300s,0n),+0s,2299161j)>,
143
- @name="The Hobbit",
144
- @pages=200,
145
- @published=#<Date: 1937-09-21 ((2428798j,0s,0n),+0s,2299161j)>,
146
- @sold=2014-06-25 13:45:00 +0200,
147
- @title="There and Back Again">
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/<my-github-username>/fast_attributes/fork )
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`)
@@ -1,3 +1,3 @@
1
1
  module FastAttributes
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -15,7 +15,7 @@ module FastAttributes
15
15
  end
16
16
 
17
17
  def get_type_casting(klass)
18
- @type_casting[klass]
18
+ type_casting[klass]
19
19
  end
20
20
 
21
21
  def set_type_casting(klass, casting)
@@ -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.1
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-06-26 00:00:00.000000000 Z
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
- - ".coveralls.yml"
91
- - ".gitignore"
92
- - ".rspec"
93
- - ".travis.yml"
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.2.2
128
+ rubygems_version: 2.1.11
129
129
  signing_key:
130
130
  specification_version: 4
131
131
  summary: Fast attributes with data types