sleeping_king_studios-tools 0.7.0 → 0.7.1

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: 2710128170b585a52948f4ea6c5fd45823fb5a04
4
- data.tar.gz: aec1358fbbc2bb7cb24d1f421f0bb267cd184502
3
+ metadata.gz: 694e8a5ab01a8bbe5c689954d0c00a70045f13cd
4
+ data.tar.gz: e6421ef4c5f581125590ef984c3b0f1281e45a36
5
5
  SHA512:
6
- metadata.gz: e2fbf02cd573fa10459ade0902fb686cb837b327fa20c6d76619873b26d948275b09f9e2c0f28f79ef6267c773c8beb9297e1090bd7896213741236d14d67f54
7
- data.tar.gz: fa2db45be8fbb184ec7e2ca82b35626b266d8ccf791a08cec960e09bada31eaab5c2669c9d17576436e5e1012151aa3c12e321f27d4a5f34f21884a02ccece4d
6
+ metadata.gz: 113e19e8b5e5f37906c3bd6dfa05e3bd7f400f3159d13b335128d40acaae22f6426bcd414bed58891661a21914962b98bcc5c9c4cf14d6819f5e4cd62e1c46d7
7
+ data.tar.gz: 58b378e8326afd2ed60ad1487301c9e4e117bc6709c61543ff50a36b4805e432cd90f948eed78c0a710d11476115d4c31d51d4365ec5a9affc135ab2bbe70b81
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Current Release
4
4
 
5
+ ### 0.7.1
6
+
7
+ - Implement CoreTools#empty_binding.
8
+ - Implement HashTools#generate_binding.
9
+
5
10
  ### 0.7.0
6
11
 
7
12
  #### Tools
data/README.md CHANGED
@@ -187,6 +187,14 @@ Prints a deprecation warning.
187
187
  ObjectTools#old_method was deprecated in version 0.1.0.
188
188
  called from /path/to/file.rb:4: in something_or_other
189
189
 
190
+ #### `#empty_binding`
191
+
192
+ Generates an empty Binding object. Note that this binding object still has
193
+ access to Object methods and constants - it is **not** eval-safe.
194
+
195
+ CoreTools.empty_binding
196
+ #=> Binding
197
+
190
198
  #### `#require_each`
191
199
 
192
200
  Takes a file pattern or a list of file names and requires each file.
@@ -262,6 +270,22 @@ Freezes the hash and performs a deep freeze on each hash key and value.
262
270
  hsh[:one].frozen?
263
271
  #=> true
264
272
 
273
+ #### `#generate_binding`
274
+
275
+ Generates a Binding object, with the hash converted to local variables in the
276
+ binding.
277
+
278
+ hsh = { :one => 'one', :two => 'two', :three => 'three' }
279
+ binding = HashTools.generate_binding(hsh)
280
+ #=> Binding
281
+
282
+ binding.local_variable_defined?(:one)
283
+ #=> true
284
+ binding.local_variable_get(:one)
285
+ #=> 'one'
286
+ binding.eval('one')
287
+ #=> 'one'
288
+
265
289
  #### `#hash?`
266
290
 
267
291
  Returns true if the object is or appears to be a Hash.
@@ -33,6 +33,19 @@ module SleepingKingStudios::Tools
33
33
  Kernel.warn str
34
34
  end # method deprecate
35
35
 
36
+ # Generates an empty Binding object with a BasicObject as the receiver.
37
+ #
38
+ # @return [Binding] The empty binding object.
39
+ def empty_binding
40
+ context = Object.new
41
+
42
+ def context.binding
43
+ Kernel.instance_method(:binding).bind(self).call
44
+ end # singleton method binding
45
+
46
+ context.binding
47
+ end # method empty_binding
48
+
36
49
  # Expands each file pattern and requires each file.
37
50
  #
38
51
  # @param file_patterns [Array] The files to require.
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'sleeping_king_studios/tools'
4
4
  require 'sleeping_king_studios/tools/array_tools'
5
+ require 'sleeping_king_studios/tools/core_tools'
5
6
  require 'sleeping_king_studios/tools/object_tools'
6
7
 
7
8
  module SleepingKingStudios::Tools
@@ -72,6 +73,16 @@ module SleepingKingStudios::Tools
72
73
  end # each
73
74
  end # method deep_freeze
74
75
 
76
+ def generate_binding hsh
77
+ require_hash! hsh
78
+
79
+ CoreTools.empty_binding.tap do |binding|
80
+ hsh.each do |key, value|
81
+ binding.local_variable_set key, value
82
+ end # each
83
+ end # tap
84
+ end # method generate_binding
85
+
75
86
  # Returns true if the object is or appears to be a Hash.
76
87
  #
77
88
  # @param hsh [Object] The object to test.
@@ -14,7 +14,7 @@ module SleepingKingStudios
14
14
 
15
15
  MAJOR = 0
16
16
  MINOR = 7
17
- PATCH = 0
17
+ PATCH = 1
18
18
  PRERELEASE = nil
19
19
  BUILD = nil
20
20
  end # module
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sleeping_king_studios-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob "Merlin" Smith
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-19 00:00:00.000000000 Z
11
+ date: 2017-05-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake