emittance 0.0.5 → 0.0.6

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
  SHA1:
3
- metadata.gz: d00db3f1aa0790c17aa370f2828521fdd26b6faa
4
- data.tar.gz: 57d27c48984c030993a0a33b82ff828ca90f4f04
3
+ metadata.gz: 04b42fbe154e0d5cde79009304ca822446cdab4a
4
+ data.tar.gz: 7ab0a1d41824b4ac72b0eea7ffb452a1d4023434
5
5
  SHA512:
6
- metadata.gz: ba6dc33ab2075c945f6d49790926297f19025c1a70493f771fd12b9f103a2d40f7c1804e35bf6d97c8b85bb7e9efcdd85c21052f1d40997f544fba7cdf4bdada
7
- data.tar.gz: 1b9dbb91cb57c985f8b55ec7c3497775637e3a9365d26cb3795de2857305d91bc73988eb13c02696698e543b31b834bc771cf418e8f81fa73632c0f4ecbe2284
6
+ metadata.gz: f7a2c245677fbedd995c14a097111051f9b5e545d72d3653e5ffa18eb7b931531453c050c8d8f6cfd58b9c1dec2a55637a63b1a21f374e56ac7e86754e3f3d03
7
+ data.tar.gz: b96f64c4b769476dab89bd3922db4db33b3cb14a5f4c7f6d91b7db3263148e2fcc25cac845c0915452afc696bf34604c6ee65da9575fc196c8350711ae71900b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- emittance (0.0.4)
4
+ emittance (0.0.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -6,7 +6,7 @@ module Emittance
6
6
  # Some helpers for fetching, setting, and manipulating constants.
7
7
  #
8
8
  module ConstantHelpers
9
- # Since +Object.const_set+ does not support namespaced constant names, use this to set the constant to the
9
+ # Since +Object#const_set+ does not support namespaced constant names, use this to set the constant to the
10
10
  # correct namespace.
11
11
  #
12
12
  # Example:
@@ -21,13 +21,30 @@ module Emittance
21
21
  #
22
22
  # @param const_name [String] a valid namespaced constant name
23
23
  # @param obj the value you wish to set that constant to
24
- def set_namespaced_constant_by_name(const_name, obj)
24
+ # @return the object to which you assigned the namespaced constant
25
+ def set_namespaced_constant_by_name(const_name, obj, namespace_filler_klass = Module)
25
26
  names = const_name.split('::')
26
27
  names.shift if names.size > 1 && names.first.empty?
27
28
 
28
- namespace = names.size == 1 ? Object : Object.const_get(names[0...-1].join('::'))
29
+ parent_names = names[0...-1]
30
+ parent_namespace_name = names[0...-1].join('::')
31
+
32
+ fill_in_namespace(parent_names, parent_namespace_name, namespace_filler_klass)
33
+
34
+ namespace = parent_names.empty? ? Object : Object.const_get(parent_namespace_name)
29
35
  namespace.const_set names.last, obj
30
36
  end
37
+
38
+ private
39
+
40
+ def fill_in_namespace(parent_names, parent_namespace_name, namespace_filler_klass)
41
+ set_namespaced_constant_by_name parent_namespace_name, namespace_filler_klass.new, namespace_filler_klass \
42
+ unless parent_names.empty? || Object.const_defined?(parent_namespace_name)
43
+ end
31
44
  end
32
45
  end
33
46
  end
47
+
48
+ # class Foo
49
+ # extend Emittance::Helpers::ConstantHelpers
50
+ # end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Emittance
4
- VERSION = '0.0.5'
4
+ VERSION = '0.0.6'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: emittance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Guillen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-12-14 00:00:00.000000000 Z
11
+ date: 2017-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler