necromancer 0.3.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +70 -3
  3. data/README.md +204 -86
  4. data/lib/necromancer.rb +17 -18
  5. data/lib/necromancer/configuration.rb +1 -1
  6. data/lib/necromancer/context.rb +16 -3
  7. data/lib/necromancer/conversion_target.rb +31 -14
  8. data/lib/necromancer/conversions.rb +39 -16
  9. data/lib/necromancer/converter.rb +10 -8
  10. data/lib/necromancer/converters/array.rb +143 -45
  11. data/lib/necromancer/converters/boolean.rb +21 -19
  12. data/lib/necromancer/converters/date_time.rb +58 -13
  13. data/lib/necromancer/converters/hash.rb +119 -0
  14. data/lib/necromancer/converters/numeric.rb +32 -28
  15. data/lib/necromancer/converters/range.rb +44 -18
  16. data/lib/necromancer/null_converter.rb +4 -2
  17. data/lib/necromancer/version.rb +2 -2
  18. metadata +39 -72
  19. data/.gitignore +0 -14
  20. data/.rspec +0 -3
  21. data/.ruby-version +0 -1
  22. data/.travis.yml +0 -19
  23. data/Gemfile +0 -16
  24. data/Rakefile +0 -8
  25. data/necromancer.gemspec +0 -21
  26. data/spec/spec_helper.rb +0 -53
  27. data/spec/unit/can_spec.rb +0 -11
  28. data/spec/unit/config_spec.rb +0 -32
  29. data/spec/unit/configuration/new_spec.rb +0 -30
  30. data/spec/unit/conversions/register_spec.rb +0 -49
  31. data/spec/unit/convert_spec.rb +0 -104
  32. data/spec/unit/converters/array/array_to_boolean_spec.rb +0 -22
  33. data/spec/unit/converters/array/array_to_numeric_spec.rb +0 -22
  34. data/spec/unit/converters/array/array_to_set_spec.rb +0 -18
  35. data/spec/unit/converters/array/object_to_array_spec.rb +0 -21
  36. data/spec/unit/converters/array/string_to_array_spec.rb +0 -33
  37. data/spec/unit/converters/boolean/boolean_to_integer_spec.rb +0 -26
  38. data/spec/unit/converters/boolean/integer_to_boolean_spec.rb +0 -22
  39. data/spec/unit/converters/boolean/string_to_boolean_spec.rb +0 -36
  40. data/spec/unit/converters/date_time/string_to_date_spec.rb +0 -22
  41. data/spec/unit/converters/date_time/string_to_datetime_spec.rb +0 -32
  42. data/spec/unit/converters/numeric/string_to_float_spec.rb +0 -48
  43. data/spec/unit/converters/numeric/string_to_integer_spec.rb +0 -62
  44. data/spec/unit/converters/numeric/string_to_numeric_spec.rb +0 -32
  45. data/spec/unit/converters/range/string_to_range_spec.rb +0 -35
  46. data/spec/unit/new_spec.rb +0 -12
  47. data/spec/unit/register_spec.rb +0 -17
  48. data/tasks/console.rake +0 -10
  49. data/tasks/coverage.rake +0 -11
  50. data/tasks/spec.rake +0 -29
@@ -1,9 +1,11 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "converter"
2
4
 
3
5
  module Necromancer
4
6
  # A pass through converter
5
7
  class NullConverter < Converter
6
- def call(value, options = {})
8
+ def call(value, strict: config.strict)
7
9
  value
8
10
  end
9
11
  end # NullConverter
@@ -1,5 +1,5 @@
1
- # coding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Necromancer
4
- VERSION = "0.3.0"
4
+ VERSION = "0.7.0"
5
5
  end # Necromancer
metadata CHANGED
@@ -1,45 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: necromancer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-14 00:00:00.000000000 Z
11
+ date: 2020-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.6'
19
+ version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.6'
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
27
41
  description: Conversion from one object type to another with a bit of black magic.
28
42
  email:
29
- - ''
43
+ - piotr@piotrmurach.com
30
44
  executables: []
31
45
  extensions: []
32
- extra_rdoc_files: []
46
+ extra_rdoc_files:
47
+ - README.md
48
+ - CHANGELOG.md
49
+ - LICENSE.txt
33
50
  files:
34
- - .gitignore
35
- - .rspec
36
- - .ruby-version
37
- - .travis.yml
38
51
  - CHANGELOG.md
39
- - Gemfile
40
52
  - LICENSE.txt
41
53
  - README.md
42
- - Rakefile
43
54
  - lib/necromancer.rb
44
55
  - lib/necromancer/configuration.rb
45
56
  - lib/necromancer/context.rb
@@ -49,81 +60,37 @@ files:
49
60
  - lib/necromancer/converters/array.rb
50
61
  - lib/necromancer/converters/boolean.rb
51
62
  - lib/necromancer/converters/date_time.rb
63
+ - lib/necromancer/converters/hash.rb
52
64
  - lib/necromancer/converters/numeric.rb
53
65
  - lib/necromancer/converters/range.rb
54
66
  - lib/necromancer/null_converter.rb
55
67
  - lib/necromancer/version.rb
56
- - necromancer.gemspec
57
- - spec/spec_helper.rb
58
- - spec/unit/can_spec.rb
59
- - spec/unit/config_spec.rb
60
- - spec/unit/configuration/new_spec.rb
61
- - spec/unit/conversions/register_spec.rb
62
- - spec/unit/convert_spec.rb
63
- - spec/unit/converters/array/array_to_boolean_spec.rb
64
- - spec/unit/converters/array/array_to_numeric_spec.rb
65
- - spec/unit/converters/array/array_to_set_spec.rb
66
- - spec/unit/converters/array/object_to_array_spec.rb
67
- - spec/unit/converters/array/string_to_array_spec.rb
68
- - spec/unit/converters/boolean/boolean_to_integer_spec.rb
69
- - spec/unit/converters/boolean/integer_to_boolean_spec.rb
70
- - spec/unit/converters/boolean/string_to_boolean_spec.rb
71
- - spec/unit/converters/date_time/string_to_date_spec.rb
72
- - spec/unit/converters/date_time/string_to_datetime_spec.rb
73
- - spec/unit/converters/numeric/string_to_float_spec.rb
74
- - spec/unit/converters/numeric/string_to_integer_spec.rb
75
- - spec/unit/converters/numeric/string_to_numeric_spec.rb
76
- - spec/unit/converters/range/string_to_range_spec.rb
77
- - spec/unit/new_spec.rb
78
- - spec/unit/register_spec.rb
79
- - tasks/console.rake
80
- - tasks/coverage.rake
81
- - tasks/spec.rake
82
- homepage: https://github.com/peter-murach/necromancer
68
+ homepage: https://github.com/piotrmurach/necromancer
83
69
  licenses:
84
70
  - MIT
85
- metadata: {}
71
+ metadata:
72
+ allowed_push_host: https://rubygems.org
73
+ changelog_uri: https://github.com/piotrmurach/necromancer/blob/master/CHANGELOG.md
74
+ documentation_uri: https://www.rubydoc.info/gems/necromancer
75
+ homepage_uri: https://github.com/piotrmurach/necromancer
76
+ source_code_uri: https://github.com/piotrmurach/necromancer
86
77
  post_install_message:
87
78
  rdoc_options: []
88
79
  require_paths:
89
80
  - lib
90
81
  required_ruby_version: !ruby/object:Gem::Requirement
91
82
  requirements:
92
- - - '>='
83
+ - - ">="
93
84
  - !ruby/object:Gem::Version
94
- version: '0'
85
+ version: 2.0.0
95
86
  required_rubygems_version: !ruby/object:Gem::Requirement
96
87
  requirements:
97
- - - '>='
88
+ - - ">="
98
89
  - !ruby/object:Gem::Version
99
90
  version: '0'
100
91
  requirements: []
101
- rubyforge_project:
102
- rubygems_version: 2.0.3
92
+ rubygems_version: 3.2.3
103
93
  signing_key:
104
94
  specification_version: 4
105
95
  summary: Conversion from one object type to another with a bit of black magic.
106
- test_files:
107
- - spec/spec_helper.rb
108
- - spec/unit/can_spec.rb
109
- - spec/unit/config_spec.rb
110
- - spec/unit/configuration/new_spec.rb
111
- - spec/unit/conversions/register_spec.rb
112
- - spec/unit/convert_spec.rb
113
- - spec/unit/converters/array/array_to_boolean_spec.rb
114
- - spec/unit/converters/array/array_to_numeric_spec.rb
115
- - spec/unit/converters/array/array_to_set_spec.rb
116
- - spec/unit/converters/array/object_to_array_spec.rb
117
- - spec/unit/converters/array/string_to_array_spec.rb
118
- - spec/unit/converters/boolean/boolean_to_integer_spec.rb
119
- - spec/unit/converters/boolean/integer_to_boolean_spec.rb
120
- - spec/unit/converters/boolean/string_to_boolean_spec.rb
121
- - spec/unit/converters/date_time/string_to_date_spec.rb
122
- - spec/unit/converters/date_time/string_to_datetime_spec.rb
123
- - spec/unit/converters/numeric/string_to_float_spec.rb
124
- - spec/unit/converters/numeric/string_to_integer_spec.rb
125
- - spec/unit/converters/numeric/string_to_numeric_spec.rb
126
- - spec/unit/converters/range/string_to_range_spec.rb
127
- - spec/unit/new_spec.rb
128
- - spec/unit/register_spec.rb
129
- has_rdoc:
96
+ test_files: []
data/.gitignore DELETED
@@ -1,14 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- mkmf.log
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --color
2
- --require spec_helper
3
- --warnings
@@ -1 +0,0 @@
1
- 2.0.0
@@ -1,19 +0,0 @@
1
- language: ruby
2
- bundler_args: --without yard benchmarks
3
- script: "bundle exec rake ci"
4
- rvm:
5
- - 1.9.3
6
- - 2.0.0
7
- - 2.1.0
8
- - ruby-head
9
- - jruby-19mode
10
- - rbx-2
11
- matrix:
12
- include:
13
- - rvm: jruby-head
14
- allow_failures:
15
- - rvm: ruby-head
16
- - rvm: jruby-head
17
- fast_finish: true
18
- branches:
19
- only: master
data/Gemfile DELETED
@@ -1,16 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- group :development do
6
- gem 'rake', '~> 10.3.2'
7
- gem 'rspec', '~> 3.1.0'
8
- gem 'yard', '~> 0.8.7'
9
- gem 'benchmark-ips', '~> 2.0.0'
10
- end
11
-
12
- group :metrics do
13
- gem 'coveralls', '~> 0.7.0'
14
- gem 'simplecov', '~> 0.8.2'
15
- gem 'yardstick', '~> 0.9.9'
16
- end
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'bundler/gem_tasks'
4
-
5
- FileList['tasks/**/*.rake'].each(&method(:import))
6
-
7
- desc 'Run all specs'
8
- task ci: %w[ spec ]
@@ -1,21 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'necromancer/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'necromancer'
8
- spec.version = Necromancer::VERSION
9
- spec.authors = ['Piotr Murach']
10
- spec.email = ['']
11
- spec.summary = %q{Conversion from one object type to another with a bit of black magic.}
12
- spec.description = %q{Conversion from one object type to another with a bit of black magic.}
13
- spec.homepage = 'https://github.com/peter-murach/necromancer'
14
- spec.license = 'MIT'
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.test_files = spec.files.grep(%r{^(spec)/})
18
- spec.require_paths = ["lib"]
19
-
20
- spec.add_development_dependency "bundler", "~> 1.6"
21
- end
@@ -1,53 +0,0 @@
1
- # encoding: utf-8
2
-
3
- if RUBY_VERSION > '1.9' and (ENV['COVERAGE'] || ENV['TRAVIS'])
4
- require 'simplecov'
5
- require 'coveralls'
6
-
7
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
- SimpleCov::Formatter::HTMLFormatter,
9
- Coveralls::SimpleCov::Formatter
10
- ]
11
-
12
- SimpleCov.start do
13
- command_name 'spec'
14
- add_filter 'spec'
15
- end
16
- end
17
-
18
- require 'necromancer'
19
-
20
- RSpec.configure do |config|
21
- config.expect_with :rspec do |expectations|
22
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
23
- end
24
-
25
- config.mock_with :rspec do |mocks|
26
- mocks.verify_partial_doubles = true
27
- end
28
-
29
- # Limits the available syntax to the non-monkey patched syntax that is recommended.
30
- config.disable_monkey_patching!
31
-
32
- # This setting enables warnings. It's recommended, but in some cases may
33
- # be too noisy due to issues in dependencies.
34
- config.warnings = true
35
-
36
- if config.files_to_run.one?
37
- config.default_formatter = 'doc'
38
- end
39
-
40
- config.profile_examples = 2
41
-
42
- config.order = :random
43
-
44
- Kernel.srand config.seed
45
-
46
- config.before :each do
47
- [:UpcaseConverter, :Custom].each do |class_name|
48
- if Object.const_defined?(class_name)
49
- Object.send(:remove_const, class_name)
50
- end
51
- end
52
- end
53
- end
@@ -1,11 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Necromancer, 'can?' do
6
- it "checks if conversion is possible" do
7
- converter = described_class.new
8
- expect(converter.can?(:string, :integer)).to eq(true)
9
- expect(converter.can?(:unknown, :integer)).to eq(false)
10
- end
11
- end
@@ -1,32 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Necromancer, 'config' do
6
- it "configures global settings per instance" do
7
- converter = described_class.new
8
-
9
- converter.configure do |config|
10
- config.strict false
11
- end
12
- expect(converter.convert("1.2.3").to(:array)).to eq(["1.2.3"])
13
-
14
- converter.configure do |config|
15
- config.strict true
16
- end
17
- expect {
18
- converter.convert("1.2.3").to(:array)
19
- }.to raise_error(Necromancer::ConversionTypeError)
20
- end
21
-
22
- it "configures global settings through instance block" do
23
- converter = described_class.new do |config|
24
- config.strict true
25
- end
26
- expect(converter.configuration.strict).to eq(true)
27
-
28
- expect {
29
- converter.convert("1.2.3").to(:array)
30
- }.to raise_error(Necromancer::ConversionTypeError)
31
- end
32
- end
@@ -1,30 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Necromancer::Configuration, '.new' do
6
-
7
- subject(:config) { described_class.new }
8
-
9
- it { is_expected.to respond_to(:strict=) }
10
-
11
- it { is_expected.to respond_to(:copy=) }
12
-
13
- it "is in non-strict mode by default" do
14
- expect(config.strict).to eq(false)
15
- end
16
-
17
- it "is in copy mode by default" do
18
- expect(config.copy).to eq(true)
19
- end
20
-
21
- it "allows to set strict through method" do
22
- config.strict true
23
- expect(config.strict).to eq(true)
24
- end
25
-
26
- it "allows to set copy mode through method" do
27
- config.copy false
28
- expect(config.strict).to eq(false)
29
- end
30
- end
@@ -1,49 +0,0 @@
1
- # coding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- RSpec.describe Necromancer::Conversions, '.register' do
6
- it "allows to register converter" do
7
- context = described_class.new
8
- converter = double(:converter, {source: :string, target: :numeric})
9
- expect(context.register(converter)).to eq(true)
10
- expect(context[:string, :numeric]).to eq(converter)
11
- end
12
-
13
- it "allows to register converter with no source" do
14
- context = described_class.new
15
- converter = double(:converter, {source: nil, target: :numeric})
16
- expect(context.register(converter)).to eq(true)
17
- expect(context[:none, :numeric]).to eq(converter)
18
- end
19
-
20
- it "allows to register converter with no target" do
21
- context = described_class.new
22
- converter = double(:converter, {source: :string, target: nil})
23
- expect(context.register(converter)).to eq(true)
24
- expect(context[:string, :none]).to eq(converter)
25
- end
26
-
27
- it "allows to register anonymous converter" do
28
- conversions = described_class.new
29
-
30
- conversions.register do |c|
31
- c.source= :string
32
- c.target= :upcase
33
- c.convert = proc { |value| value.to_s.upcase }
34
- end
35
- expect(conversions[:string, :upcase].call('magic')).to eq('MAGIC')
36
- end
37
-
38
- it "allows to register custom converter" do
39
- conversions = described_class.new
40
- UpcaseConverter = Struct.new(:source, :target) do
41
- def call(value)
42
- value.to_s.upcase
43
- end
44
- end
45
- upcase_converter = UpcaseConverter.new(:string, :upcase)
46
- expect(conversions.register(upcase_converter)).to be(true)
47
- expect(conversions[:string, :upcase].call('magic')).to eq('MAGIC')
48
- end
49
- end