output_attributes 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: 5853821c644c05df3134cba84d1fb800540eafe828ee11cbb6e17f4bb1d80fcd
4
- data.tar.gz: 5b9acc26991eb9f52a1e93633badb9761564b9393cfa1a5a713f453f15c45e30
3
+ metadata.gz: 2ca0d8769aa2e316843cad1728211dbc7d0fb35165927b04a7c6d99d00cd2046
4
+ data.tar.gz: f8ee1ee5cd330c5deca707dcf34456a3d771f2a2456428c0e17cd3e96edff40f
5
5
  SHA512:
6
- metadata.gz: 0cd70015e649d210c073ee061b6691823642c6ac5dcb7e03ed84ca5089759f56d9b67ac690223d5e48b94089ffcb5fb9f81daffa8d0c920e25606c0d2105bd2e
7
- data.tar.gz: 30cc7fd8b45ea679001cf3e32ad977222ce0643109643b0c021ef4a19b1f5ed577bfbe3a01d84f49d34d5ae0ef66a9e6c7a7a2808b11a1b88a6fd12779b9756a
6
+ metadata.gz: d8c06caab668a52cd446b8e045f9add37e3d141bb630745ea7aacf59f9d0fc31ef62aefa0cd6c334d13d3c8ab7da142cdaee9b0d994c817f988811541a089ffa
7
+ data.tar.gz: 4601bc74afad5daf820795bd65438113a9d92722eb398ac26546916294317aaed3eab7407c4d8c364343b0d3ab3b26bed8ae1891e9b8e04dcd3b85232cce97a3
@@ -12,7 +12,7 @@ GEM
12
12
  pry (0.12.2)
13
13
  coderay (~> 1.1.0)
14
14
  method_source (~> 0.9.0)
15
- rake (10.5.0)
15
+ rake (13.0.1)
16
16
 
17
17
  PLATFORMS
18
18
  ruby
@@ -22,7 +22,7 @@ DEPENDENCIES
22
22
  minitest (~> 5.0)
23
23
  output_attributes!
24
24
  pry
25
- rake (~> 10.0)
25
+ rake (~> 13.0)
26
26
 
27
27
  BUNDLED WITH
28
28
  2.0.2
data/README.md CHANGED
@@ -1,10 +1,32 @@
1
1
  # OutputAttributes
2
2
 
3
- This gem provides a class macro that adds `output` helpers when defining your class. I find it jarring to keep `#to_hash` up to date on classes that have many data attributes, and a few helper methods. I often wish to just mark a method as "This method describes my data and should be part of `#to_hash`".
3
+ This gem helps you serialize your data object by providing an `output` class macro for defining your class. You can call `#output_attributes` to get a hash representing your object from the output helpers.
4
+
5
+ I find it jarring to keep `#to_hash` up to date on classes that have many data attributes, and a few helper methods. I often wish to just mark a method as "This method describes my data and should be part of `#to_hash`".
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'output_attributes'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install output_attributes
22
+
23
+ ## Usage
4
24
 
5
25
  Behold:
6
26
 
7
27
  ```ruby
28
+ require 'output_attributes'
29
+
8
30
  class Item
9
31
  include OutputAttributes
10
32
 
@@ -157,9 +179,16 @@ class Page < SimpleDelegator
157
179
  labels(:size)
158
180
  end
159
181
 
160
- output :extracted_at, from: ->(_){ Time.now }
182
+ output def description
183
+ "#{name} #{size} #{color}"
184
+ end
161
185
 
162
- alias to_hash output_attributes
186
+ def to_hash
187
+ output_attributes.merge(
188
+ extracted_at: Time.now,
189
+ object: self.class
190
+ )
191
+ end
163
192
 
164
193
  private
165
194
  def labels(key)
@@ -171,7 +200,9 @@ end
171
200
  Page.new(nokogirilike).to_hash
172
201
  ```
173
202
 
174
- Usually when I'm writing a method for a page object, I'm thinking "Is this part of my data output, or is this just a helper method?". I've often forgotten to update `#to_hash` when it lives further away from the method itself. I've also tried other styles that involved packaging my data methods into a module, and then doing something like `Attributes.public_instance_methods.reduce({})...` but I wanted to give this style a spin.
203
+ Usually when I'm writing a method for a page object, I'm already thinking "Is this part of my data output, or is this just a helper method?". I've often forgotten to update `#to_hash` when it lives far away from the method itself.
204
+
205
+ I've also tried other styles that involved packaging my data methods into a module, and then doing something like `Attributes.public_instance_methods.reduce({})...` but I wanted to give this style a spin. For now, I like it well enough.
175
206
 
176
207
 
177
208
  # Fun Fact
@@ -184,24 +215,7 @@ memoize def my_method
184
215
  end
185
216
  ```
186
217
 
187
- I think this is pretty cool, and is exactly the type of syntax I wanted when creating data objects.
188
-
189
-
190
- ## Installation
191
-
192
- Add this line to your application's Gemfile:
193
-
194
- ```ruby
195
- gem 'output_attributes'
196
- ```
197
-
198
- And then execute:
199
-
200
- $ bundle
201
-
202
- Or install it yourself as:
203
-
204
- $ gem install output_attributes
218
+ I think this is pretty cool. It's exactly the type of syntax I usually wished I had when creating data objects.
205
219
 
206
220
  ## Development
207
221
 
@@ -1,3 +1,3 @@
1
1
  module OutputAttributes
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  spec.add_development_dependency "bundler", "~> 2.0"
34
- spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rake", "~> 13.0"
35
35
  spec.add_development_dependency "minitest", "~> 5.0"
36
36
  spec.add_development_dependency "pry"
37
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: output_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Tilberg
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-26 00:00:00.000000000 Z
11
+ date: 2020-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.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
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
107
  - !ruby/object:Gem::Version
108
108
  version: '0'
109
109
  requirements: []
110
- rubygems_version: 3.0.4
110
+ rubygems_version: 3.0.3
111
111
  signing_key:
112
112
  specification_version: 4
113
113
  summary: Easily declare a hash to represent your object using `output` attributes