import.rb 0.1.2 → 0.2.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +15 -0
- data/Guardfile +12 -0
- data/README.md +6 -1
- data/bin/console +3 -3
- data/import.rb.gemspec +5 -1
- data/lib/import.rb +66 -50
- data/lib/import/version.rb +1 -0
- metadata +61 -3
- data/lib/version.rb +0 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a6608c08d4bd4a80dd415303d2641794cfac2edc
|
4
|
+
data.tar.gz: 1c55989625bdb68f1bd9a184e3ec672a698de4fe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cbb17dd2f69aff5848a7e1b8bd5dc1a3800a25e21344140c89e0d399dd8b50a5df9e51b123a8a06f15d09138cf2dc1549827a56abb5c02c891d76d656b90fdd7
|
7
|
+
data.tar.gz: 9c808c2d667082bd705679cce1cc96e4b4a201a7b8177145e73822ff11f034aa42a7c7ad98912b25e7477f2b724d69c457f09cc7ef04ef4b8afeec84608aab0b
|
data/.travis.yml
ADDED
data/Guardfile
ADDED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
[](https://badge.fury.io/rb/import.rb)
|
2
|
+
[](https://travis-ci.org/pocke/import.rb)
|
2
3
|
|
3
4
|
# import.rb
|
4
5
|
|
@@ -37,7 +38,7 @@ end
|
|
37
38
|
|
38
39
|
```ruby
|
39
40
|
require 'import'
|
40
|
-
cat = import('./cat')::Cat
|
41
|
+
cat = Import.import('./cat')::Cat
|
41
42
|
cat.new.meow # => meow meow
|
42
43
|
|
43
44
|
# Cat # => uninitialized constant Cat (NameError)
|
@@ -53,3 +54,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
53
54
|
|
54
55
|
Bug reports and pull requests are welcome on GitHub at https://github.com/pocke/import.rb .
|
55
56
|
|
57
|
+
|
58
|
+
## Reference
|
59
|
+
|
60
|
+
- [require しないで Ruby を書く -- import.rb というアプローチ](http://pocke.hatenablog.com/entry/2015/10/28/154214) (Japanese Blog)
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
require "bundler/setup"
|
4
|
-
require "import
|
4
|
+
require "import"
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "import/rb"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require "
|
14
|
-
|
13
|
+
require "pry"
|
14
|
+
binding.pry
|
data/import.rb.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'import'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "import.rb"
|
8
|
-
spec.version =
|
8
|
+
spec.version = Import::VERSION
|
9
9
|
spec.authors = ["Masataka Kuwabara"]
|
10
10
|
spec.email = ["p.ck.t22@gmail.com"]
|
11
11
|
|
@@ -21,4 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.10"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "test-unit", "~> 3.1.5"
|
25
|
+
spec.add_development_dependency "guard", "~> 2.13.0"
|
26
|
+
spec.add_development_dependency "guard-test", "~> 2.0.6"
|
27
|
+
spec.add_development_dependency "pry", "~> 0.10.2"
|
24
28
|
end
|
data/lib/import.rb
CHANGED
@@ -1,60 +1,76 @@
|
|
1
1
|
require 'pathname'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
#
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
return full_path if FileTest.file?(full_path)
|
13
|
-
|
14
|
-
rb ="#{full_path}.rb"
|
15
|
-
return rb if FileTest.file?(rb)
|
16
|
-
|
17
|
-
return nil
|
18
|
-
}
|
19
|
-
|
20
|
-
# @param [String] feature
|
21
|
-
# @return [String|nil]
|
22
|
-
find_file = -> (feature) {
|
23
|
-
# absolute path
|
24
|
-
if feature[0] == '/'
|
25
|
-
full_path = exist_file.(feature)
|
26
|
-
return full_path if full_path
|
27
|
-
end
|
3
|
+
module Import
|
4
|
+
class << self
|
5
|
+
# If file exists, returns full path. unless, returns nil
|
6
|
+
# @param [String] path Base path
|
7
|
+
# @param [String] fname file name
|
8
|
+
# @return [String|nil]
|
9
|
+
def exist_file(path, fname = nil)
|
10
|
+
pn = Pathname.new(path)
|
11
|
+
pn = pn.join(fname) if fname
|
28
12
|
|
29
|
-
|
30
|
-
if feature.start_with?('./') || feature.start_with?('../')
|
31
|
-
base = caller_locations[2].absolute_path
|
32
|
-
full_path = exist_file.(File.expand_path("../#{feature}", base))
|
33
|
-
return full_path if full_path
|
34
|
-
end
|
13
|
+
full_path = pn.to_s
|
35
14
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
15
|
+
return full_path if FileTest.file?(full_path)
|
16
|
+
|
17
|
+
rb ="#{full_path}.rb"
|
18
|
+
return rb if FileTest.file?(rb)
|
19
|
+
|
20
|
+
return nil
|
21
|
+
end
|
22
|
+
|
23
|
+
# @param [String] feature
|
24
|
+
# @return [String|nil]
|
25
|
+
def find_file(feature, base)
|
26
|
+
# absolute path
|
27
|
+
if feature[0] == '/'
|
28
|
+
full_path = exist_file(feature)
|
29
|
+
return full_path if full_path
|
30
|
+
end
|
40
31
|
|
41
|
-
|
42
|
-
|
32
|
+
# relative path
|
33
|
+
if feature.start_with?('./') || feature.start_with?('../')
|
34
|
+
full_path = exist_file(File.expand_path("../#{feature}", base))
|
35
|
+
return full_path if full_path
|
36
|
+
end
|
43
37
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
38
|
+
$LOAD_PATH.each do |path|
|
39
|
+
full_path = exist_file(path, feature)
|
40
|
+
return full_path if full_path
|
41
|
+
end
|
48
42
|
|
49
|
-
|
50
|
-
|
43
|
+
return nil
|
44
|
+
end
|
51
45
|
|
52
|
-
|
53
|
-
|
46
|
+
# @param [String] path
|
47
|
+
# @return [Module]
|
48
|
+
def evaluate(path)
|
49
|
+
script = File.read(path)
|
54
50
|
|
55
|
-
|
56
|
-
|
57
|
-
|
51
|
+
res = Module.new
|
52
|
+
res.module_eval(script, path)
|
53
|
+
|
54
|
+
return res
|
55
|
+
end
|
56
|
+
|
57
|
+
# @param [String] feature
|
58
|
+
# @param [String] base
|
59
|
+
def import(feature, base = caller_locations[0].absolute_path)
|
60
|
+
path = find_file(feature, base)
|
61
|
+
raise LoadError, "cannot load such file -- #{feature}" unless path
|
62
|
+
|
63
|
+
return evaluate(path)
|
64
|
+
end
|
65
|
+
|
66
|
+
define_method(:global) do
|
67
|
+
module ::Kernel
|
68
|
+
def import(feature)
|
69
|
+
Import.import(feature, caller_locations[0].absolute_path)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
58
74
|
|
59
|
-
|
60
|
-
|
75
|
+
VERSION = self.import('./import/version')::VERSION
|
76
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
VERSION = '0.2.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: import.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Masataka Kuwabara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,6 +38,62 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.1.5
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.1.5
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.13.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 2.13.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-test
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 2.0.6
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 2.0.6
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.10.2
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.10.2
|
41
97
|
description: Instead of Kernel.require
|
42
98
|
email:
|
43
99
|
- p.ck.t22@gmail.com
|
@@ -46,14 +102,16 @@ extensions: []
|
|
46
102
|
extra_rdoc_files: []
|
47
103
|
files:
|
48
104
|
- ".gitignore"
|
105
|
+
- ".travis.yml"
|
49
106
|
- Gemfile
|
107
|
+
- Guardfile
|
50
108
|
- README.md
|
51
109
|
- Rakefile
|
52
110
|
- bin/console
|
53
111
|
- bin/setup
|
54
112
|
- import.rb.gemspec
|
55
113
|
- lib/import.rb
|
56
|
-
- lib/version.rb
|
114
|
+
- lib/import/version.rb
|
57
115
|
homepage: https://github.com/pocke/import.rb
|
58
116
|
licenses:
|
59
117
|
- CC0-1.0
|
data/lib/version.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
VERSION = '0.1.2'
|