mostash 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +2 -0
- data/VERSION +1 -1
- data/lib/mostash/mostash.rb +19 -1
- data/spec/mostash_spec.rb +7 -0
- metadata +3 -3
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/lib/mostash/mostash.rb
CHANGED
@@ -5,6 +5,18 @@ class Mostash < OpenStruct
|
|
5
5
|
__init__ init
|
6
6
|
end
|
7
7
|
|
8
|
+
def new_ostruct_member(name)
|
9
|
+
name = name.to_sym
|
10
|
+
unless self.respond_to?(name)
|
11
|
+
super
|
12
|
+
eigenclass.class_eval do
|
13
|
+
remove_method("#{name}") if self.respond_to?(name)
|
14
|
+
define_method("#{name}=") { |x| modifiable[name] = __adjusted_value__ x }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
name
|
18
|
+
end
|
19
|
+
|
8
20
|
def method_missing(method_name, *args, &block)
|
9
21
|
#dbg "#{method_name} was sent #{args.inspect}, and block #{block.inspect}"
|
10
22
|
if @table.respond_to? method_name
|
@@ -17,7 +29,7 @@ class Mostash < OpenStruct
|
|
17
29
|
end
|
18
30
|
|
19
31
|
def []=(key, value)
|
20
|
-
self.send "#{key.to_s}=", value
|
32
|
+
self.send "#{key.to_s}=", __adjusted_value__(value)
|
21
33
|
end
|
22
34
|
|
23
35
|
def [](key)
|
@@ -72,4 +84,10 @@ class Mostash < OpenStruct
|
|
72
84
|
def __is_setter__(method_name)
|
73
85
|
method_name.to_s =~ /=$/
|
74
86
|
end
|
87
|
+
|
88
|
+
def eigenclass
|
89
|
+
class << self
|
90
|
+
self
|
91
|
+
end
|
92
|
+
end
|
75
93
|
end
|
data/spec/mostash_spec.rb
CHANGED
@@ -46,6 +46,13 @@ describe MoStash do
|
|
46
46
|
mo.foo.bar.should == 'baz'
|
47
47
|
end
|
48
48
|
|
49
|
+
it "should automatically make a hash a Mostash if key already exist" do
|
50
|
+
mo = MoStash.new( {:foo => {:bar => 'baz' } } )
|
51
|
+
|
52
|
+
mo.foo = { :bar => 'new_baz' }
|
53
|
+
mo.foo.bar.should == 'new_baz'
|
54
|
+
end
|
55
|
+
|
49
56
|
it "should correctly handle an array of hashes" do
|
50
57
|
mo = MoStash.new
|
51
58
|
mo.foo = [{:hey => 'you'}, {:oh => 'hai'}]
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 5
|
9
|
+
version: 0.0.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Joel Friedman
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-04-
|
17
|
+
date: 2011-04-21 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|