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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c8efeda908f064fe724ea86726341c7050eff71
4
- data.tar.gz: 852c4de05c7976e753a46475885397af6996f5d2
3
+ metadata.gz: a6608c08d4bd4a80dd415303d2641794cfac2edc
4
+ data.tar.gz: 1c55989625bdb68f1bd9a184e3ec672a698de4fe
5
5
  SHA512:
6
- metadata.gz: 309e92fdd0dbc5cb4dffe0de68e6c1cf690fdefc18d8f4086c630f1b0303071cfd4faa44ed07cd5941accceac3f39c2b8b6c5bc1216b96203625e438fa0bd01c
7
- data.tar.gz: 33169b00d63a31fa3eb5d346834c7b4ec1980ed960e6d7f2af6bbe54dd3ce13ca29ac681354962ad96b56204532245f28b76cad4ebc9c653b3aa271540c581ba
6
+ metadata.gz: cbb17dd2f69aff5848a7e1b8bd5dc1a3800a25e21344140c89e0d399dd8b50a5df9e51b123a8a06f15d09138cf2dc1549827a56abb5c02c891d76d656b90fdd7
7
+ data.tar.gz: 9c808c2d667082bd705679cce1cc96e4b4a201a7b8177145e73822ff11f034aa42a7c7ad98912b25e7477f2b724d69c457f09cc7ef04ef4b8afeec84608aab0b
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0
4
+ - 2.1
5
+ - 2.2.3
6
+ - ruby-head
7
+
8
+ sudo: false
9
+
10
+
11
+ before_install:
12
+ - 'gem install bundler'
13
+
14
+ script:
15
+ - 'shopt -s globstar && ruby test/**/*_test.rb'
@@ -0,0 +1,12 @@
1
+ options = {
2
+ cmd: "ruby",
3
+ run_all: {
4
+ cmd: "ruby test/**/*_test.rb",
5
+ cmd_additional_args: ""
6
+ }
7
+ }
8
+
9
+ guard :test, options do
10
+ watch(%r{^test/.+_test\.rb$})
11
+ watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
12
+ end
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/import.rb.svg)](https://badge.fury.io/rb/import.rb)
2
+ [![Build Status](https://travis-ci.org/pocke/import.rb.svg?branch=master)](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)
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "import/rb"
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 "irb"
14
- IRB.start
13
+ require "pry"
14
+ binding.pry
@@ -5,7 +5,7 @@ require 'import'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "import.rb"
8
- spec.version = Kernel.import('./lib/version')::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
@@ -1,60 +1,76 @@
1
1
  require 'pathname'
2
2
 
3
- # @param [String] path Base path
4
- # @param [String] fname file name
5
- # @return [String|nil]
6
- exist_file = -> (path, fname = nil) {
7
- pn = Pathname.new(path)
8
- pn = pn.join(fname) if fname
9
-
10
- full_path = pn.to_s
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
- # relative path
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
- $LOAD_PATH.each do |path|
37
- full_path = exist_file.(path, feature)
38
- return full_path if full_path
39
- end
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
- return nil
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
- # @param [String] path
45
- # @return [Module]
46
- evaluate = -> (path) {
47
- script = File.read(path)
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
- res = Module.new
50
- res.module_eval(script, path)
43
+ return nil
44
+ end
51
45
 
52
- return res
53
- }
46
+ # @param [String] path
47
+ # @return [Module]
48
+ def evaluate(path)
49
+ script = File.read(path)
54
50
 
55
- define_method(:import, -> (feature) {
56
- path = find_file.(feature)
57
- raise LoadError, "cannot load such file -- #{feature}" unless path
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
- return evaluate.(path)
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.1.2
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-28 00:00:00.000000000 Z
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
@@ -1 +0,0 @@
1
- VERSION = '0.1.2'