autoloaded 1.7.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +8 -4
  3. data/.rspec +1 -1
  4. data/.travis.yml +1 -15
  5. data/Gemfile +10 -11
  6. data/Guardfile +22 -21
  7. data/History.md +16 -40
  8. data/License.md +1 -1
  9. data/README.md +69 -79
  10. data/Rakefile +0 -4
  11. data/autoloaded.gemspec +37 -41
  12. data/lib/autoloaded/autoloader.rb +8 -31
  13. data/lib/autoloaded/deprecation.rb +20 -11
  14. data/lib/autoloaded/inflection.rb +9 -7
  15. data/lib/autoloaded/load_pathed_directory.rb +4 -2
  16. data/lib/autoloaded/specification.rb +0 -2
  17. data/lib/autoloaded/specifications.rb +10 -16
  18. data/lib/autoloaded/version.rb +1 -1
  19. data/lib/autoloaded/warning.rb +44 -26
  20. data/lib/autoloaded.rb +0 -40
  21. data/lib/tasks/lib_each.rake +3 -15
  22. data/lib/tasks/spec.rake +6 -3
  23. data/spec/autoloaded/autoloader_spec.rb +469 -0
  24. data/spec/autoloaded/inflection_spec.rb +30 -0
  25. data/spec/autoloaded/load_pathed_directory_spec.rb +120 -0
  26. data/spec/autoloaded/specification_spec.rb +98 -0
  27. data/spec/autoloaded/specifications_spec.rb +191 -0
  28. data/spec/autoloaded/version_spec.rb +3 -0
  29. data/spec/autoloaded/warning_spec.rb +115 -0
  30. data/spec/autoloaded_macro_sharedspec.rb +24 -0
  31. data/spec/autoloaded_spec.rb +173 -0
  32. data/spec/fixtures/autoloaded_with_conventional_filename/N-est-ed.rb +1 -0
  33. data/spec/fixtures/autoloaded_with_conventional_filename/nest_ed.rb +1 -0
  34. data/spec/fixtures/autoloaded_with_conventional_filename/nested/doubly_nested.rb +9 -0
  35. data/spec/fixtures/autoloaded_with_conventional_filename/nested.rb +16 -0
  36. data/spec/fixtures/autoloaded_with_conventional_filename/old_school_autoload.rb +5 -0
  37. data/spec/fixtures/autoloaded_with_conventional_filename.rb +12 -0
  38. data/spec/fixtures/autoloaded_with_unconventional_filename/N-est-ed.rb +7 -0
  39. data/spec/fixtures/autoloaded_with_unconventional_filename/nest_ed.rb +1 -0
  40. data/spec/fixtures/autoloaded_with_unconventional_filename/old_school_autoload.rb +5 -0
  41. data/spec/fixtures/autoloaded_with_unconventional_filename.rb +12 -0
  42. data/spec/fixtures/filenames/AFilename.rb +0 -0
  43. data/spec/fixtures/filenames/a-file-name.rb +0 -0
  44. data/spec/fixtures/filenames/a-filename.rb +0 -0
  45. data/spec/fixtures/filenames/a_file_name.rb +0 -0
  46. data/spec/fixtures/filenames/a_filename.rb +0 -0
  47. data/spec/fixtures/filenames/afile-name.rb +0 -0
  48. data/spec/fixtures/filenames/afile_name.rb +0 -0
  49. data/spec/fixtures/not_autoloaded/nested.rb +1 -0
  50. data/spec/fixtures/not_autoloaded/old_school_autoload.rb +5 -0
  51. data/spec/fixtures/not_autoloaded.rb +5 -0
  52. data/spec/matchers.rb +85 -0
  53. data/spec/spec_helper.rb +91 -0
  54. data/spec/support/util.rb +42 -0
  55. data/spec/support/without_side_effects.rb +37 -0
  56. metadata +86 -25
  57. data/bin/console +0 -10
  58. data/bin/setup +0 -8
  59. data/lib/autoloaded/compatibility/refine_and_using.rb +0 -19
  60. data/lib/autoloaded/constant.rb +0 -94
  61. data/lib/autoloaded/refine/string/to_source_filename.rb +0 -58
  62. data/lib/autoloaded/refine/string.rb +0 -20
  63. data/lib/autoloaded/refine.rb +0 -16
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1 @@
1
+ raise "The file #{__FILE__} should not have been loaded"
@@ -0,0 +1,5 @@
1
+ module NotAutoloaded
2
+
3
+ module OldSchoolAutoload; end
4
+
5
+ end
@@ -0,0 +1,5 @@
1
+ module NotAutoloaded
2
+
3
+ autoload :OldSchoolAutoload, 'fixtures/not_autoloaded/old_school_autoload'
4
+
5
+ end
data/spec/matchers.rb ADDED
@@ -0,0 +1,85 @@
1
+ require 'support/util'
2
+ require 'support/without_side_effects'
3
+
4
+ RSpec::Matchers.define :define_constants do |*constant_names|
5
+ match do |source_file|
6
+ # Ensure the file exists.
7
+ File.open source_file, 'r' do
8
+ end
9
+
10
+ without_side_effects do
11
+ constant_names.each do |constant_name|
12
+ if Util.constantize(constant_name)
13
+ fail "constant #{constant_name} is already defined outside #{source_file}"
14
+ end
15
+ end
16
+
17
+ load source_file
18
+
19
+ constant_names.all? do |constant_name|
20
+ Util.namespace_and_unqualified_constant_name constant_name,
21
+ raise_if_namespace_invalid: true
22
+ Util.constantize constant_name
23
+ end
24
+ end
25
+ end
26
+
27
+ description do
28
+ fragments = []
29
+ fragments << case constant_names.length
30
+ when 0
31
+ 'no constants'
32
+ when 1
33
+ "constant #{constant_names.first}"
34
+ else
35
+ "constants #{constant_names.join ' and '}"
36
+ end
37
+ "define #{fragments.join ' '}"
38
+ end
39
+ end
40
+
41
+ RSpec::Matchers.define :set_up_autoload_for_constant do |constant_name|
42
+ match do |source_file|
43
+ # Ensure the file exists.
44
+ File.open source_file, 'r' do
45
+ end
46
+
47
+ without_side_effects do
48
+ namespace, unqualified_constant_name = Util.namespace_and_unqualified_constant_name(constant_name)
49
+ if namespace && namespace.autoload?(unqualified_constant_name)
50
+ fail "#{namespace.name}::#{unqualified_constant_name} is already set up for autoload outside #{source_file}"
51
+ end
52
+
53
+ load source_file
54
+
55
+ namespace, unqualified_constant_name = Util.namespace_and_unqualified_constant_name(constant_name,
56
+ raise_if_namespace_invalid: true)
57
+ if filename_or_filenames
58
+ Array(filename_or_filenames).sort == Array(namespace.autoload?(unqualified_constant_name)).sort
59
+ else
60
+ namespace.autoload? unqualified_constant_name
61
+ end
62
+ end
63
+ end
64
+
65
+ chain :from_file do |filename|
66
+ @filename_or_filenames = filename
67
+ end
68
+
69
+ chain :from_files do |*filenames|
70
+ @filename_or_filenames = filenames
71
+ end
72
+
73
+ description do
74
+ fragments = []
75
+ fragments << "constant #{constant_name}"
76
+ if filename_or_filenames
77
+ unless (filenames = Array(filename_or_filenames)).empty?
78
+ fragments << "from file#{(filenames.length == 1) ? nil : 's'} #{filenames.join ' and '}"
79
+ end
80
+ end
81
+ "set up #{Module.name}#autoload? for #{fragments.join ' '}"
82
+ end
83
+
84
+ attr_reader :filename_or_filenames
85
+ end
@@ -0,0 +1,91 @@
1
+ require 'codeclimate-test-reporter'
2
+
3
+ CodeClimate::TestReporter.start
4
+
5
+ # This file was generated by the `rspec --init` command. Conventionally, all
6
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
7
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
8
+ # file to always be loaded, without a need to explicitly require it in any files.
9
+ #
10
+ # Given that it is always loaded, you are encouraged to keep this file as
11
+ # light-weight as possible. Requiring heavyweight dependencies from this file
12
+ # will add to the boot time of your test suite on EVERY test run, even for an
13
+ # individual file that may not need all of that loaded. Instead, consider making
14
+ # a separate helper file that requires the additional dependencies and performs
15
+ # the additional setup, and require it from the spec files that actually need it.
16
+ #
17
+ # The `.rspec` file also contains a few flags that are not defaults but that
18
+ # users commonly want.
19
+ #
20
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+ RSpec.configure do |config|
22
+ # rspec-expectations config goes here. You can use an alternate
23
+ # assertion/expectation library such as wrong or the stdlib/minitest
24
+ # assertions if you prefer.
25
+ config.expect_with :rspec do |expectations|
26
+ # This option will default to `true` in RSpec 4. It makes the `description`
27
+ # and `failure_message` of custom matchers include text for helper methods
28
+ # defined using `chain`, e.g.:
29
+ # be_bigger_than(2).and_smaller_than(4).description
30
+ # # => "be bigger than 2 and smaller than 4"
31
+ # ...rather than:
32
+ # # => "be bigger than 2"
33
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
+ end
35
+
36
+ # rspec-mocks config goes here. You can use an alternate test double
37
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
38
+ config.mock_with :rspec do |mocks|
39
+ # Prevents you from mocking or stubbing a method that does not exist on
40
+ # a real object. This is generally recommended, and will default to
41
+ # `true` in RSpec 4.
42
+ mocks.verify_partial_doubles = true
43
+ end
44
+
45
+ # These two settings work together to allow you to limit a spec run
46
+ # to individual examples or groups you care about by tagging them with
47
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
48
+ # get run.
49
+ config.filter_run :focus
50
+ config.run_all_when_everything_filtered = true
51
+
52
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
53
+ # For more details, see:
54
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
55
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
56
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
57
+ config.disable_monkey_patching!
58
+
59
+ # This setting enables warnings. It's recommended, but in some cases may
60
+ # be too noisy due to issues in dependencies.
61
+ # config.warnings = true
62
+
63
+ # Many RSpec users commonly either run the entire suite or an individual
64
+ # file, and it's useful to allow more verbose output when running an
65
+ # individual spec file.
66
+ if config.files_to_run.one?
67
+ # Use the documentation formatter for detailed output,
68
+ # unless a formatter has already been configured
69
+ # (e.g. via a command-line flag).
70
+ config.default_formatter = 'doc'
71
+ end
72
+
73
+ # Print the 10 slowest examples and example groups at the
74
+ # end of the spec run, to help surface which specs are running
75
+ # particularly slow.
76
+ config.profile_examples = 1
77
+
78
+ # Run specs in random order to surface order dependencies. If you find an
79
+ # order dependency and want to debug it, you can fix the order by providing
80
+ # the seed, which is printed after each run.
81
+ # --seed 1234
82
+ config.order = :random
83
+
84
+ # Seed global randomization in this process using the `--seed` CLI option.
85
+ # Setting this allows you to use `--seed` to deterministically reproduce
86
+ # test failures related to randomization by passing the same `--seed` value
87
+ # as the one that triggered the failure.
88
+ Kernel.srand config.seed
89
+ end
90
+
91
+ require 'autoloaded'
@@ -0,0 +1,42 @@
1
+ module Util
2
+
3
+ class << self
4
+
5
+ def constantize(name)
6
+ return nil unless name
7
+
8
+ begin
9
+ eval name.to_s
10
+ rescue NameError
11
+ nil
12
+ end
13
+ end
14
+
15
+ def namespace_and_unqualified_constant_name(constant_name, options={})
16
+ namespace_name, unqualified_constant_name = split_namespace_and_constant(constant_name)
17
+ if namespace_name && (namespace = constantize(namespace_name)).nil?
18
+ if options[:raise_if_namespace_invalid]
19
+ raise "namespace of #{constant_name} is not defined"
20
+ end
21
+ end
22
+ [namespace, unqualified_constant_name]
23
+ end
24
+
25
+ def namespace_delimiter
26
+ '::'
27
+ end
28
+
29
+ private
30
+
31
+ def split_namespace_and_constant(constant_name)
32
+ if (last_delimiter_index = constant_name.to_s.rindex(namespace_delimiter))
33
+ return [constant_name[0...last_delimiter_index],
34
+ constant_name[(last_delimiter_index + namespace_delimiter.length)..-1]]
35
+ end
36
+
37
+ return [nil, constant_name]
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,37 @@
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 Exception => 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
+
22
+ # The codeclimate-test-reporter RubyGem uses Kernel#at_exit to hook the end
23
+ # of test/spec runs for sending coverage statistics to their web service. We
24
+ # need to skip that hook in this process fork because this is not the end of
25
+ # a test/spec run, only of a process fork.
26
+ exit!(true) if ENV['CODECLIMATE_REPO_TOKEN']
27
+ end
28
+
29
+ Process.wait pid
30
+
31
+ out_writer.close
32
+ err_writer.close
33
+
34
+ return Marshal.load(out_reader.read) if $?.success?
35
+
36
+ raise Marshal.load(err_reader.read)
37
+ end
metadata CHANGED
@@ -1,57 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autoloaded
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nils Jonsson
8
- autorequire:
9
- bindir: exe
8
+ autorequire:
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-19 00:00:00.000000000 Z
11
+ date: 2014-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: codeclimate-test-reporter
14
+ name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
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
- version: '0'
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
- version: '13'
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
- version: '13'
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
- version: '3.3'
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
- version: '3.3'
54
+ version: '3'
55
55
  description: If you like the ‘Module#autoload’ feature of the Ruby Core library, you
56
56
  may have wished for Autoloaded. It eliminates the drudgery of handcrafting an `autoload`
57
57
  statement for each Ruby source code file in your project. It also avoids the limitations
@@ -76,18 +76,11 @@ files:
76
76
  - README.md
77
77
  - Rakefile
78
78
  - autoloaded.gemspec
79
- - bin/console
80
- - bin/setup
81
79
  - lib/autoloaded.rb
82
80
  - lib/autoloaded/autoloader.rb
83
- - lib/autoloaded/compatibility/refine_and_using.rb
84
- - lib/autoloaded/constant.rb
85
81
  - lib/autoloaded/deprecation.rb
86
82
  - lib/autoloaded/inflection.rb
87
83
  - lib/autoloaded/load_pathed_directory.rb
88
- - lib/autoloaded/refine.rb
89
- - lib/autoloaded/refine/string.rb
90
- - lib/autoloaded/refine/string/to_source_filename.rb
91
84
  - lib/autoloaded/specification.rb
92
85
  - lib/autoloaded/specifications.rb
93
86
  - lib/autoloaded/version.rb
@@ -97,11 +90,44 @@ files:
97
90
  - lib/tasks/lib_each.rake
98
91
  - lib/tasks/spec.rake
99
92
  - lib/tasks/spec_each.rake
100
- homepage: https://njonsson.github.io/autoloaded
93
+ - spec/autoloaded/autoloader_spec.rb
94
+ - spec/autoloaded/inflection_spec.rb
95
+ - spec/autoloaded/load_pathed_directory_spec.rb
96
+ - spec/autoloaded/specification_spec.rb
97
+ - spec/autoloaded/specifications_spec.rb
98
+ - spec/autoloaded/version_spec.rb
99
+ - spec/autoloaded/warning_spec.rb
100
+ - spec/autoloaded_macro_sharedspec.rb
101
+ - spec/autoloaded_spec.rb
102
+ - spec/fixtures/autoloaded_with_conventional_filename.rb
103
+ - spec/fixtures/autoloaded_with_conventional_filename/N-est-ed.rb
104
+ - spec/fixtures/autoloaded_with_conventional_filename/nest_ed.rb
105
+ - spec/fixtures/autoloaded_with_conventional_filename/nested.rb
106
+ - spec/fixtures/autoloaded_with_conventional_filename/nested/doubly_nested.rb
107
+ - spec/fixtures/autoloaded_with_conventional_filename/old_school_autoload.rb
108
+ - spec/fixtures/autoloaded_with_unconventional_filename.rb
109
+ - spec/fixtures/autoloaded_with_unconventional_filename/N-est-ed.rb
110
+ - spec/fixtures/autoloaded_with_unconventional_filename/nest_ed.rb
111
+ - spec/fixtures/autoloaded_with_unconventional_filename/old_school_autoload.rb
112
+ - spec/fixtures/filenames/AFilename.rb
113
+ - spec/fixtures/filenames/a-file-name.rb
114
+ - spec/fixtures/filenames/a-filename.rb
115
+ - spec/fixtures/filenames/a_file_name.rb
116
+ - spec/fixtures/filenames/a_filename.rb
117
+ - spec/fixtures/filenames/afile-name.rb
118
+ - spec/fixtures/filenames/afile_name.rb
119
+ - spec/fixtures/not_autoloaded.rb
120
+ - spec/fixtures/not_autoloaded/nested.rb
121
+ - spec/fixtures/not_autoloaded/old_school_autoload.rb
122
+ - spec/matchers.rb
123
+ - spec/spec_helper.rb
124
+ - spec/support/util.rb
125
+ - spec/support/without_side_effects.rb
126
+ homepage: http://njonsson.github.io/autoloaded
101
127
  licenses:
102
128
  - MIT
103
129
  metadata: {}
104
- post_install_message:
130
+ post_install_message:
105
131
  rdoc_options: []
106
132
  require_paths:
107
133
  - lib
@@ -109,20 +135,55 @@ required_ruby_version: !ruby/object:Gem::Requirement
109
135
  requirements:
110
136
  - - ">="
111
137
  - !ruby/object:Gem::Version
112
- version: '2'
138
+ version: '1.9'
113
139
  - - "<"
114
140
  - !ruby/object:Gem::Version
115
- version: '4'
141
+ version: '3'
116
142
  required_rubygems_version: !ruby/object:Gem::Requirement
117
143
  requirements:
118
144
  - - ">="
119
145
  - !ruby/object:Gem::Version
120
146
  version: '0'
121
147
  requirements: []
122
- rubygems_version: 3.2.20
123
- signing_key:
148
+ rubyforge_project:
149
+ rubygems_version: 2.2.2
150
+ signing_key:
124
151
  specification_version: 4
125
152
  summary: Eliminates the drudgery of handcrafting a Ruby Core library `autoload` statement
126
153
  for each Ruby source code file in your project. It also avoids the limitations of
127
154
  rigid convention-driven facilities such as those provided by the ActiveSupport RubyGem.
128
- test_files: []
155
+ test_files:
156
+ - spec/autoloaded/autoloader_spec.rb
157
+ - spec/autoloaded/inflection_spec.rb
158
+ - spec/autoloaded/load_pathed_directory_spec.rb
159
+ - spec/autoloaded/specification_spec.rb
160
+ - spec/autoloaded/specifications_spec.rb
161
+ - spec/autoloaded/version_spec.rb
162
+ - spec/autoloaded/warning_spec.rb
163
+ - spec/autoloaded_macro_sharedspec.rb
164
+ - spec/autoloaded_spec.rb
165
+ - spec/fixtures/autoloaded_with_conventional_filename.rb
166
+ - spec/fixtures/autoloaded_with_conventional_filename/N-est-ed.rb
167
+ - spec/fixtures/autoloaded_with_conventional_filename/nest_ed.rb
168
+ - spec/fixtures/autoloaded_with_conventional_filename/nested.rb
169
+ - spec/fixtures/autoloaded_with_conventional_filename/nested/doubly_nested.rb
170
+ - spec/fixtures/autoloaded_with_conventional_filename/old_school_autoload.rb
171
+ - spec/fixtures/autoloaded_with_unconventional_filename.rb
172
+ - spec/fixtures/autoloaded_with_unconventional_filename/N-est-ed.rb
173
+ - spec/fixtures/autoloaded_with_unconventional_filename/nest_ed.rb
174
+ - spec/fixtures/autoloaded_with_unconventional_filename/old_school_autoload.rb
175
+ - spec/fixtures/filenames/AFilename.rb
176
+ - spec/fixtures/filenames/a-file-name.rb
177
+ - spec/fixtures/filenames/a-filename.rb
178
+ - spec/fixtures/filenames/a_file_name.rb
179
+ - spec/fixtures/filenames/a_filename.rb
180
+ - spec/fixtures/filenames/afile-name.rb
181
+ - spec/fixtures/filenames/afile_name.rb
182
+ - spec/fixtures/not_autoloaded.rb
183
+ - spec/fixtures/not_autoloaded/nested.rb
184
+ - spec/fixtures/not_autoloaded/old_school_autoload.rb
185
+ - spec/matchers.rb
186
+ - spec/spec_helper.rb
187
+ - spec/support/util.rb
188
+ - spec/support/without_side_effects.rb
189
+ has_rdoc:
data/bin/console DELETED
@@ -1,10 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'bundler/setup'
4
- require 'autoloaded'
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- require 'pry'
10
- Pry.start
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
-
5
- which bundle || gem install bundler
6
- bundle
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,19 +0,0 @@
1
- # Fall back to monkeypatching if refinements are not supported.
2
-
3
- unless ::Module.private_instance_methods.include?(:refine)
4
- # @api private
5
- class ::Module
6
-
7
- private
8
-
9
- def refine(klass, &block)
10
- klass.class_eval(&block)
11
- end
12
-
13
- end
14
- end
15
-
16
- unless private_methods.include?(:using)
17
- def using(*arguments); end
18
- private :using
19
- end
@@ -1,94 +0,0 @@
1
- require 'autoloaded/refine/string/to_source_filename'
2
- require 'set'
3
-
4
- using ::Autoloaded::Refine::String::ToSourceFilename
5
-
6
- module Autoloaded; end
7
-
8
- # Represents a Ruby constant.
9
- #
10
- # @since 0.0.1
11
- #
12
- # @api private
13
- class Autoloaded::Constant
14
-
15
- attr_reader :name
16
-
17
- def initialize(name)
18
- @name = name.freeze
19
- end
20
-
21
- def each_matching_filename_in(directory, &block)
22
- filenames = ::Set.new
23
-
24
- yield_qualified_name_source_filename_in(directory,
25
- unless_in: filenames,
26
- &block)
27
- yield_all_qualified_filenames_in(directory, unless_in: filenames, &block)
28
- end
29
-
30
- private
31
-
32
- def extension
33
- '.rb'
34
- end
35
-
36
- def filename_without_extension(filename)
37
- "#{::File.dirname filename}/#{::File.basename filename, extension}"
38
- end
39
-
40
- def filename_without_load_path_prefix(filename)
41
- first_applicable_load_path = $:.detect do |path|
42
- filename.start_with? path
43
- end
44
- if first_applicable_load_path
45
- regexp = /^#{::Regexp.escape first_applicable_load_path}\/?/
46
- filename = filename.gsub(regexp, '')
47
- end
48
- filename
49
- end
50
-
51
- def format_filename(filename)
52
- filename_without_load_path_prefix filename_without_extension(filename)
53
- end
54
-
55
- def name_signature
56
- @name_signature ||= signature(name)
57
- end
58
-
59
- def name_source_filename
60
- @name_source_filename ||= [name.to_s.to_source_filename, extension].join
61
- end
62
-
63
- def qualified_glob_in(directory)
64
- ::File.join(directory, ['*', extension].join)
65
- end
66
-
67
- def signature(string)
68
- string.to_s.gsub(/[^a-z0-9]/i, '').downcase
69
- end
70
-
71
- def yield_all_qualified_filenames_in(directory, unless_in: nil, &block)
72
- unless unless_in
73
- raise ::ArgumentError, "missing keyword: unless_in"
74
- end
75
- ::Dir.glob(qualified_glob_in(directory), ::File::FNM_CASEFOLD) do |filename|
76
- filename_signature = signature(::File.basename(filename, extension))
77
- if (filename_signature == name_signature) &&
78
- unless_in.add?(::File.basename(filename))
79
- block.call format_filename(filename)
80
- end
81
- end
82
- end
83
-
84
- def yield_qualified_name_source_filename_in(directory, unless_in: nil, &block)
85
- unless unless_in
86
- raise ::ArgumentError, "missing keyword: unless_in"
87
- end
88
- qualified = ::File.join(directory, name_source_filename)
89
- if ::File.file?(qualified) && unless_in.add?(name_source_filename)
90
- block.call format_filename(qualified)
91
- end
92
- end
93
-
94
- end
@@ -1,58 +0,0 @@
1
- require 'autoloaded/compatibility/refine_and_using'
2
-
3
- module Autoloaded
4
-
5
- module Refine
6
-
7
- module String; end
8
-
9
- end
10
-
11
- end
12
-
13
- # Refines _String_ to translate a constant name into a source filename.
14
- #
15
- # @since 0.0.1
16
- #
17
- # @api private
18
- module Autoloaded::Refine::String::ToSourceFilename
19
-
20
- # @!method to_source_filename
21
- # Translates the name of a constant into the name of a source file.
22
- #
23
- # @return [String] the name of a source file corresponding to the name of a
24
- # constant
25
- #
26
- # @note Namespaces are ignored rather than translated into directories.
27
- refine ::String do
28
- def replace_nonalphanumeric_sequence_with_separator
29
- gsub(/[^a-z0-9]+/i, separator.to_s)
30
- end
31
-
32
- def separate_capital_and_following_capitalized_word
33
- gsub(/([A-Z])([A-Z])([a-z])/,
34
- "\\1#{separator}\\2\\3")
35
- end
36
-
37
- def separate_digit_and_following_letter
38
- gsub(/([0-9])([a-z])/i, "\\1#{separator}\\2")
39
- end
40
-
41
- def separate_lowercase_letter_and_following_capital_letter
42
- gsub(/([a-z])([A-Z])/, "\\1#{separator}\\2")
43
- end
44
-
45
- def separator
46
- '_'
47
- end
48
-
49
- def to_source_filename
50
- replace_nonalphanumeric_sequence_with_separator.
51
- separate_capital_and_following_capitalized_word.
52
- separate_lowercase_letter_and_following_capital_letter.
53
- separate_digit_and_following_letter.
54
- downcase
55
- end
56
- end
57
-
58
- end