hashr 0.0.22 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 363367721272caa3b82603de2d83346a509a4a5f
4
+ data.tar.gz: 5a3b97d5394ae7c46e6f926e8e72cd5f37b3856b
5
+ SHA512:
6
+ metadata.gz: 8a89f6e9a054164233456eabe2a4e14ce9ef42f4d6c80a2ebb3c42e185412ab39ba56dda24079293593238c089762444583cdfaaaaa955c5a33442abc7991eda
7
+ data.tar.gz: 609ed7d5b46af9cf45c52783efd0f97420280eb42dfb2b9c204805e9dd4a5036163244c1aebab428065e5a5d12b2f711491d45b0af7ae9d4dc8621933239b7fd
data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
  gemspec
@@ -1,11 +1,12 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hashr (0.0.20)
4
+ hashr (0.0.22)
5
5
 
6
6
  GEM
7
- remote: http://rubygems.org/
7
+ remote: https://rubygems.org/
8
8
  specs:
9
+ minitest (5.3.4)
9
10
  rake (0.9.2)
10
11
  test_declarative (0.0.5)
11
12
 
@@ -15,5 +16,6 @@ PLATFORMS
15
16
 
16
17
  DEPENDENCIES
17
18
  hashr!
19
+ minitest (>= 5.0.0)
18
20
  rake
19
21
  test_declarative (>= 0.0.2)
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+
3
+ $:.unshift File.expand_path('../lib', __FILE__)
4
+ require 'hashr/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "hashr"
8
+ s.version = Hashr::VERSION
9
+ s.authors = ["Sven Fuchs"]
10
+ s.email = "svenfuchs@artweb-design.de"
11
+ s.homepage = "http://github.com/svenfuchs/hashr"
12
+ s.summary = "Simple Hash extension to make working with nested hashes (e.g. for configuration) easier and less error-prone"
13
+ s.description = "Simple Hash extension to make working with nested hashes (e.g. for configuration) easier and less error-prone."
14
+
15
+ s.files = Dir['{lib/**/*,test/**/*,[A-Z]*}']
16
+ s.platform = Gem::Platform::RUBY
17
+ s.require_path = 'lib'
18
+ s.rubyforge_project = '[none]'
19
+
20
+ s.add_development_dependency 'rake'
21
+ s.add_development_dependency 'test_declarative', '>=0.0.2'
22
+ s.add_development_dependency 'minitest', '>=5.0.0'
23
+ end
@@ -38,6 +38,7 @@ class Hashr < Hash
38
38
  undef :id if method_defined?(:id) # undefine deprecated method #id on 1.8.x
39
39
 
40
40
  def initialize(data = {}, definition = self.class.definition, &block)
41
+ raise(ArgumentError.new("Invalid input #{data.inspect}")) unless data.nil? || data.is_a?(Hash)
41
42
  replace((deep_hashrize(definition.deep_merge((data || {}).deep_symbolize_keys))))
42
43
  deep_defaultize(self)
43
44
  (class << self; self; end).class_eval(&block) if block_given?
@@ -57,8 +58,12 @@ class Hashr < Hash
57
58
  tokens.size == 1 ? self[path] = value : self[tokens.shift, Hashr.new].set(tokens.join('.'), value, stack)
58
59
  end
59
60
 
60
- def respond_to?(*args)
61
- true
61
+ def respond_to?(method)
62
+ if self.class.raise_missing_keys
63
+ key?(method)
64
+ else
65
+ true
66
+ end
62
67
  end
63
68
 
64
69
  def method_missing(name, *args, &block)
@@ -1,3 +1,3 @@
1
1
  class Hashr < Hash
2
- VERSION = '0.0.22'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class CoreExtTest < Test::Unit::TestCase
3
+ class CoreExtTest < Minitest::Test
4
4
  test 'Hash#deep_symbolize_keys walks arrays, too' do
5
5
  hash = { 'foo' => [{ 'bar' => 'bar', 'baz' => { 'buz' => 'buz' } }] }
6
6
  expected = { :foo => [{ :bar => 'bar', :baz => { :buz => 'buz' } }] }
@@ -1,12 +1,16 @@
1
1
  require 'test_helper'
2
2
 
3
- class HashrTest < Test::Unit::TestCase
3
+ class HashrTest < Minitest::Test
4
4
  def teardown
5
5
  Hashr.raise_missing_keys = false
6
6
  end
7
7
 
8
8
  test 'initialize takes nil' do
9
- assert_nothing_raised { Hashr.new(nil) }
9
+ Hashr.new(nil)
10
+ end
11
+
12
+ test 'initialize raises an ArgumentError when given a string' do
13
+ assert_raises(ArgumentError) { Hashr.new("foo") }
10
14
  end
11
15
 
12
16
  test 'method access on an existing key returns the value' do
@@ -89,6 +93,25 @@ class HashrTest < Test::Unit::TestCase
89
93
  assert_equal 'foo', hashr.foo
90
94
  end
91
95
 
96
+ test 'respond_to? returns true if raise_missing_keys is off' do
97
+ Hashr.raise_missing_keys = false
98
+ hashr = Hashr.new
99
+ assert hashr.respond_to?(:foo)
100
+ end
101
+
102
+ test 'respond_to? returns false for missing keys if raise_missing_keys is on' do
103
+ Hashr.raise_missing_keys = true
104
+ hashr = Hashr.new
105
+ assert_equal false, hashr.respond_to?(:foo)
106
+ end
107
+
108
+ test 'respond_to? returns true for extant keys if raise_missing_keys is on' do
109
+ Hashr.raise_missing_keys = true
110
+ hashr = Hashr.new
111
+ hashr[:foo] = 'bar'
112
+ assert hashr.respond_to?(:foo)
113
+ end
114
+
92
115
  test 'defining defaults' do
93
116
  klass = Class.new(Hashr) do
94
117
  define :foo => 'foo', :bar => { :baz => 'baz' }
@@ -205,4 +228,3 @@ class HashrTest < Test::Unit::TestCase
205
228
  assert_equal 'baz', hashr.foo.baz
206
229
  end
207
230
  end
208
-
@@ -1,4 +1,4 @@
1
1
  require 'bundler/setup'
2
- require 'test/unit'
2
+ require 'minitest/autorun'
3
3
  require 'test_declarative'
4
4
  require 'hashr'
metadata CHANGED
@@ -1,48 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hashr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
5
- prerelease:
4
+ version: 1.0.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Sven Fuchs
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-08-22 00:00:00.000000000 Z
11
+ date: 2015-10-04 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rake
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :development
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: test_declarative
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: 0.0.2
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: 0.0.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 5.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 5.0.0
46
55
  description: Simple Hash extension to make working with nested hashes (e.g. for configuration)
47
56
  easier and less error-prone.
48
57
  email: svenfuchs@artweb-design.de
@@ -50,41 +59,41 @@ executables: []
50
59
  extensions: []
51
60
  extra_rdoc_files: []
52
61
  files:
62
+ - Gemfile
63
+ - Gemfile.lock
64
+ - MIT-LICENSE
65
+ - README.md
66
+ - Rakefile
67
+ - hashr.gemspec
68
+ - lib/hashr.rb
53
69
  - lib/hashr/core_ext/ruby/hash.rb
54
70
  - lib/hashr/env_defaults.rb
55
71
  - lib/hashr/version.rb
56
- - lib/hashr.rb
57
72
  - test/core_ext_test.rb
58
73
  - test/hashr_test.rb
59
74
  - test/test_helper.rb
60
- - Gemfile
61
- - Gemfile.lock
62
- - MIT-LICENSE
63
- - Rakefile
64
- - README.md
65
75
  homepage: http://github.com/svenfuchs/hashr
66
76
  licenses: []
77
+ metadata: {}
67
78
  post_install_message:
68
79
  rdoc_options: []
69
80
  require_paths:
70
81
  - lib
71
82
  required_ruby_version: !ruby/object:Gem::Requirement
72
- none: false
73
83
  requirements:
74
- - - ! '>='
84
+ - - ">="
75
85
  - !ruby/object:Gem::Version
76
86
  version: '0'
77
87
  required_rubygems_version: !ruby/object:Gem::Requirement
78
- none: false
79
88
  requirements:
80
- - - ! '>='
89
+ - - ">="
81
90
  - !ruby/object:Gem::Version
82
91
  version: '0'
83
92
  requirements: []
84
- rubyforge_project: ! '[none]'
85
- rubygems_version: 1.8.23
93
+ rubyforge_project: "[none]"
94
+ rubygems_version: 2.4.5
86
95
  signing_key:
87
- specification_version: 3
96
+ specification_version: 4
88
97
  summary: Simple Hash extension to make working with nested hashes (e.g. for configuration)
89
98
  easier and less error-prone
90
99
  test_files: []