hashr 0.0.9 → 0.0.10

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/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hashr (0.0.8)
4
+ hashr (0.0.9)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -43,10 +43,31 @@ You can make Hashr raise an `IndexError` though like this:
43
43
  config.foo? # => false
44
44
  config.foo # => raises an IndexError "Key :foo is not defined."
45
45
 
46
- Derive a custom class to define defaults like this:
46
+ You can also anonymously overwrite core Hash methods like this:
47
+
48
+ config = Hashr.new(:count => 3) do
49
+ def count
50
+ self[:count]
51
+ end
52
+ end
53
+ config.count # => 3
54
+
55
+ And you can anonymously provide defaults like this:
56
+
57
+ data = { :foo => 'foo' }
58
+ defaults = { :bar => 'bar' }
59
+ config = Hashr.new(data, defaults)
60
+ config.foo # => 'foo'
61
+ config.bar # => 'bar'
62
+
63
+ But you can obvioulsy also derive a custom class to define defaults and overwrite core Hash methods like this:
47
64
 
48
65
  class Config < Hashr
49
66
  define :foo => { :bar => 'bar' }
67
+
68
+ def count
69
+ self[:count]
70
+ end
50
71
  end
51
72
 
52
73
  config = Config.new
@@ -57,7 +78,7 @@ Include modules to nested hashes like this:
57
78
  class Config < Hashr
58
79
  module Boxes
59
80
  def count
60
- self['count'] # overwrites a Hash method to return the Hash's content here
81
+ self[:count] # overwrites a Hash method to return the Hash's content here
61
82
  end
62
83
 
63
84
  def names
data/lib/hashr.rb CHANGED
@@ -17,8 +17,9 @@ class Hashr < Hash
17
17
  end
18
18
  end
19
19
 
20
- def initialize(data = {}, definition = self.class.definition)
20
+ def initialize(data = {}, definition = self.class.definition, &block)
21
21
  replace(deep_hashrize(definition.deep_merge((data || {}).deep_symbolize_keys)))
22
+ (class << self; self; end).class_eval(&block) if block_given?
22
23
  end
23
24
 
24
25
  def []=(key, value)
data/lib/hashr/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class Hashr < Hash
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
data/test/hashr_test.rb CHANGED
@@ -129,5 +129,14 @@ class HashrTest < Test::Unit::TestCase
129
129
  end
130
130
  assert_equal 'helper', klass.new.foo.helper
131
131
  end
132
+
133
+ test 'anonymously overwriting core Hash methods' do
134
+ hashr = Hashr.new(:count => 5) do
135
+ def count
136
+ self[:count]
137
+ end
138
+ end
139
+ assert_equal 5, hashr.count
140
+ end
132
141
  end
133
142
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-07-25 00:00:00.000000000 +02:00
13
- default_executable:
12
+ date: 2011-07-31 00:00:00.000000000Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: rake
17
- requirement: &2165518780 !ruby/object:Gem::Requirement
16
+ requirement: &70212682650560 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,10 +21,10 @@ dependencies:
22
21
  version: '0'
23
22
  type: :development
24
23
  prerelease: false
25
- version_requirements: *2165518780
24
+ version_requirements: *70212682650560
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: test_declarative
28
- requirement: &2165518260 !ruby/object:Gem::Requirement
27
+ requirement: &70212682649260 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ! '>='
@@ -33,7 +32,7 @@ dependencies:
33
32
  version: 0.0.2
34
33
  type: :development
35
34
  prerelease: false
36
- version_requirements: *2165518260
35
+ version_requirements: *70212682649260
37
36
  description: Simple Hash extension to make working with nested hashes (e.g. for configuration)
38
37
  easier and less error-prone.
39
38
  email: svenfuchs@artweb-design.de
@@ -52,7 +51,6 @@ files:
52
51
  - MIT-LICENSE
53
52
  - Rakefile
54
53
  - README.md
55
- has_rdoc: true
56
54
  homepage: http://github.com/svenfuchs/hashr
57
55
  licenses: []
58
56
  post_install_message:
@@ -73,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
73
71
  version: '0'
74
72
  requirements: []
75
73
  rubyforge_project: ! '[none]'
76
- rubygems_version: 1.6.2
74
+ rubygems_version: 1.8.6
77
75
  signing_key:
78
76
  specification_version: 3
79
77
  summary: Simple Hash extension to make working with nested hashes (e.g. for configuration)