config_mapper 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2b50eb5ad224762a6891a4bb75077f7cf24dd19a
4
- data.tar.gz: ee8a164e3478984a0793df79345af4bbaa67054a
3
+ metadata.gz: 730e8ad6d07818c8a126170b75e361889117fb22
4
+ data.tar.gz: 2c1d748c237d41c25bd9cedeee534ec9638a912c
5
5
  SHA512:
6
- metadata.gz: 4f16a33006c27cc333e7bed302052b372728755a900103f42781f116639cde0a6af56c598d2335677bba75b031ed49e0c3c70162d00c5bcce0cce0085d80a302
7
- data.tar.gz: 0ef76dfb3980e16c6e671e5a055e4deb546408c1515f7675da6bccf43d10357d4432b7c43262f8767f7b2017e42765e869ca44823c502480661098b5cde93b52
6
+ metadata.gz: 36fa79abe4a1c4ab0deec2b8637ba2cc934012019f04ee9f07a225c06cdde1c7a783e59ed68c6f77cda4c295ce16e3f916d91ce74829465adbe3d16633da5541
7
+ data.tar.gz: 6bfe96aa8076d5a76b8205179e2a6aa2010aa64d19b0d791bcef6707fbc2415c66cc2c07184151749418a3b554134ab6987cf29f2877e0f439964e299d8dbd4a
data/lib/config_mapper.rb CHANGED
@@ -1,5 +1,5 @@
1
+ require "config_mapper/collection_mapper"
1
2
  require "config_mapper/config_dict"
2
- require "config_mapper/dict_mapper"
3
3
  require "config_mapper/object_mapper"
4
4
 
5
5
  # Supports marshalling of plain-old data (e.g. loaded from
@@ -28,8 +28,8 @@ module ConfigMapper
28
28
  alias set configure_with
29
29
 
30
30
  def mapper_for(target)
31
- if target.is_a?(Hash) || target.is_a?(ConfigMapper::ConfigDict)
32
- DictMapper.new(target)
31
+ if target.respond_to?(:[]) && target.respond_to?(:each)
32
+ CollectionMapper.new(target)
33
33
  else
34
34
  ObjectMapper.new(target)
35
35
  end
@@ -2,9 +2,9 @@ require "config_mapper/mapper"
2
2
 
3
3
  module ConfigMapper
4
4
 
5
- # Configuration proxy for a Hash.
5
+ # Configuration proxy for a collection (e.g. Hash, Array, ConfigDict)
6
6
  #
7
- class DictMapper < Mapper
7
+ class CollectionMapper < Mapper
8
8
 
9
9
  def initialize(hash)
10
10
  @hash = hash
@@ -22,6 +22,10 @@ module ConfigMapper
22
22
  @hash[key] = value
23
23
  end
24
24
 
25
+ def can_set?(key)
26
+ @hash.respond_to?("[]=")
27
+ end
28
+
25
29
  end
26
30
 
27
31
  end
@@ -25,7 +25,7 @@ module ConfigMapper
25
25
 
26
26
  extend Forwardable
27
27
 
28
- def_delegators :@entries, :each, :empty?, :keys, :map, :size
28
+ def_delegators :@entries, :each, :empty?, :key?, :keys, :map, :size
29
29
 
30
30
  include Enumerable
31
31
 
@@ -10,8 +10,14 @@ module ConfigMapper
10
10
  #
11
11
  def configure_with(data)
12
12
  errors = {}
13
- data.each do |key, value|
14
- configure_attribute(key, value, errors)
13
+ if data.respond_to?(:each_pair)
14
+ data.each_pair do |key, value|
15
+ configure_attribute(key, value, errors)
16
+ end
17
+ else
18
+ data.each_with_index do |value, index|
19
+ configure_attribute(index, value, errors)
20
+ end
15
21
  end
16
22
  errors
17
23
  end
@@ -22,13 +28,13 @@ module ConfigMapper
22
28
  #
23
29
  def configure_attribute(key, value, errors)
24
30
  attribute_path = path(key)
25
- if value.is_a?(Hash) && !get(key).nil?
31
+ if can_set?(key)
32
+ set(key, value)
33
+ else
26
34
  nested_errors = ConfigMapper.configure_with(value, get(key))
27
35
  nested_errors.each do |nested_path, error|
28
36
  errors["#{attribute_path}#{nested_path}"] = error
29
37
  end
30
- else
31
- set(key, value)
32
38
  end
33
39
  rescue NoMethodError, ArgumentError => e
34
40
  errors[attribute_path] = e
@@ -22,6 +22,10 @@ module ConfigMapper
22
22
  @object.public_send("#{key}=", value)
23
23
  end
24
24
 
25
+ def can_set?(key)
26
+ @object.respond_to?("#{key}=")
27
+ end
28
+
25
29
  end
26
30
 
27
31
  end
@@ -1,5 +1,5 @@
1
1
  module ConfigMapper
2
2
 
3
- VERSION = "1.2.0".freeze
3
+ VERSION = "1.3.0".freeze
4
4
 
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-09 00:00:00.000000000 Z
11
+ date: 2016-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -59,20 +59,12 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - ".gitignore"
63
- - ".rspec"
64
- - ".rubocop.yml"
65
- - ".travis.yml"
66
- - Gemfile
67
- - Guardfile
68
62
  - LICENSE.txt
69
63
  - README.md
70
- - Rakefile
71
- - config_mapper.gemspec
72
64
  - lib/config_mapper.rb
65
+ - lib/config_mapper/collection_mapper.rb
73
66
  - lib/config_mapper/config_dict.rb
74
67
  - lib/config_mapper/config_struct.rb
75
- - lib/config_mapper/dict_mapper.rb
76
68
  - lib/config_mapper/mapper.rb
77
69
  - lib/config_mapper/object_mapper.rb
78
70
  - lib/config_mapper/version.rb
@@ -96,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
88
  version: '0'
97
89
  requirements: []
98
90
  rubyforge_project:
99
- rubygems_version: 2.5.1
91
+ rubygems_version: 2.4.5.1
100
92
  signing_key:
101
93
  specification_version: 4
102
94
  summary: Maps config data onto plain old objects
data/.gitignore DELETED
@@ -1,9 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format documentation
2
- --color
data/.rubocop.yml DELETED
@@ -1,54 +0,0 @@
1
- Eval:
2
- Exclude:
3
- - "Rakefile"
4
-
5
- Metrics/AbcSize:
6
- Enabled: false
7
-
8
- Metrics/LineLength:
9
- Max: 120
10
-
11
- Metrics/MethodLength:
12
- Max: 30
13
-
14
- Style/AccessorMethodName:
15
- Enabled: false
16
-
17
- Style/ClassAndModuleChildren:
18
- EnforcedStyle: nested
19
- Exclude:
20
- - "spec/**/*"
21
-
22
- Style/Documentation:
23
- Exclude:
24
- - "lib/**/version.rb"
25
- - "spec/**/*"
26
-
27
- Style/EmptyLinesAroundBlockBody:
28
- Enabled: false
29
-
30
- Style/EmptyLinesAroundClassBody:
31
- EnforcedStyle: empty_lines
32
-
33
- Style/EmptyLinesAroundModuleBody:
34
- Enabled: false
35
-
36
- Style/Encoding:
37
- EnforcedStyle: when_needed
38
- Enabled: true
39
-
40
- Style/FileName:
41
- Exclude:
42
- - "bin/*"
43
-
44
- Style/HashSyntax:
45
- EnforcedStyle: hash_rockets
46
-
47
- Style/Lambda:
48
- Enabled: false
49
-
50
- Style/StringLiterals:
51
- EnforcedStyle: double_quotes
52
-
53
- Style/WordArray:
54
- Enabled: false
data/.travis.yml DELETED
@@ -1,4 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.2.2
4
- before_install: gem install bundler -v 1.10.5
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- group :development do
4
- gem "guard-rspec", :require => false
5
- gem "rubocop", :require => false
6
- end
7
-
8
- # Specify your gem's dependencies in config_mapper.gemspec
9
- gemspec
data/Guardfile DELETED
@@ -1,43 +0,0 @@
1
- # A sample Guardfile
2
- # More info at https://github.com/guard/guard#readme
3
-
4
- ## Uncomment and set this to only include directories you want to watch
5
- # directories %w(app lib config test spec features) \
6
- # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
-
8
- ## Note: if you are using the `directories` clause above and you are not
9
- ## watching the project directory ('.'), then you will want to move
10
- ## the Guardfile to a watched dir and symlink it back, e.g.
11
- #
12
- # $ mkdir config
13
- # $ mv Guardfile config/
14
- # $ ln -s config/Guardfile .
15
- #
16
- # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
-
18
- # Note: The cmd option is now required due to the increasing number of ways
19
- # rspec may be run, below are examples of the most common uses.
20
- # * bundler: 'bundle exec rspec'
21
- # * bundler binstubs: 'bin/rspec'
22
- # * spring: 'bin/rspec' (This will use spring if running and you have
23
- # installed the spring binstubs per the docs)
24
- # * zeus: 'zeus rspec' (requires the server to be started separately)
25
- # * 'just' rspec: 'rspec'
26
-
27
- guard :rspec, :cmd => "bundle exec rspec" do
28
- require "guard/rspec/dsl"
29
- dsl = Guard::RSpec::Dsl.new(self)
30
-
31
- # Feel free to open issues for suggestions and improvements
32
-
33
- # RSpec files
34
- rspec = dsl.rspec
35
- watch(rspec.spec_helper) { rspec.spec_dir }
36
- watch(rspec.spec_support) { rspec.spec_dir }
37
- watch(rspec.spec_files)
38
-
39
- # Ruby files
40
- ruby = dsl.ruby
41
- dsl.watch_spec_files_for(ruby.lib_files)
42
-
43
- end
data/Rakefile DELETED
@@ -1,6 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new(:spec)
5
-
6
- task :default => :spec
@@ -1,25 +0,0 @@
1
- lib = File.expand_path("../lib", __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "config_mapper/version"
4
-
5
- Gem::Specification.new do |spec|
6
-
7
- spec.name = "config_mapper"
8
- spec.version = ConfigMapper::VERSION
9
-
10
- spec.summary = "Maps config data onto plain old objects"
11
- spec.license = "MIT"
12
-
13
- spec.authors = ["Mike Williams"]
14
- spec.email = ["mdub@dogbiscuit.org"]
15
- spec.homepage = "https://github.com/mdub/config_mapper"
16
-
17
- spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.test_files = spec.files.grep(%r{^spec/})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency "bundler", "~> 1.10"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "rspec"
24
-
25
- end