mostash 0.0.4 → 0.0.5

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/Rakefile CHANGED
@@ -21,3 +21,5 @@ desc "run all specs"
21
21
  Spec::Rake::SpecTask.new( "spec" ) do |t|
22
22
  t.spec_files = FileList["spec/**/*_spec.rb"]
23
23
  end
24
+
25
+ task :default => :spec
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -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
@@ -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
- - 4
9
- version: 0.0.4
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-18 00:00:00 -05:00
17
+ date: 2011-04-21 00:00:00 -05:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency