hashie 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hashie}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Michael Bleigh"]
12
- s.date = %q{2009-11-13}
12
+ s.date = %q{2009-11-16}
13
13
  s.description = %q{Hashie is a small collection of tools that make hashes more powerful. Currently includes Mash (Mocking Hash) and Dash (Discrete Hash).}
14
14
  s.email = %q{michael@intridea.com}
15
15
  s.extra_rdoc_files = [
@@ -71,18 +71,24 @@ module Hashie
71
71
 
72
72
  # Retrieve a value from the Dash (will return the
73
73
  # property's default value if it hasn't been set).
74
- def [](property_name)
75
- super(property_name.to_sym)
74
+ def [](property)
75
+ super(property.to_sym) if property_exists? property
76
76
  end
77
77
 
78
78
  # Set a value on the Dash in a Hash-like way. Only works
79
79
  # on pre-existing properties.
80
80
  def []=(property, value)
81
- if self.class.property?(property.to_sym)
82
- super
83
- else
84
- raise NoMethodError, "The property '#{property}' is not defined for this Dash."
85
- end
81
+ super if property_exists? property
86
82
  end
83
+
84
+ private
85
+ # Raises an NoMethodError if the property doesn't exist
86
+ #
87
+ def property_exists?(property)
88
+ unless self.class.property?(property.to_sym)
89
+ raise NoMethodError, "The property '#{property}' is not defined for this Dash."
90
+ end
91
+ true
92
+ end
87
93
  end
88
94
  end
@@ -39,7 +39,7 @@ module Hashie
39
39
 
40
40
  def hashie_inspect
41
41
  ret = "<##{self.class.to_s}"
42
- keys.sort.each do |key|
42
+ stringify_keys.keys.sort.each do |key|
43
43
  ret << " #{key}=#{self[key].inspect}"
44
44
  end
45
45
  ret << ">"
@@ -11,6 +11,12 @@ describe Hashie::Dash do
11
11
  (Hashie::Dash < Hash).should be_true
12
12
  end
13
13
 
14
+ it '#inspect should be ok!' do
15
+ dash = DashTest.new
16
+ dash.email = "abd@abc.com"
17
+ dash.inspect.should == "<#DashTest count=0 email=\"abd@abc.com\" first_name=nil>"
18
+ end
19
+
14
20
  describe ' creating properties' do
15
21
  it 'should add the property to the list' do
16
22
  DashTest.property :not_an_att
@@ -26,6 +32,12 @@ describe Hashie::Dash do
26
32
  end
27
33
  end
28
34
 
35
+ describe 'reading properties' do
36
+ it 'should raise an error when reading a non-existent property' do
37
+ lambda{@dash['abc']}.should raise_error(NoMethodError)
38
+ end
39
+ end
40
+
29
41
  describe ' writing to properties' do
30
42
  before do
31
43
  @dash = DashTest.new
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashie
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-13 00:00:00 -05:00
12
+ date: 2009-11-16 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency