dot_hash 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
+
1
2
  # DotHash
3
+ [![Build Status](https://travis-ci.org/3den/dot_hash.png?branch=master)](https://travis-ci.org/3den/dot_hash)
2
4
 
3
- A very efficient gem that lets you use hashes as object properties. It is almost as fast as a plain Hash
5
+ A very efficient gem that lets you use hashes as object properties. It is almost as fast as a plain Hash
4
6
  since it's complexity is also linear, `O(n) # where N is the number of nested parents of the given property`.
5
7
 
6
8
  ## Installation
@@ -25,6 +27,8 @@ properties = some_hash.to_properties
25
27
 
26
28
  properties.size.height # returns 100, it is the same as some_hash[:size][:height]
27
29
  properties.color # returns "red", it works with Strings and Symbol keys
30
+ properties[:color] # returns "red", can be used like a hash with string keys
31
+ properties["color"] # returns "red", can be used like a hash with symbol keys
28
32
  ```
29
33
 
30
34
  ## Contributing
data/Rakefile CHANGED
@@ -7,3 +7,5 @@ Rake::TestTask.new do |t|
7
7
  t.test_files = FileList['test/**/*_test.rb']
8
8
  t.verbose = true
9
9
  end
10
+
11
+ task default: :test
@@ -16,6 +16,11 @@ module DotHash
16
16
  has_key?(key) or super(key, *args)
17
17
  end
18
18
 
19
+ def [](key)
20
+ symbolize_key key
21
+ get_value(key)
22
+ end
23
+
19
24
  private
20
25
 
21
26
  def has_key?(key)
@@ -1,3 +1,3 @@
1
1
  module DotHash
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -39,6 +39,20 @@ module DotHash
39
39
  settings.user.info.is_admin.must_equal false
40
40
  end
41
41
  end
42
+
43
+ describe "#[]" do
44
+ before do
45
+ @settings = Properties.new user: { name: "dude" }
46
+ end
47
+
48
+ it "accesses properties like a symbol hash" do
49
+ settings[:user][:name].must_equal "dude"
50
+ end
51
+
52
+ it "accesses properties like a string hash" do
53
+ settings["user"]["name"].must_equal "dude"
54
+ end
55
+ end
42
56
  end
43
57
 
44
58
  describe "#respond_to?" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dot_hash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-11 00:00:00.000000000 Z
12
+ date: 2013-01-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -35,6 +35,7 @@ extensions: []
35
35
  extra_rdoc_files: []
36
36
  files:
37
37
  - .gitignore
38
+ - .travis.yml
38
39
  - Gemfile
39
40
  - LICENSE
40
41
  - README.md
@@ -61,7 +62,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
62
  version: '0'
62
63
  segments:
63
64
  - 0
64
- hash: -2717258685003126638
65
+ hash: -937726017345117898
65
66
  required_rubygems_version: !ruby/object:Gem::Requirement
66
67
  none: false
67
68
  requirements:
@@ -70,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
71
  version: '0'
71
72
  segments:
72
73
  - 0
73
- hash: -2717258685003126638
74
+ hash: -937726017345117898
74
75
  requirements: []
75
76
  rubyforge_project:
76
77
  rubygems_version: 1.8.24