autoloaded 1.6.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +8 -4
  3. data/.rspec +1 -1
  4. data/.travis.yml +1 -14
  5. data/Gemfile +10 -11
  6. data/Guardfile +22 -21
  7. data/History.md +12 -27
  8. data/README.md +48 -58
  9. data/Rakefile +0 -4
  10. data/autoloaded.gemspec +37 -41
  11. data/lib/autoloaded.rb +0 -40
  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/tasks/lib_each.rake +3 -15
  21. data/lib/tasks/spec.rake +6 -3
  22. data/spec/autoloaded/autoloader_spec.rb +469 -0
  23. data/spec/autoloaded/inflection_spec.rb +30 -0
  24. data/spec/autoloaded/load_pathed_directory_spec.rb +120 -0
  25. data/spec/autoloaded/specification_spec.rb +98 -0
  26. data/spec/autoloaded/specifications_spec.rb +191 -0
  27. data/spec/autoloaded/version_spec.rb +3 -0
  28. data/spec/autoloaded/warning_spec.rb +115 -0
  29. data/spec/autoloaded_macro_sharedspec.rb +24 -0
  30. data/spec/autoloaded_spec.rb +173 -0
  31. data/spec/fixtures/autoloaded_with_conventional_filename.rb +12 -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.rb +16 -0
  35. data/spec/fixtures/autoloaded_with_conventional_filename/nested/doubly_nested.rb +9 -0
  36. data/spec/fixtures/autoloaded_with_conventional_filename/old_school_autoload.rb +5 -0
  37. data/spec/fixtures/autoloaded_with_unconventional_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/filenames/AFilename.rb +0 -0
  42. data/spec/fixtures/filenames/a-file-name.rb +0 -0
  43. data/spec/fixtures/filenames/a-filename.rb +0 -0
  44. data/spec/fixtures/filenames/a_file_name.rb +0 -0
  45. data/spec/fixtures/filenames/a_filename.rb +0 -0
  46. data/spec/fixtures/filenames/afile-name.rb +0 -0
  47. data/spec/fixtures/filenames/afile_name.rb +0 -0
  48. data/spec/fixtures/not_autoloaded.rb +5 -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/matchers.rb +85 -0
  52. data/spec/spec_helper.rb +91 -0
  53. data/spec/support/util.rb +42 -0
  54. data/spec/support/without_side_effects.rb +37 -0
  55. metadata +86 -22
  56. data/bin/console +0 -10
  57. data/bin/setup +0 -8
  58. data/lib/autoloaded/compatibility/refine_and_using.rb +0 -19
  59. data/lib/autoloaded/constant.rb +0 -94
  60. data/lib/autoloaded/refine.rb +0 -16
  61. data/lib/autoloaded/refine/string.rb +0 -20
  62. data/lib/autoloaded/refine/string/to_source_filename.rb +0 -58
@@ -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.6.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nils Jonsson
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-06 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,7 +90,40 @@ 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: {}
@@ -107,19 +133,57 @@ require_paths:
107
133
  - lib
108
134
  required_ruby_version: !ruby/object:Gem::Requirement
109
135
  requirements:
110
- - - "~>"
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '1.9'
139
+ - - "<"
111
140
  - !ruby/object:Gem::Version
112
- version: '2'
141
+ version: '3'
113
142
  required_rubygems_version: !ruby/object:Gem::Requirement
114
143
  requirements:
115
144
  - - ">="
116
145
  - !ruby/object:Gem::Version
117
146
  version: '0'
118
147
  requirements: []
119
- rubygems_version: 3.1.2
148
+ rubyforge_project:
149
+ rubygems_version: 2.2.2
120
150
  signing_key:
121
151
  specification_version: 4
122
152
  summary: Eliminates the drudgery of handcrafting a Ruby Core library `autoload` statement
123
153
  for each Ruby source code file in your project. It also avoids the limitations of
124
154
  rigid convention-driven facilities such as those provided by the ActiveSupport RubyGem.
125
- 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:
@@ -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,16 +0,0 @@
1
- module Autoloaded
2
-
3
- # Contains Ruby Core Library type refinements.
4
- #
5
- # @see http://ruby-doc.org/core Ruby Core Library
6
- #
7
- # @since 0.0.1
8
- #
9
- # @api private
10
- module Refine
11
-
12
- autoload :String, 'autoloaded/refine/string'
13
-
14
- end
15
-
16
- end
@@ -1,20 +0,0 @@
1
- module Autoloaded
2
-
3
- module Refine
4
-
5
- # Contains _String_ refinements.
6
- #
7
- # @see http://ruby-doc.org/core/String.html String
8
- #
9
- # @since 0.0.1
10
- #
11
- # @api private
12
- module String
13
-
14
- autoload :ToSourceFilename, 'autoloaded/refine/string/to_source_filename'
15
-
16
- end
17
-
18
- end
19
-
20
- 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