unfickle 0.1.0 → 0.2.0
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.
- data/README +7 -6
- data/lib/unfickle/unfickle.rb +9 -26
- data/lib/unfickle/version.rb +1 -1
- data/spec/lib/unfickle/unfickle_spec.rb +15 -1
- metadata +2 -2
data/README
CHANGED
@@ -1,11 +1,12 @@
|
|
1
1
|
This allows for better constant management. Use it like so:
|
2
|
-
class MyClass
|
3
|
-
|
4
|
-
|
5
|
-
end
|
2
|
+
class MyClass
|
3
|
+
set_const :read, 1
|
4
|
+
set_const :write, 2
|
5
|
+
end
|
6
6
|
|
7
7
|
You can then reference it directly like so:
|
8
8
|
|
9
|
-
MyClass::READ
|
9
|
+
MyClass::READ
|
10
10
|
|
11
|
-
|
11
|
+
Unfickle gives you the ability to traverse through your constants by calling
|
12
|
+
MyClass.each_constant {|constant,constant_value| dosomething(constant, constant_value) }
|
data/lib/unfickle/unfickle.rb
CHANGED
@@ -6,7 +6,11 @@ module Unfickle
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def const_missing(key)
|
9
|
-
|
9
|
+
if(has_constant?(key))
|
10
|
+
get_const(key)
|
11
|
+
else
|
12
|
+
super(key)
|
13
|
+
end
|
10
14
|
end
|
11
15
|
|
12
16
|
def each_constant
|
@@ -25,32 +29,11 @@ module Unfickle
|
|
25
29
|
@hash[:constants][key]
|
26
30
|
end
|
27
31
|
|
28
|
-
def
|
29
|
-
@hash
|
30
|
-
end
|
31
|
-
|
32
|
-
def each
|
33
|
-
warn '.each method is deprecated in favor of .each_constant'
|
34
|
-
warn "please remove your call to .each from #{caller.first}"
|
35
|
-
end
|
36
|
-
|
37
|
-
def values
|
38
|
-
warn '.values method is deprecated in favor of .constant_values'
|
39
|
-
warn "please remove your call to .values from #{caller.first}"
|
32
|
+
def has_constant?(key)
|
33
|
+
@hash[:constants].keys.include?(key)
|
40
34
|
end
|
41
35
|
|
42
|
-
def
|
43
|
-
|
44
|
-
warn "please remove your call to .keys from #{caller.first}"
|
45
|
-
end
|
46
|
-
|
47
|
-
def clear
|
48
|
-
warn '.clear method is deprecated in favor of .clear_constants'
|
49
|
-
warn "please remove your call to .clear from #{caller.first}"
|
50
|
-
end
|
51
|
-
|
52
|
-
def [](key)
|
53
|
-
warn '[] method is deprecated in favor of .get_const'
|
54
|
-
warn "please remove your call to [] from #{caller.first}"
|
36
|
+
def clear_constants
|
37
|
+
@hash = {constants: {}}
|
55
38
|
end
|
56
39
|
end
|
data/lib/unfickle/version.rb
CHANGED
@@ -23,7 +23,7 @@ describe Unfickle do
|
|
23
23
|
describe '.const_missing' do
|
24
24
|
context 'constant really is missing' do
|
25
25
|
it 'just returns nil' do
|
26
|
-
subject.const_missing(:YEEHAH).
|
26
|
+
expect { subject.const_missing(:YEEHAH)}.to raise_error NameError, 'uninitialized constant TestClass::YEEHAH'
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -68,4 +68,18 @@ describe Unfickle do
|
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
71
|
+
describe '.has_constant?' do
|
72
|
+
context 'it has' do
|
73
|
+
it 'returns true' do
|
74
|
+
subject.has_constant?(:BLAH).should == true
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'it has not' do
|
79
|
+
it 'returns false' do
|
80
|
+
subject.has_constant?(:BLAM).should == false
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
71
85
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: unfickle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.
|
5
|
+
version: 0.2.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Tracey Eubanks
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-10-03 00:00:00 -06:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|