hashr 0.0.5 → 0.0.6

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.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hashr (0.0.4)
4
+ hashr (0.0.5)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://secure.travis-ci.org/svenfuchs/hashr.png)](http://travis-ci.org/svenfuchs/hashr)
2
+
1
3
  # Hashr
2
4
 
3
5
  Hashr is a very simple and tiny class derived from Ruby's core Hash class which makes using nested hashes for configuration (and other purposes) easier and less repetive and error prone.
@@ -5,7 +7,7 @@ Hashr is a very simple and tiny class derived from Ruby's core Hash class which
5
7
  It supports the following features:
6
8
 
7
9
  * method read and write access
8
- * automatic predicate (boolean, i.e. ?) methods
10
+ * automatic predicate (boolean, i.e. `?`) methods
9
11
  * easy defaults
10
12
  * easy inclusion of modules into nested hashes
11
13
  * automatic symbolized keys
@@ -22,19 +24,19 @@ Directly use Hashr instances like this:
22
24
  config.foo.bar? # => true
23
25
  config.foo.bar # => 'bar'
24
26
 
25
- config.foo.bar = 'BAR'
26
- config.foo.bar # => 'BAR'
27
+ config.foo.bar = 'bar!'
28
+ config.foo.bar # => 'bar!'
27
29
 
28
30
  config.foo.baz = 'baz'
29
31
  config.foo.baz # => 'baz'
30
32
 
31
- Be aware that by default missing keys won't raise a method missing error but instead behave like Hash access:
33
+ Be aware that by default missing keys won't raise an exception but instead behave like Hash access:
32
34
 
33
35
  config = Hashr.new
34
36
  config.foo? # => false
35
37
  config.foo # => nil
36
38
 
37
- You can make Hashr to raise an IndexError though like this:
39
+ You can make Hashr to raise an `IndexError` though like this:
38
40
 
39
41
  Hashr.raise_missing_keys = true
40
42
  config = Hashr.new
@@ -98,3 +100,14 @@ You can run the tests as follows:
98
100
 
99
101
  # using just ruby
100
102
  ruby -rubygems -Ilib:test test/hashr_test.rb
103
+
104
+ ## Other libraries
105
+
106
+ You also might want to check out OpenStruct and Hashie.
107
+
108
+ * [OpenStruct](http://ruby-doc.org/stdlib/libdoc/ostruct/rdoc/classes/OpenStruct.html) does less but comes as a Ruby standard library.
109
+ * [Hashie](https://github.com/intridea/hashie) has a bunch of support classes (like `Mash`, `Dash`, `Trash`) which all support different features that you might need.
110
+
111
+ ## License
112
+
113
+ [MIT License](https://github.com/svenfuchs/hashr/blob/master/MIT-LICENSE)
@@ -35,17 +35,13 @@ class Hashr < Hash
35
35
  when '='
36
36
  self[name.to_s[0..-2].to_sym] = args.first
37
37
  else
38
- read(name)
38
+ raise(IndexError.new("Key #{name.inspect} is not defined.")) if !key?(name) && self.class.raise_missing_keys
39
+ self[name]
39
40
  end
40
41
  end
41
42
 
42
43
  protected
43
44
 
44
- def read(key)
45
- raise(IndexError.new("Key #{key.inspect} is not defined.")) if !key?(key) && self.class.raise_missing_keys
46
- self[key]
47
- end
48
-
49
45
  def include_modules(modules)
50
46
  Array(modules).each { |mod| meta_class.send(:include, mod) } if modules
51
47
  end
@@ -1,3 +1,3 @@
1
1
  class Hashr < Hash
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sven Fuchs
@@ -48,7 +48,7 @@ dependencies:
48
48
  version: 0.0.2
49
49
  type: :development
50
50
  version_requirements: *id002
51
- description: Simple Hash extension targetted at configuration.
51
+ description: Simple Hash extension to make working with nested hashes (e.g. for configuration) easier and less error-prone.
52
52
  email: svenfuchs@artweb-design.de
53
53
  executables: []
54
54
 
@@ -100,6 +100,6 @@ rubyforge_project: "[none]"
100
100
  rubygems_version: 1.6.2
101
101
  signing_key:
102
102
  specification_version: 3
103
- summary: Simple Hash extension targetted at configuration
103
+ summary: Simple Hash extension to make working with nested hashes (e.g. for configuration) easier and less error-prone
104
104
  test_files: []
105
105