configulations 0.1.2 → 0.1.3

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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.1.3
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{configulations}
8
- s.version = "0.1.2"
8
+ s.version = "0.1.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Leon Gersing"]
data/lib/magic_hash.rb CHANGED
@@ -10,7 +10,7 @@ module MagicHash
10
10
  tmp={}
11
11
  tmp.extend(MagicHash)
12
12
  self.each_pair do |key, value|
13
- new_key = key.gsub(/\s|-/,"_").strip.to_sym
13
+ new_key = key.is_a?(Symbol) ? key : key.gsub(/\s|-/,"_").strip.to_sym
14
14
  if(value.is_a? Hash)
15
15
  value.extend(MagicHash) unless value.respond_to? :objectify
16
16
  tmp[new_key] = value.make_keys_valid_message_aliases
@@ -55,12 +55,13 @@ module MagicHash
55
55
  end
56
56
 
57
57
  def method_missing(method_name, *args, &blk)
58
- message = method_name.to_s.strip.downcase.gsub(/-/,"_").to_sym
58
+ message = method_name.to_s.strip.downcase.gsub(/-/,"_")
59
59
  if message =~ /=/
60
- self[message]= args.flatten.first
60
+ self[message.gsub(/=/,"").to_sym]= args.flatten.first
61
+ self.objectify
61
62
  return
62
63
  else
63
- result = self[message]
64
+ result = self[message.to_sym]
64
65
  return result if result
65
66
  end
66
67
 
@@ -15,5 +15,21 @@ describe(MagicHash) do
15
15
  options.is_a?(Hash).should == true
16
16
  end
17
17
 
18
+ it "lets you add keys that don't exist." do
19
+ options = {:foo => "bar"}
20
+ options.extend(MagicHash)
21
+ options.foo.should == "bar"
22
+ options.baz = "leon"
23
+ options.baz.should == "leon"
24
+ end
25
+
26
+ it "makes new Hash assignments, magic." do
27
+ options = {:foo => "bar"}
28
+ options.extend(MagicHash)
29
+ options.foo.should == "bar"
30
+ options.org_chart = {"employees" => [{"name"=>"Leon"},{"name"=>"Jerry"}]}
31
+ options.org_chart.employees.first.name.should == "Leon"
32
+ end
33
+
18
34
  end
19
35
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: configulations
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.1.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Leon Gersing
@@ -99,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
- hash: 3543635930889180181
102
+ hash: 4050517127552312950
103
103
  segments:
104
104
  - 0
105
105
  version: "0"