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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/emittance/helpers/constant_helpers.rb +20 -3
- data/lib/emittance/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04b42fbe154e0d5cde79009304ca822446cdab4a
|
4
|
+
data.tar.gz: 7ab0a1d41824b4ac72b0eea7ffb452a1d4023434
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7a2c245677fbedd995c14a097111051f9b5e545d72d3653e5ffa18eb7b931531453c050c8d8f6cfd58b9c1dec2a55637a63b1a21f374e56ac7e86754e3f3d03
|
7
|
+
data.tar.gz: b96f64c4b769476dab89bd3922db4db33b3cb14a5f4c7f6d91b7db3263148e2fcc25cac845c0915452afc696bf34604c6ee65da9575fc196c8350711ae71900b
|
data/Gemfile.lock
CHANGED
@@ -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
|
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
|
-
|
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
|
-
|
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
|
data/lib/emittance/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2017-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|