hash_out 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 56b34fb6f1350b47bbc803efbde46242a4babc9c
4
- data.tar.gz: 1edbc3f705f9f1d81999baede78fcba59efbf877
3
+ metadata.gz: 09d4acf8885e3018d89507399d889841f5b67e34
4
+ data.tar.gz: 180a33b85d8abd7cfc25b333d9649bd1c0465cb3
5
5
  SHA512:
6
- metadata.gz: 6a6b821ba4ae67caa5f9c29a9b72a574bbd091801ee361a3f22a5db3caad5de81b3683c506ce3ab66036a4afe5ac5446c8a367da0547595e17fa4b6665a6e14b
7
- data.tar.gz: cfe507b3e4bb5b70afde46f1c1b050ad2c2891f9a574d7031d5ed588e44f1dc2a4a3897197b5a10b2adb0a55a85683be86bd8839ece1d268dd0163f18cd117b2
6
+ metadata.gz: 2c7021e5425cefeef649cf02d1e4e291098ecb6636838f55b416a6eb74a1f4fb464108ef9d5b6d410e6b5e6fe37da6ec15159d042f1ff7d219f50383b3b1731c
7
+ data.tar.gz: cd0abe87615671b457852adaf3a68b7138f4e9526d8d0d3a85f102a86665c60a2d2e92c9c29d25ad21a515386e58e477dd03c60bfa97d28eb2d0018d5ef3d84a
data/README.md CHANGED
@@ -21,7 +21,10 @@ $ gem install hash_out
21
21
  3. If desired, exclude methods from `#hash_out` by adding `exclude_from_hash_out` to them.
22
22
  4. Call `#hash_out` on the instance to return a hash of method names and their values.
23
23
 
24
- **`#hash_out` automatically excludes private methods and methods that require arguments.**
24
+ ##### `#hash_out` automatically excludes the following from the hash it returns:
25
+ 1. private methods
26
+ 2. methods that require arguments
27
+ 3. instance methods in classes that include `HashOut` that wrap or otherwise call `#hash_out`
25
28
 
26
29
  ```ruby
27
30
  require 'hash_out'
data/hash_out.gemspec CHANGED
@@ -5,8 +5,8 @@ require 'hash_out/version'
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'hash_out'
8
- s.description = 'Easily convert public methods to a hash.'
9
- s.summary = "hash_out adds a method to your class' instance and returns hash of public method names and values."
8
+ s.description = 'Easily convert objects to hashes.'
9
+ s.summary = "hash_out adds the #hash_out method to your class' instance. It returns a hash of public method names and values."
10
10
  s.authors = ['Dave Jachimiak']
11
11
  s.email = 'dave.jachimiak@gmail.com'
12
12
  s.homepage = 'http://github.com/davejachimiak/hash_out'
@@ -1,3 +1,3 @@
1
1
  module HashOut
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
data/lib/hash_out.rb CHANGED
@@ -2,8 +2,15 @@ module HashOut
2
2
  require 'set'
3
3
 
4
4
  def hash_out
5
- set_hash_out
6
- delete_exclusions
5
+ caller_method = caller_method_sym caller.first
6
+
7
+ handle_recursion(caller_method) do
8
+ if @called == 1
9
+ set_hash_out
10
+ delete_exclusions
11
+ end
12
+ end
13
+
7
14
  @hash_out
8
15
  end
9
16
 
@@ -16,6 +23,14 @@ module HashOut
16
23
 
17
24
  private
18
25
 
26
+ def handle_recursion hash_out_caller
27
+ @called ||= 0
28
+ @called += 1
29
+ exclusions.add hash_out_caller
30
+ yield
31
+ @called = 0
32
+ end
33
+
19
34
  def set_hash_out
20
35
  @hash_out = Hash[interesting_methods_and_values]
21
36
  end
@@ -83,6 +83,7 @@ describe 'HashOut#hash_out' do
83
83
 
84
84
  def clean materials
85
85
  clean_with materials
86
+ @cleaned = true
86
87
  end
87
88
 
88
89
  def blade edge=:sharp
@@ -96,7 +97,8 @@ describe 'HashOut#hash_out' do
96
97
  yield self
97
98
  end
98
99
 
99
- def clean_with
100
+ def clean_with materials
101
+ #
100
102
  end
101
103
  end
102
104
 
@@ -106,4 +108,23 @@ describe 'HashOut#hash_out' do
106
108
 
107
109
  expect(grinder.hash_out).to_equal hash_out
108
110
  end
111
+
112
+ class SoMeta
113
+ include HashOut
114
+
115
+ def an_method
116
+ :result
117
+ end
118
+
119
+ def attributes
120
+ hash_out
121
+ end
122
+ end
123
+
124
+ it "ignores internal public method that calls #hash_out" do
125
+ so_meta = SoMeta.new
126
+ hash_out = { an_method: :result }
127
+
128
+ expect(so_meta.attributes).to_equal hash_out
129
+ end
109
130
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_out
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Jachimiak
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - ~>
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.1'
41
- description: Easily convert public methods to a hash.
41
+ description: Easily convert objects to hashes.
42
42
  email: dave.jachimiak@gmail.com
43
43
  executables: []
44
44
  extensions: []
@@ -77,7 +77,7 @@ rubyforge_project:
77
77
  rubygems_version: 2.0.2
78
78
  signing_key:
79
79
  specification_version: 4
80
- summary: hash_out adds a method to your class' instance and returns hash of public
81
- method names and values.
80
+ summary: 'hash_out adds the #hash_out method to your class'' instance. It returns
81
+ a hash of public method names and values.'
82
82
  test_files:
83
83
  - spec/lib/integration_spec.rb