autoloaded 0.0.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33eb826f0b852296da2a599fc26e5c474e05718c
4
- data.tar.gz: d1cd5c7cd96613522d93559ee959f7d6a3197a3a
3
+ metadata.gz: 87da530be678da00a0d6d8df5ef7d6ca2c773f04
4
+ data.tar.gz: a97be0b94d97e9a251cab40509e61c49e65f97e1
5
5
  SHA512:
6
- metadata.gz: 4c6050535f8b9948d416e63d8a0c9e9640eb37320b922995d6cded3e0fdba95f23494bb707bebd640f7fab079ee73ab0d3685f784a42a71731ed7eb18ff75d93
7
- data.tar.gz: 0c1bbe28aa23983de38b5aff8972a6fa184b824c2e5ac801f852561f04c3f5737562c4daddea60f26b0b0ff2ef89261b0af90d9a2236c5b906b35d20c73231b7
6
+ metadata.gz: 5ae33778e6eb8560c101c5a44f995e321b3963e96721fc22b69c55eaa69b6648d9921080e44842f7c6f9460e151376ee8bc39dda02541630a938eb9c426e2d52
7
+ data.tar.gz: c745087aa0cd848990c3c222d475559e4d27fe86c9f86eeffd50941df790d75dfd15dd0cb15b2b91a4270d5112bd5cae32de78024a27f9c0af9d9ced11609cbb
data/.gitignore CHANGED
@@ -11,4 +11,6 @@
11
11
  *.so
12
12
  *.o
13
13
  *.a
14
+ .ruby-gemset
15
+ .ruby-version
14
16
  mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ bundler_args: --without debug doc tooling
3
+ rvm:
4
+ - 2.0
5
+ - 2.1.0
6
+ - ruby-head
7
+ - jruby-head
8
+ script: "bundle exec rake test"
9
+ matrix:
10
+ allow_failures:
11
+ - rvm: ruby-head
12
+ - rvm: jruby-head
data/Gemfile CHANGED
@@ -3,18 +3,22 @@ source 'https://rubygems.org'
3
3
  gemspec
4
4
 
5
5
  group :debug do
6
- gem 'pry-byebug', '~> 2', platforms: [:mri_20, :mri_21]
7
- gem 'pry-debugger', '~> 0', platforms: :mri_19
6
+ gem 'pry-byebug', '~> 2', platforms: [:mri_20, :mri_21]
7
+ gem 'pry-debugger', '~> 0', platforms: :mri_19
8
8
  end
9
9
 
10
10
  group :doc do
11
- gem 'yard', '~> 0', require: false
12
- gem 'rdiscount', '~> 2', require: false
11
+ gem 'yard', '~> 0', require: false
12
+ gem 'rdiscount', '~> 2', require: false
13
+ end
14
+
15
+ group :test do
16
+ gem 'codeclimate-test-reporter', '~> 0', require: false
13
17
  end
14
18
 
15
19
  group :tooling do
16
- gem 'guard-rspec', '~> 4', require: false
20
+ gem 'guard-rspec', '~> 4', require: false
17
21
  if RUBY_PLATFORM =~ /darwin/i
18
- gem 'rb-fsevent', '~> 0', require: false
22
+ gem 'rb-fsevent', '~> 0', require: false
19
23
  end
20
24
  end
data/Guardfile CHANGED
@@ -22,7 +22,10 @@ guard :rspec, all_after_pass: true,
22
22
  # Run all specs when a matcher changes.
23
23
  watch( 'spec/matchers.rb' ) { 'spec' }
24
24
 
25
- # Run all when a fixture changes.
25
+ # Run all specs when a support file changes.
26
+ watch( %r{^spec/support} ) { 'spec' }
27
+
28
+ # Run all specs when a fixture changes.
26
29
  watch( %r{^spec/fixtures} ) { 'spec' }
27
30
 
28
31
  # Run all specs when the RSpec configuration changes.
data/History.markdown ADDED
@@ -0,0 +1,9 @@
1
+ # Version history for the _Autoloaded_ project
2
+
3
+ ## <a name="v1.0.0"></a>v1.0.0, Wed 10/29/2013
4
+
5
+ * Add support for Ruby v2.0
6
+
7
+ ## <a name="v0.0.3"></a>v0.0.3, Fri 10/24/2014
8
+
9
+ (First release)
data/License.md CHANGED
@@ -1,8 +1,7 @@
1
- # The MIT License
1
+ # The MIT License
2
2
 
3
- Source code for _Autoloaded_ is Copyright © 2014
4
- [Nils Jonsson](mailto:autoloaded@nilsjonsson.com) and
5
- [contributors](https://github.com/njonsson/autoloaded/contributors "Autoloaded contributors at GitHub").
3
+ Source code for _Autoloaded_ is Copyright © 2014 [Nils Jonsson][mail] and
4
+ [contributors][contributors].
6
5
 
7
6
  Permission is hereby granted, free of charge, to any person obtaining a copy of
8
7
  this software and associated documentation files (the “Software”), to deal in the
@@ -20,3 +19,6 @@ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
20
19
  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21
20
  AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
21
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ [mail]: mailto:autoloaded@nilsjonsson.com "send email to Nils Jonsson"
24
+ [contributors]: https://github.com/njonsson/autoloaded/contributors "Autoloaded contributors at GitHub"
data/README.md CHANGED
@@ -1,12 +1,19 @@
1
+ [![Autoloaded graphic]][spider-gear-image]
2
+
1
3
  # Autoloaded
2
4
 
5
+ [![Travis CI build status] ][Travis-CI-build-status]
6
+ [![Code Climate quality report] ][Code-Climate-report]
7
+ [![Code Climate coverage report]][Code-Climate-report]
8
+ [![Gemnasium build status] ][Gemnasium-build-status]
9
+ [![Inch CI build status] ][Inch-CI-build-status]
10
+ [![RubyGems release] ][RubyGems-release]
11
+
3
12
  _Autoloaded_ dynamically and flexibly loads source files in a directory when a
4
13
  corresponding constant is dereferenced. It offers several advantages over other
5
14
  autoloading facilities such as those provided by the
6
- [Ruby Core library](http://ruby-doc.org/core/Module.html#method-i-autoload) and
7
- the
8
- [ActiveSupport](http://api.rubyonrails.org/classes/ActiveSupport/Autoload.html)
9
- gem:
15
+ [Ruby Core library][Ruby-Core-Module-autoload] and the
16
+ [ActiveSupport][ActiveSupport-Autoload] gem:
10
17
 
11
18
  * It does not require a separate `autoload` statement for each constant
12
19
  * It does not enforce `CamelCase` to `snake_case` correspondence between the
@@ -106,8 +113,32 @@ end
106
113
 
107
114
  ## Contributing
108
115
 
109
- 1. [Fork the official repository](https://github.com/njonsson/autoloaded/fork).
116
+ 1. [Fork][fork-Autoloaded] the official repository.
110
117
  2. Create your feature branch: `git checkout -b my-new-feature`.
111
118
  3. Commit your changes: `git commit -am 'Add some feature'`.
112
119
  4. Push to the branch: `git push origin my-new-feature`.
113
- 5. Create a [new pull request](https://github.com/njonsson/autoloaded/compare).
120
+ 5. [Create][compare-Autoloaded-branches] a new pull request.
121
+
122
+ ## License
123
+
124
+ Released under the [MIT License][MIT-License].
125
+
126
+ [Autoloaded graphic]: https://farm5.staticflickr.com/4134/4941065976_54737fe145.jpg
127
+ [Travis CI build status]: https://secure.travis-ci.org/njonsson/autoloaded.svg?branch=master
128
+ [Code Climate quality report]: https://codeclimate.com/github/njonsson/autoloaded/badges/gpa.svg
129
+ [Code Climate coverage report]: https://codeclimate.com/github/njonsson/autoloaded/badges/coverage.svg
130
+ [Gemnasium build status]: https://gemnasium.com/njonsson/autoloaded.svg
131
+ [Inch CI build status]: http://inch-ci.org/github/njonsson/autoloaded.svg?branch=master
132
+ [RubyGems release]: https://badge.fury.io/rb/autoloaded.svg
133
+
134
+ [spider-gear-image]: https://www.flickr.com/photos/dongkwan/4941065976 "spider gear image by Ernesto Andrade"
135
+ [Travis-CI-build-status]: http://travis-ci.org/njonsson/autoloaded "Travis CI build status for Autoloaded"
136
+ [Code-Climate-report]: http://codeclimate.com/github/njonsson/autoloaded "Code Climate report for Autoloaded"
137
+ [Gemnasium-build-status]: http://gemnasium.com/njonsson/autoloaded "Gemnasium build status for Autoloaded"
138
+ [Inch-CI-build-status]: http://inch-ci.org/github/njonsson/autoloaded "Inch CI build status for Autoloaded"
139
+ [RubyGems-release]: http://rubygems.org/gems/autoloaded "RubyGems release of Autoloaded"
140
+ [Ruby-Core-Module-autoload]: http://ruby-doc.org/core/Module.html#method-i-autoload "‘Module#autoload’ method in the Ruby Core Library"
141
+ [ActiveSupport-Autoload]: http://api.rubyonrails.org/classes/ActiveSupport/Autoload.html "‘ActiveSupport::Autoload’ module in the Rails API"
142
+ [fork-Autoloaded]: https://github.com/njonsson/autoloaded/fork "Fork the official repository of Autoloaded"
143
+ [compare-Autoloaded-branches]: https://github.com/njonsson/autoloaded/compare "Compare branches of Autoloaded repositories"
144
+ [MIT-License]: http://github.com/njonsson/autoloaded/blob/master/License.md "MIT License claim for Autoloaded"
data/Rakefile CHANGED
@@ -1,2 +1,2 @@
1
1
  require 'bundler/gem_tasks'
2
-
2
+ require_relative 'lib/tasks'
data/autoloaded.gemspec CHANGED
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
33
33
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
34
34
  spec.require_paths = ['lib']
35
35
 
36
- spec.required_ruby_version = '~> 2.1'
36
+ spec.required_ruby_version = '~> 2'
37
37
 
38
38
  spec.add_development_dependency 'bundler', '~> 1'
39
39
  spec.add_development_dependency 'rake', '~> 10'
@@ -10,26 +10,16 @@ class Autoloaded::Constant
10
10
  attr_reader :name
11
11
 
12
12
  def initialize(name)
13
- @name = name
13
+ @name = name.freeze
14
14
  end
15
15
 
16
- def each_matching_filename_in(directory)
16
+ def each_matching_filename_in(directory, &block)
17
17
  filenames = ::Set.new
18
18
 
19
- ::Dir.chdir directory do
20
- filename = [name.to_s.to_source_filename, extension].join
21
- if ::File.file?(filename) && filenames.add?(filename)
22
- yield ::File.join(directory, filename)
23
- end
24
-
25
- name_signature = signature(name)
26
- ::Dir.glob(['*', extension].join, ::File::FNM_CASEFOLD) do |f|
27
- f_signature = signature(::File.basename(f, extension))
28
- if (f_signature == name_signature) && filenames.add?(f)
29
- yield ::File.join(directory, f)
30
- end
31
- end
32
- end
19
+ yield_qualified_name_source_filename_in(directory,
20
+ unless_in: filenames,
21
+ &block)
22
+ yield_all_qualified_filenames_in(directory, unless_in: filenames, &block)
33
23
  end
34
24
 
35
25
  private
@@ -38,8 +28,43 @@ private
38
28
  '.rb'
39
29
  end
40
30
 
31
+ def name_signature
32
+ @name_signature ||= signature(name)
33
+ end
34
+
35
+ def name_source_filename
36
+ @name_source_filename ||= [name.to_s.to_source_filename, extension].join
37
+ end
38
+
39
+ def qualified_glob_in(directory)
40
+ ::File.join(directory, ['*', extension].join)
41
+ end
42
+
41
43
  def signature(string)
42
44
  string.to_s.gsub(/[^a-z0-9]/i, '').downcase
43
45
  end
44
46
 
47
+ def yield_all_qualified_filenames_in(directory, unless_in: nil, &block)
48
+ unless unless_in
49
+ raise ::ArgumentError, "missing keyword: unless_in"
50
+ end
51
+ ::Dir.glob(qualified_glob_in(directory), ::File::FNM_CASEFOLD) do |filename|
52
+ filename_signature = signature(::File.basename(filename, extension))
53
+ if (filename_signature == name_signature) &&
54
+ unless_in.add?(::File.basename(filename))
55
+ block.call filename
56
+ end
57
+ end
58
+ end
59
+
60
+ def yield_qualified_name_source_filename_in(directory, unless_in: nil, &block)
61
+ unless unless_in
62
+ raise ::ArgumentError, "missing keyword: unless_in"
63
+ end
64
+ qualified = ::File.join(directory, name_source_filename)
65
+ if ::File.file?(qualified) && unless_in.add?(name_source_filename)
66
+ block.call qualified
67
+ end
68
+ end
69
+
45
70
  end
@@ -1,5 +1,5 @@
1
1
  module Autoloaded
2
2
 
3
- VERSION = '0.0.3'
3
+ VERSION = '1.0.0'
4
4
 
5
5
  end
data/lib/tasks.rb ADDED
@@ -0,0 +1,3 @@
1
+ Dir.glob "#{File.dirname __FILE__}/#{File.basename __FILE__, '.rb'}/*.rake" do |f|
2
+ load f
3
+ end
@@ -0,0 +1,8 @@
1
+ begin
2
+ require 'yard'
3
+ rescue LoadError
4
+ else
5
+ namespace :build do
6
+ YARD::Rake::YardocTask.new :doc
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ namespace :lib do
2
+ desc "Load each library file individually, looking for missing 'require' statements"
3
+ task :each do
4
+ Dir.chdir 'lib' do
5
+ Dir.glob( '**/*.rb' ) do |f|
6
+ next if f == 'tasks.rb'
7
+
8
+ puts "Loading #{f} ..."
9
+ fail unless system( "/usr/bin/env bundle exec ruby -e 'require #{f.inspect}'" )
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,70 @@
1
+ begin
2
+ require 'rspec/core/rake_task'
3
+ rescue LoadError
4
+ else
5
+ def define_spec_task(name, options={})
6
+ desc options[:desc]
7
+ begin
8
+ require 'rspec/core/rake_task'
9
+ rescue LoadError
10
+ else
11
+ RSpec::Core::RakeTask.new name do |t|
12
+ t.rspec_opts ||= []
13
+ t.rspec_opts << "--backtrace" if options[:backtrace]
14
+
15
+ debugger_gem = %w(pry-byebug pry-debugger).detect do |gem|
16
+ `bundle show #{gem} 2>&1 >/dev/null`
17
+ $?.success?
18
+ end
19
+ if debugger_gem && options[:debug] != false
20
+ t.rspec_opts << "--require #{debugger_gem}"
21
+ end
22
+
23
+ t.rspec_opts << "--format #{options[:format]}" if options.key?(:format)
24
+ t.rspec_opts << '--no-profile' if options[:profile] == false
25
+ t.rspec_opts << '--warnings' if options[:warnings]
26
+ t.pattern = options[:pattern] || %w(spec/*_spec.rb spec/**/*_spec.rb)
27
+ end
28
+ end
29
+ end
30
+
31
+ define_spec_task :spec, desc: 'Run specs', profile: true
32
+
33
+ namespace :spec do
34
+ uncommitted_files_in_spec = `git ls-files --modified --others spec/* spec/**/*`.split("\n")
35
+ uncommitted_spec_files = `git ls-files --modified --others spec/*_spec.rb spec/**/*_spec.rb`.split("\n")
36
+ nonspec_uncommitted_files_in_spec = uncommitted_files_in_spec -
37
+ uncommitted_spec_files
38
+ if nonspec_uncommitted_files_in_spec.empty?
39
+ if uncommitted_spec_files.empty?
40
+ desc 'Run uncommitted specs (none)'
41
+ task :uncommitted do
42
+ puts 'No uncommitted specs to run'
43
+ end
44
+ else
45
+ noun_phrase = "#{uncommitted_spec_files.length} uncommitted spec file#{(uncommitted_spec_files.length == 1) ? nil : 's'}"
46
+ desc = "Run #{noun_phrase}"
47
+ define_spec_task :uncommitted, desc: desc, pattern: uncommitted_spec_files
48
+ end
49
+ else
50
+ noun_phrase = "#{uncommitted_files_in_spec.length} uncommitted file#{uncommitted_files_in_spec.length == 1 ? nil : 's'}"
51
+ desc = "Run all specs because of #{noun_phrase} in 'spec'"
52
+ define_spec_task :uncommitted, desc: desc, pattern: 'spec'
53
+ end
54
+
55
+ define_spec_task :warnings, desc: 'Run specs with Ruby warnings enabled',
56
+ format: :progress,
57
+ profile: false,
58
+ warnings: true
59
+ end
60
+
61
+ desc 'Run specs'
62
+ task '' => :spec
63
+ task :default => :spec
64
+
65
+ # Support the 'gem test' command.
66
+ define_spec_task :test, desc: '', backtrace: true,
67
+ debug: false,
68
+ format: :progress,
69
+ profile: false
70
+ end
@@ -0,0 +1,19 @@
1
+ begin
2
+ require 'rspec/core/rake_task'
3
+ rescue LoadError
4
+ else
5
+ namespace :spec do
6
+ desc "Run each spec individually, looking for missing 'require' statements"
7
+ task :each do
8
+ add_separator = false
9
+ Dir.glob( 'spec/**/*_spec.rb' ) do |f|
10
+ puts '-' * `tput cols`.chomp.to_i if add_separator
11
+ add_separator = true
12
+ puts "Running #{f} ..."
13
+ unless system( "/usr/bin/env bundle exec rspec --format=progress --no-profile #{f.inspect}" )
14
+ fail
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -6,11 +6,11 @@ RSpec.describe Autoloaded::Constant do
6
6
  describe 'for' do
7
7
  let(:directory) { 'spec/fixtures/filenames' }
8
8
 
9
- {AFilename: %w(a_filename a-file-name a-filename a_file_name AFilename),
10
- A_FILENAME: %w(a_filename a-file-name a-filename a_file_name AFilename),
11
- AFileName: %w(a_file_name a-file-name a-filename a_filename AFilename),
12
- AFILEName: %w(a-file-name a-filename a_file_name a_filename AFilename)}.each do |constant_name,
13
- filenames|
9
+ {AFilename: %w(a_filename a-file-name a-filename a_file_name afile_name afile-name AFilename),
10
+ A_FILENAME: %w(a_filename a-file-name a-filename a_file_name afile_name afile-name AFilename),
11
+ AFileName: %w(a_file_name a-file-name a-filename a_filename afile_name afile-name AFilename),
12
+ AFILEName: %w(afile_name a-file-name a-filename a_file_name a_filename afile-name AFilename)}.each do |constant_name,
13
+ filenames|
14
14
  describe constant_name.inspect do
15
15
  let(:constant) { constant_class.new constant_name }
16
16
 
@@ -21,11 +21,25 @@ RSpec.describe Autoloaded::Constant do
21
21
  }
22
22
 
23
23
  describe '#each_matching_filename_in' do
24
- specify {
25
- expect { |block|
26
- constant.each_matching_filename_in(directory, &block)
27
- }.to yield_successive_args(*full_filenames)
24
+ let(:yielded_args) {
25
+ result = []
26
+ constant.each_matching_filename_in directory do |filename|
27
+ result << filename
28
+ end
29
+ result
28
30
  }
31
+
32
+ describe 'first yielded argument' do
33
+ subject(:first_yielded_argument) { yielded_args.first }
34
+
35
+ it { is_expected.to eq(full_filenames.first) }
36
+ end
37
+
38
+ describe 'subsequent yielded arguments' do
39
+ subject(:subsequent_yielded_arguments) { yielded_args[1..-1] }
40
+
41
+ it { is_expected.to match_array(full_filenames[1..-1]) }
42
+ end
29
43
  end
30
44
  end
31
45
  end
@@ -2,15 +2,20 @@ require 'autoloaded'
2
2
  require 'matchers'
3
3
 
4
4
  RSpec.describe Autoloaded do
5
- describe 'not included in a namespace' do
5
+ describe 'not extending a namespace' do
6
6
  let(:source_file) { 'spec/fixtures/namespace_that_is_not_autoloaded.rb' }
7
7
 
8
8
  specify('does not dynamically define a nested constant') {
9
9
  expect(source_file).not_to autoload_a_constant_named('NamespaceThatIsNotAutoloaded::Nested')
10
10
  }
11
+
12
+ specify('does not pollute the namespace') {
13
+ expect(source_file).to define_only_constants_named().
14
+ in_a_namespace_named(:NamespaceThatIsNotAutoloaded)
15
+ }
11
16
  end
12
17
 
13
- describe 'included in a namespace' do
18
+ describe 'extending a namespace' do
14
19
  describe 'whose source files have conventional names' do
15
20
  let(:source_file) {
16
21
  'spec/fixtures/namespace_that_is_autoloaded_conventionally.rb'
File without changes
File without changes
@@ -1 +0,0 @@
1
- raise "The file #{__FILE__} should not have been loaded"
data/spec/matchers.rb CHANGED
@@ -1,41 +1,31 @@
1
- require 'open3'
1
+ require 'support/without_side_effects'
2
2
 
3
3
  RSpec::Matchers.define :autoload_a_constant_named do |constant_name|
4
4
  match do |source_file|
5
5
  # Ensure the file exists.
6
- File.read source_file
6
+ File.open source_file, 'r' do
7
+ end
7
8
 
8
9
  constant_tokens = constant_name.split('::')
9
10
  constant_up_till_last = constant_tokens[0...-1].join('::')
10
11
  constant_last = constant_tokens.last
11
- assertion = <<-end_assertion.gsub(/^ /, '')
12
- begin;
13
- #{constant_name};
14
- rescue;
15
- else;
16
- raise('Constant #{constant_name} is already defined');
17
- end;
18
12
 
19
- load #{source_file.inspect};
13
+ without_side_effects do
14
+ begin
15
+ eval constant_name.to_s
16
+ rescue NameError
17
+ else
18
+ raise("#{constant_name} is already defined")
19
+ end
20
20
 
21
- puts(begin;
22
- #{constant_name};
23
- rescue;
24
- 'false';
25
- else;
26
- #{constant_up_till_last}.autoload?(:#{constant_last}) ?
27
- 'true' :
28
- 'false';
29
- end)
30
- end_assertion
31
- quoted_assertion = assertion.chomp.inspect.gsub('\n', "\n")
32
- Open3.popen3 "bundle exec ruby -e #{quoted_assertion}" do |stdin,
33
- stdout,
34
- stderr|
35
- if (stderr_output = stderr.read.chomp).empty?
36
- eval stdout.read.chomp
21
+ load source_file
22
+
23
+ begin
24
+ eval constant_name.to_s
25
+ rescue NameError
26
+ false
37
27
  else
38
- raise stderr_output
28
+ eval(constant_up_till_last).autoload? constant_last.to_sym
39
29
  end
40
30
  end
41
31
  end
@@ -45,38 +35,31 @@ RSpec::Matchers.define :define_only_constants_named do |*constant_names|
45
35
  attr_reader :expected_constants, :extraneous_defined_constants, :namespace_name
46
36
 
47
37
  match do |source_file|
38
+ @expected_constants, @extraneous_defined_constants = [], []
39
+
48
40
  # Ensure the file exists.
49
- File.read source_file
41
+ File.open source_file, 'r' do
42
+ end
50
43
 
51
44
  unless namespace_name
52
- raise "Missing .in_a_namespace_named(:Namespace) clause"
45
+ raise "missing .in_a_namespace_named(:Namespace) clause"
53
46
  end
54
47
 
55
- assertion = <<-end_assertion.gsub(/^ /, '')
56
- load #{source_file.inspect};
48
+ defined_constants = without_side_effects do
49
+ load source_file
57
50
 
58
- puts(begin;
59
- #{constant_names.inspect}.each do |constant_name|
60
- #{namespace_name}.const_get constant_name;
61
- end;
62
- #{namespace_name}.constants.inspect;
63
- rescue;
64
- '[]';
65
- end)
66
- end_assertion
67
- quoted_assertion = assertion.chomp.inspect.gsub('\n', "\n")
68
- Open3.popen3 "bundle exec ruby -e #{quoted_assertion}" do |stdin,
69
- stdout,
70
- stderr|
71
- if (stderr_output = stderr.read.chomp).empty?
72
- defined_constants = Array(eval(stdout.read.chomp)).sort.collect(&:to_sym)
73
- @expected_constants = constant_names.sort.collect(&:to_sym)
74
- @extraneous_defined_constants = defined_constants - expected_constants
75
- extraneous_defined_constants.empty?
76
- else
77
- raise stderr_output
51
+ namespace = eval(namespace_name.to_s)
52
+
53
+ # Trigger autoloading.
54
+ constant_names.each do |constant_name|
55
+ namespace.const_get constant_name
78
56
  end
57
+
58
+ namespace.constants.sort.collect(&:to_sym)
79
59
  end
60
+ @expected_constants = constant_names.sort.collect(&:to_sym)
61
+ @extraneous_defined_constants = defined_constants - expected_constants
62
+ extraneous_defined_constants.empty?
80
63
  end
81
64
 
82
65
  chain :in_a_namespace_named do |namespace_name|
data/spec/spec_helper.rb CHANGED
@@ -1,3 +1,7 @@
1
+ require 'codeclimate-test-reporter'
2
+
3
+ CodeClimate::TestReporter.start
4
+
1
5
  # This file was generated by the `rspec --init` command. Conventionally, all
2
6
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
7
  # The generated `.rspec` file contains `--require spec_helper` which will cause this
@@ -0,0 +1,31 @@
1
+ def without_side_effects
2
+ return nil unless block_given?
3
+
4
+ out_reader, out_writer = IO.pipe.collect { |io| io.tap(&:binmode) }
5
+ err_reader, err_writer = IO.pipe.collect { |io| io.tap(&:binmode) }
6
+
7
+ pid = fork do
8
+ out_reader.close
9
+ err_reader.close
10
+
11
+ begin
12
+ out_writer.write Marshal.dump(yield)
13
+ rescue => e
14
+ clean_backtrace = e.backtrace.reject do |frame|
15
+ frame.include? __FILE__
16
+ end
17
+ e.set_backtrace clean_backtrace
18
+ err_writer.write Marshal.dump(e)
19
+ raise e
20
+ end
21
+ end
22
+
23
+ Process.wait pid
24
+
25
+ out_writer.close
26
+ err_writer.close
27
+
28
+ return Marshal.load(out_reader.read) if $?.success?
29
+
30
+ raise Marshal.load(err_reader.read)
31
+ end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autoloaded
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nils Jonsson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-24 00:00:00.000000000 Z
11
+ date: 2014-10-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1'
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
26
  version: '1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3'
55
55
  description: 'Dynamically and flexibly loads source files in a directory when a corresponding
@@ -64,13 +64,13 @@ executables: []
64
64
  extensions: []
65
65
  extra_rdoc_files: []
66
66
  files:
67
- - .gitignore
68
- - .rspec
69
- - .ruby-gemset
70
- - .ruby-version
71
- - .yardopts
67
+ - ".gitignore"
68
+ - ".rspec"
69
+ - ".travis.yml"
70
+ - ".yardopts"
72
71
  - Gemfile
73
72
  - Guardfile
73
+ - History.markdown
74
74
  - License.md
75
75
  - README.md
76
76
  - Rakefile
@@ -81,15 +81,22 @@ files:
81
81
  - lib/autoloaded/refine/string.rb
82
82
  - lib/autoloaded/refine/string/to_source_filename.rb
83
83
  - lib/autoloaded/version.rb
84
+ - lib/tasks.rb
85
+ - lib/tasks/build_doc.rake
86
+ - lib/tasks/lib_each.rake
87
+ - lib/tasks/spec.rake
88
+ - lib/tasks/spec_each.rake
84
89
  - spec/autoloaded/constant_spec.rb
85
90
  - spec/autoloaded/refine/string/to_source_filename_spec.rb
86
- - spec/autoloaded/shallow_spec.rb
87
91
  - spec/autoloaded/version_spec.rb
92
+ - spec/autoloaded_spec.rb
88
93
  - spec/fixtures/filenames/AFilename.rb
89
94
  - spec/fixtures/filenames/a-file-name.rb
90
95
  - spec/fixtures/filenames/a-filename.rb
91
96
  - spec/fixtures/filenames/a_file_name.rb
92
97
  - spec/fixtures/filenames/a_filename.rb
98
+ - spec/fixtures/filenames/afile-name.rb
99
+ - spec/fixtures/filenames/afile_name.rb
93
100
  - spec/fixtures/namespace_that_is_autoloaded_conventionally.rb
94
101
  - spec/fixtures/namespace_that_is_autoloaded_conventionally/N-est-ed.rb
95
102
  - spec/fixtures/namespace_that_is_autoloaded_conventionally/nest_ed.rb
@@ -101,6 +108,7 @@ files:
101
108
  - spec/fixtures/namespace_that_is_not_autoloaded/nested.rb
102
109
  - spec/matchers.rb
103
110
  - spec/spec_helper.rb
111
+ - spec/support/without_side_effects.rb
104
112
  homepage: https://github.com/njonsson/autoloaded
105
113
  licenses:
106
114
  - MIT
@@ -111,12 +119,12 @@ require_paths:
111
119
  - lib
112
120
  required_ruby_version: !ruby/object:Gem::Requirement
113
121
  requirements:
114
- - - ~>
122
+ - - "~>"
115
123
  - !ruby/object:Gem::Version
116
- version: '2.1'
124
+ version: '2'
117
125
  required_rubygems_version: !ruby/object:Gem::Requirement
118
126
  requirements:
119
- - - '>='
127
+ - - ">="
120
128
  - !ruby/object:Gem::Version
121
129
  version: '0'
122
130
  requirements: []
@@ -129,13 +137,15 @@ summary: Dynamically and flexibly loads source files in a directory when a corre
129
137
  test_files:
130
138
  - spec/autoloaded/constant_spec.rb
131
139
  - spec/autoloaded/refine/string/to_source_filename_spec.rb
132
- - spec/autoloaded/shallow_spec.rb
133
140
  - spec/autoloaded/version_spec.rb
141
+ - spec/autoloaded_spec.rb
134
142
  - spec/fixtures/filenames/AFilename.rb
135
143
  - spec/fixtures/filenames/a-file-name.rb
136
144
  - spec/fixtures/filenames/a-filename.rb
137
145
  - spec/fixtures/filenames/a_file_name.rb
138
146
  - spec/fixtures/filenames/a_filename.rb
147
+ - spec/fixtures/filenames/afile-name.rb
148
+ - spec/fixtures/filenames/afile_name.rb
139
149
  - spec/fixtures/namespace_that_is_autoloaded_conventionally.rb
140
150
  - spec/fixtures/namespace_that_is_autoloaded_conventionally/N-est-ed.rb
141
151
  - spec/fixtures/namespace_that_is_autoloaded_conventionally/nest_ed.rb
@@ -147,4 +157,5 @@ test_files:
147
157
  - spec/fixtures/namespace_that_is_not_autoloaded/nested.rb
148
158
  - spec/matchers.rb
149
159
  - spec/spec_helper.rb
160
+ - spec/support/without_side_effects.rb
150
161
  has_rdoc:
data/.ruby-gemset DELETED
@@ -1 +0,0 @@
1
- autoloaded
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 2.1.2