dry-importer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.rspec +3 -0
- data/.rubocop.yml +16 -0
- data/.rubocop_todo.yml +6 -0
- data/.travis.yml +30 -0
- data/Gemfile +10 -0
- data/LICENSE +20 -0
- data/README.md +52 -0
- data/Rakefile +12 -0
- data/dry-importer.gemspec +21 -0
- data/lib/dry-importer.rb +1 -0
- data/lib/dry/importer.rb +22 -0
- data/lib/dry/importer/version.rb +5 -0
- data/rakelib/rubocop.rake +18 -0
- data/spec/integration/importer_spec.rb +58 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/support/have_constant_matcher.rb +5 -0
- metadata +106 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 09893159d3b0c5e75d2bd28d314702abeeef2eda
|
4
|
+
data.tar.gz: c71169a5d4f2e4fde3241054a23962f8fca258c1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 510a81c5d8fce52e1da5ef3b2ab85963a7265e73b5bd3e48c514dd41b3257510618ca883085cfd6ea6f5ef8cdc80ddbd4fc2aed3219418601d220ce2091205e2
|
7
|
+
data.tar.gz: b0936a902076b26af041fc0c93887805877e6da62534f3193f87f34cdfcb5b881fc31ac70e2390529cb3b73c35207f5443124d1b4b4e8c1cc7b81cc1d73881d5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# Generated by `rubocop --auto-gen-config`
|
2
|
+
inherit_from: .rubocop_todo.yml
|
3
|
+
|
4
|
+
Metrics/LineLength:
|
5
|
+
Max: 120
|
6
|
+
|
7
|
+
Style/Documentation:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Lint/HandleExceptions:
|
11
|
+
Exclude:
|
12
|
+
- rakelib/*.rake
|
13
|
+
|
14
|
+
Style/FileName:
|
15
|
+
Exclude:
|
16
|
+
- lib/dry-importer.rb
|
data/.rubocop_todo.yml
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
+
# on 2015-07-23 23:48:21 +0100 using RuboCop version 0.32.0.
|
3
|
+
# The point is for the user to remove these configuration records
|
4
|
+
# one by one as the offenses are removed from the code base.
|
5
|
+
# Note that changes in the inspected code, or installation of new
|
6
|
+
# versions of RuboCop, may require this file to be generated again.
|
data/.travis.yml
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
language: ruby
|
2
|
+
sudo: false
|
3
|
+
cache: bundler
|
4
|
+
bundler_args: --without console
|
5
|
+
script:
|
6
|
+
- bundle exec rspec
|
7
|
+
- bundle exec rubocop
|
8
|
+
rvm:
|
9
|
+
- 2.0
|
10
|
+
- 2.1
|
11
|
+
- 2.2
|
12
|
+
- rbx-2
|
13
|
+
- jruby
|
14
|
+
- ruby-head
|
15
|
+
- jruby-head
|
16
|
+
env:
|
17
|
+
global:
|
18
|
+
- JRUBY_OPTS='--dev -J-Xmx1024M'
|
19
|
+
matrix:
|
20
|
+
allow_failures:
|
21
|
+
- rvm: ruby-head
|
22
|
+
- rvm: jruby-head
|
23
|
+
notifications:
|
24
|
+
email: false
|
25
|
+
webhooks:
|
26
|
+
urls:
|
27
|
+
- https://webhooks.gitter.im/e/19098b4253a72c9796db
|
28
|
+
on_success: change # options: [always|never|change] default: always
|
29
|
+
on_failure: always # options: [always|never|change] default: always
|
30
|
+
on_start: false # default: false
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Ruby Object Mapper
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# dry-importer <a href="https://gitter.im/dryrb/chat" target="_blank">![Join the chat at https://gitter.im/dryrb/chat](https://badges.gitter.im/Join%20Chat.svg)</a>
|
2
|
+
|
3
|
+
<a href="https://rubygems.org/gems/dry-importer" target="_blank">![Gem Version](https://badge.fury.io/rb/dry-importer.svg)</a>
|
4
|
+
<a href="https://travis-ci.org/dryrb/dry-importer" target="_blank">![Build Status](https://travis-ci.org/dryrb/dry-importer.svg?branch=master)</a>
|
5
|
+
<a href="https://gemnasium.com/dryrb/dry-importer" target="_blank">![Dependency Status](https://gemnasium.com/dryrb/dry-importer.svg)</a>
|
6
|
+
<a href="https://codeclimate.com/github/dryrb/dry-importer" target="_blank">![Code Climate](https://codeclimate.com/github/dryrb/dry-importer/badges/gpa.svg)</a>
|
7
|
+
<a href="http://inch-ci.org/github/dryrb/dry-importer" target="_blank">![Documentation Status](http://inch-ci.org/github/dryrb/dry-importer.svg?branch=master&style=flat)</a>
|
8
|
+
|
9
|
+
Import a constant tree into another
|
10
|
+
|
11
|
+
## Synopsis
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
module BaseLibrary
|
15
|
+
class SomeClass
|
16
|
+
def self.base_method
|
17
|
+
'base'
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class Tool
|
22
|
+
def self.get_base_method
|
23
|
+
namespace::SomeClass.base_method
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def self.namespace
|
29
|
+
Module.const_get(self.to_s[/(.*)(?=::)/])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module ExtensionLibrary
|
35
|
+
Dry::Importer.import(self, BaseLibrary)
|
36
|
+
|
37
|
+
class SomeClass
|
38
|
+
def self.base_method
|
39
|
+
"was #{super}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
BaseLibrary::Tool.get_base_method
|
45
|
+
# => "base"
|
46
|
+
ExtensionLibrary::Tool.get_base_method
|
47
|
+
# => "was base"
|
48
|
+
```
|
49
|
+
|
50
|
+
## License
|
51
|
+
|
52
|
+
See `LICENSE` file.
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
|
4
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
5
|
+
|
6
|
+
require 'rspec/core'
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
|
9
|
+
task default: :spec
|
10
|
+
|
11
|
+
desc 'Run all specs in spec directory'
|
12
|
+
RSpec::Core::RakeTask.new(:spec)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require File.expand_path('../lib/dry/importer/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |spec|
|
5
|
+
spec.name = 'dry-importer'
|
6
|
+
spec.version = Dry::Importer::VERSION
|
7
|
+
spec.authors = ['Andy Holland']
|
8
|
+
spec.email = ['andyholland1991@aol.com']
|
9
|
+
spec.summary = 'Import a constant tree into another'
|
10
|
+
spec.homepage = 'https://github.com/dryrb/dry-importer'
|
11
|
+
spec.license = 'MIT'
|
12
|
+
|
13
|
+
spec.files = `git ls-files -z`.split("\x0")
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = ['lib']
|
17
|
+
|
18
|
+
spec.add_development_dependency 'bundler'
|
19
|
+
spec.add_development_dependency 'rake'
|
20
|
+
spec.add_development_dependency 'rspec'
|
21
|
+
end
|
data/lib/dry-importer.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'dry/importer'
|
data/lib/dry/importer.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'dry/importer/version'
|
2
|
+
|
3
|
+
module Dry
|
4
|
+
module Importer
|
5
|
+
module_function
|
6
|
+
|
7
|
+
WRAPPER_MAP = {
|
8
|
+
Class => ->(const) { Class.new(const) },
|
9
|
+
Module => ->(const) { Module.new.extend(const) }
|
10
|
+
}
|
11
|
+
NOOP = ->(const) { const }
|
12
|
+
|
13
|
+
def import(target, namespace)
|
14
|
+
namespace.constants(false).each do |constant|
|
15
|
+
namespace.const_get(constant).tap do |const|
|
16
|
+
ns = target.const_set(constant, WRAPPER_MAP.fetch(const.class, NOOP).call(const))
|
17
|
+
import(ns, const) if const.respond_to?(:constants)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
begin
|
2
|
+
require 'rubocop/rake_task'
|
3
|
+
|
4
|
+
Rake::Task[:default].enhance [:rubocop]
|
5
|
+
|
6
|
+
RuboCop::RakeTask.new do |task|
|
7
|
+
task.options << '--display-cop-names'
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :rubocop do
|
11
|
+
desc 'Generate a configuration file acting as a TODO list.'
|
12
|
+
task :auto_gen_config do
|
13
|
+
exec 'bundle exec rubocop --auto-gen-config'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
rescue LoadError
|
18
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
RSpec.describe 'Dry::Importer' do
|
2
|
+
before do
|
3
|
+
module Test
|
4
|
+
module BaseLibrary
|
5
|
+
VERSION = '0.1.0'
|
6
|
+
|
7
|
+
module Tools
|
8
|
+
EMPTY_ARRAY = [].freeze
|
9
|
+
|
10
|
+
class SomeClass; end
|
11
|
+
|
12
|
+
class FirstTool
|
13
|
+
def self.empty_array
|
14
|
+
EMPTY_ARRAY
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class SecondTool
|
19
|
+
def self.some_class
|
20
|
+
namespace::SomeClass.new
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def self.namespace
|
26
|
+
Module.const_get(self.to_s[/(.*)(?=::)/])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
module ExtensionLibrary
|
33
|
+
Dry::Importer.import(self, Test::BaseLibrary)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'imports a constant tree into another' do
|
39
|
+
expect(Test::ExtensionLibrary).to have_constant(:VERSION)
|
40
|
+
expect(Test::ExtensionLibrary).to have_constant(:Tools)
|
41
|
+
expect(Test::ExtensionLibrary::Tools).to have_constant(:EMPTY_ARRAY)
|
42
|
+
expect(Test::ExtensionLibrary::Tools).to have_constant(:SomeClass)
|
43
|
+
expect(Test::ExtensionLibrary::Tools).to have_constant(:FirstTool)
|
44
|
+
expect(Test::ExtensionLibrary::Tools).to have_constant(:SecondTool)
|
45
|
+
expect(Test::ExtensionLibrary::VERSION).to eq('0.1.0')
|
46
|
+
expect(Test::ExtensionLibrary::Tools::EMPTY_ARRAY).to eq([])
|
47
|
+
expect(Test::ExtensionLibrary::Tools::EMPTY_ARRAY).to be_frozen
|
48
|
+
expect(Test::ExtensionLibrary::Tools::FirstTool.empty_array).to eq([])
|
49
|
+
expect(Test::ExtensionLibrary::Tools::SecondTool.some_class).to be_a(
|
50
|
+
Test::ExtensionLibrary::Tools::SomeClass
|
51
|
+
)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'does not mutate original namespace' do
|
55
|
+
Test::ExtensionLibrary::VERSION = '0.2.0'
|
56
|
+
expect(Test::BaseLibrary::VERSION).to eq('0.1.0')
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'dry-importer'
|
4
|
+
|
5
|
+
Dir[Pathname(__FILE__).dirname.join('support/**/*.rb').to_s].each do |file|
|
6
|
+
require file
|
7
|
+
end
|
8
|
+
|
9
|
+
# Namespace holding all objects created during specs
|
10
|
+
module Test
|
11
|
+
def self.remove_constants
|
12
|
+
constants.each(&method(:remove_const))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.after do
|
18
|
+
Test.remove_constants
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dry-importer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andy Holland
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- andyholland1991@aol.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- .rspec
|
64
|
+
- .rubocop.yml
|
65
|
+
- .rubocop_todo.yml
|
66
|
+
- .travis.yml
|
67
|
+
- Gemfile
|
68
|
+
- LICENSE
|
69
|
+
- README.md
|
70
|
+
- Rakefile
|
71
|
+
- dry-importer.gemspec
|
72
|
+
- lib/dry-importer.rb
|
73
|
+
- lib/dry/importer.rb
|
74
|
+
- lib/dry/importer/version.rb
|
75
|
+
- rakelib/rubocop.rake
|
76
|
+
- spec/integration/importer_spec.rb
|
77
|
+
- spec/spec_helper.rb
|
78
|
+
- spec/support/have_constant_matcher.rb
|
79
|
+
homepage: https://github.com/dryrb/dry-importer
|
80
|
+
licenses:
|
81
|
+
- MIT
|
82
|
+
metadata: {}
|
83
|
+
post_install_message:
|
84
|
+
rdoc_options: []
|
85
|
+
require_paths:
|
86
|
+
- lib
|
87
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - '>='
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
requirements: []
|
98
|
+
rubyforge_project:
|
99
|
+
rubygems_version: 2.4.6
|
100
|
+
signing_key:
|
101
|
+
specification_version: 4
|
102
|
+
summary: Import a constant tree into another
|
103
|
+
test_files:
|
104
|
+
- spec/integration/importer_spec.rb
|
105
|
+
- spec/spec_helper.rb
|
106
|
+
- spec/support/have_constant_matcher.rb
|