requirable 0.0.3

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 57506ebb8d735bacc267b4e70f8470ca673409bb
4
+ data.tar.gz: 0a30e9c0844094fb34a958947686dac5d4d76056
5
+ SHA512:
6
+ metadata.gz: f7dded6457717f6367339cdad96d20fcf1088b06e287b9894cb41b225d3a08a155eab10151d810415dcfe3761f6450e0d1b5988608fd9885da612b3d92544fa6
7
+ data.tar.gz: 8a8da08fe12e9cf32b7e495e28dd9f7f9fe2c7b956367dd5789c0e5a7f54c57de6bdf365cb793802723ec992cfda39b8c768fa38ef1eabddfb5c4054f5837df5
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .ruby-version
19
+ .ruby-gemset
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in requirable.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 joaquimadraz
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,55 @@
1
+ # Requirable
2
+
3
+ File require logic extracted from Padrino's gem.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'requirable'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install requirable
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ |-- app
23
+ | |-- models
24
+ | | |-- user.rb
25
+ | |-- routes
26
+ | | |-- home.rb
27
+ | | |-- users.rb
28
+ | | |-- items.rb
29
+ |-- config
30
+ | |-- configs.rb
31
+ | |-- env.rb
32
+ |-- app.rb
33
+ |-- boot.rb
34
+ ```
35
+
36
+ Let's say this is your root, you can use Requirable to load all your files:
37
+
38
+ ```ruby
39
+ Requirable.load! 'config', 'app'
40
+ ```
41
+
42
+ Or just tell which folders and files you want to require:
43
+
44
+ ```ruby
45
+ Requirable.load "./config/*.rb"
46
+ Requirable.load "./app/**{,/*/**}/*.rb"
47
+ ```
48
+
49
+ ## Contributing
50
+
51
+ 1. Fork it ( http://github.com/joaquimadraz/requirable/fork )
52
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
53
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
54
+ 4. Push to the branch (`git push origin my-new-feature`)
55
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,77 @@
1
+ require 'requirable/version'
2
+
3
+ module Requirable
4
+
5
+ def load(paths)
6
+ current_file = nil
7
+
8
+ files = [*paths].flatten.map { |path| dir_list(path) }.flatten.uniq
9
+
10
+ until files.empty?
11
+ last_file_counter = files.length
12
+
13
+ fatal, error = nil, nil
14
+
15
+ files.dup.each do |file|
16
+ current_file = figure_path(file)
17
+
18
+ begin
19
+ require figure_path(file)
20
+
21
+ files.delete(file)
22
+ rescue NameError, LoadError => error
23
+ # puts "Cyclic dependency reload for #{error.class}: #{error.message} on file: #{file}"
24
+ rescue Exception => fatal
25
+ break
26
+ end
27
+ end
28
+
29
+ if fatal
30
+ exception = fatal || error
31
+
32
+ puts "Requirable::32 raised and exception: #{fatal}"
33
+
34
+ raise exception
35
+ end
36
+
37
+ if last_file_counter == files.length && error
38
+ split = current_file.split('/')
39
+ current_file_name = split[-1]
40
+ current_file_dir = split[0..-2].join('/')
41
+
42
+ raise %Q{
43
+ An error occurred while loading #{current_file}
44
+ Error:
45
+ #{error}
46
+ Possible problems:
47
+ - Syntax error on #{current_file_name}
48
+ - LOAD_PATH does not have app ROOT_PATH so it can find #{current_file_name} inside #{current_file_dir}
49
+ }
50
+ end
51
+ end
52
+ end
53
+
54
+ def load!(*folder_names)
55
+ folder_names.each do |name|
56
+ Requirable.load(["./#{name}/**{,/*/**}/*.rb"])
57
+ end
58
+ end
59
+
60
+ def figure_path(file)
61
+ return file if Pathname.new(file).absolute?
62
+
63
+ $LOAD_PATH.each do |path|
64
+ found = File.join(path, file)
65
+ return File.expand_path(found) if File.file?(found)
66
+ end
67
+
68
+ file
69
+ end
70
+
71
+ def dir_list(path)
72
+ Dir.glob(path).sort_by { |filename| filename.count('/') }
73
+ end
74
+
75
+ extend self
76
+
77
+ end
@@ -0,0 +1,3 @@
1
+ module Requirable
2
+ VERSION = '0.0.3'
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'requirable/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "requirable"
8
+ spec.version = Requirable::VERSION
9
+ spec.authors = ["joaquimadraz"]
10
+ spec.email = ["joaquim.adraz@gmail.com"]
11
+ spec.summary = %q{Require ruby code}
12
+ spec.description = %q{Based on padrino's ruby require code}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,80 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: requirable
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - joaquimadraz
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-05 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: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
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
+ description: Based on padrino's ruby require code
42
+ email:
43
+ - joaquim.adraz@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/requirable.rb
54
+ - lib/requirable/version.rb
55
+ - requirable.gemspec
56
+ homepage: ''
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.4.5
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Require ruby code
80
+ test_files: []