prependers 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +38 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop-https---relaxed-ruby-style-rubocop-yml +170 -0
- data/.rubocop.yml +13 -0
- data/.travis.yml +7 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +60 -0
- data/LICENSE.txt +21 -0
- data/README.md +146 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/prependers/errors.rb +7 -0
- data/lib/prependers/loader.rb +47 -0
- data/lib/prependers/prepender.rb +22 -0
- data/lib/prependers/version.rb +5 -0
- data/lib/prependers.rb +16 -0
- data/prependers.gemspec +33 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 9a1eac50893ccb55164b21b283e65e94391b83ffc31eda995e0f165563b061f3
|
4
|
+
data.tar.gz: 38a7b5ef5a65a0f770c3d266a4f25f9ef70826619222e40e8fbdddd45af27c9f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 717c6c18e4c420c290991b5875efbc665c06e52ab52fd2e06d683c0e9c3397645ded55cdc46b6b98247d030690d8a92a67f69d358fe250d4d06c3a0df6e70629
|
7
|
+
data.tar.gz: b43b8612c46d2db304c9bfa7765a73f944ec4600e0edd84f6238cbb783ee99a1ed526c5ef45f03c36c68f2d41ff11b6e13fe79ab66f429eb3d8b26a9aea13ed3
|
@@ -0,0 +1,38 @@
|
|
1
|
+
version: 2.1
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
parallelism: 3
|
5
|
+
docker:
|
6
|
+
- image: circleci/ruby:2.6.3
|
7
|
+
environment:
|
8
|
+
BUNDLE_JOBS: 3
|
9
|
+
BUNDLE_RETRY: 3
|
10
|
+
BUNDLE_PATH: vendor/bundle
|
11
|
+
steps:
|
12
|
+
- checkout
|
13
|
+
|
14
|
+
- restore_cache:
|
15
|
+
keys:
|
16
|
+
- prependers-v1-{{ checksum "Gemfile.lock" }}
|
17
|
+
- prependers-v1-
|
18
|
+
|
19
|
+
- run:
|
20
|
+
name: Bundle Install
|
21
|
+
command: bundle check || bundle install
|
22
|
+
|
23
|
+
- save_cache:
|
24
|
+
key: prependers-v1-{{ checksum "Gemfile.lock" }}
|
25
|
+
paths:
|
26
|
+
- vendor/bundle
|
27
|
+
|
28
|
+
- run:
|
29
|
+
name: Run rspec in parallel
|
30
|
+
command: |
|
31
|
+
bundle exec rspec \
|
32
|
+
--format RspecJunitFormatter \
|
33
|
+
--out test_results/rspec.xml \
|
34
|
+
--format progress \
|
35
|
+
$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
|
36
|
+
|
37
|
+
- store_test_results:
|
38
|
+
path: test_results
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1,170 @@
|
|
1
|
+
# Relaxed.Ruby.Style
|
2
|
+
## Version 2.2
|
3
|
+
|
4
|
+
Style/Alias:
|
5
|
+
Enabled: false
|
6
|
+
StyleGuide: https://relaxed.ruby.style/#stylealias
|
7
|
+
|
8
|
+
Style/AsciiComments:
|
9
|
+
Enabled: false
|
10
|
+
StyleGuide: https://relaxed.ruby.style/#styleasciicomments
|
11
|
+
|
12
|
+
Style/BeginBlock:
|
13
|
+
Enabled: false
|
14
|
+
StyleGuide: https://relaxed.ruby.style/#stylebeginblock
|
15
|
+
|
16
|
+
Style/BlockDelimiters:
|
17
|
+
Enabled: false
|
18
|
+
StyleGuide: https://relaxed.ruby.style/#styleblockdelimiters
|
19
|
+
|
20
|
+
Style/CommentAnnotation:
|
21
|
+
Enabled: false
|
22
|
+
StyleGuide: https://relaxed.ruby.style/#stylecommentannotation
|
23
|
+
|
24
|
+
Style/Documentation:
|
25
|
+
Enabled: false
|
26
|
+
StyleGuide: https://relaxed.ruby.style/#styledocumentation
|
27
|
+
|
28
|
+
Layout/DotPosition:
|
29
|
+
Enabled: false
|
30
|
+
StyleGuide: https://relaxed.ruby.style/#layoutdotposition
|
31
|
+
|
32
|
+
Style/DoubleNegation:
|
33
|
+
Enabled: false
|
34
|
+
StyleGuide: https://relaxed.ruby.style/#styledoublenegation
|
35
|
+
|
36
|
+
Style/EndBlock:
|
37
|
+
Enabled: false
|
38
|
+
StyleGuide: https://relaxed.ruby.style/#styleendblock
|
39
|
+
|
40
|
+
Style/FormatString:
|
41
|
+
Enabled: false
|
42
|
+
StyleGuide: https://relaxed.ruby.style/#styleformatstring
|
43
|
+
|
44
|
+
Style/IfUnlessModifier:
|
45
|
+
Enabled: false
|
46
|
+
StyleGuide: https://relaxed.ruby.style/#styleifunlessmodifier
|
47
|
+
|
48
|
+
Style/Lambda:
|
49
|
+
Enabled: false
|
50
|
+
StyleGuide: https://relaxed.ruby.style/#stylelambda
|
51
|
+
|
52
|
+
Style/ModuleFunction:
|
53
|
+
Enabled: false
|
54
|
+
StyleGuide: https://relaxed.ruby.style/#stylemodulefunction
|
55
|
+
|
56
|
+
Style/MultilineBlockChain:
|
57
|
+
Enabled: false
|
58
|
+
StyleGuide: https://relaxed.ruby.style/#stylemultilineblockchain
|
59
|
+
|
60
|
+
Style/NegatedIf:
|
61
|
+
Enabled: false
|
62
|
+
StyleGuide: https://relaxed.ruby.style/#stylenegatedif
|
63
|
+
|
64
|
+
Style/NegatedWhile:
|
65
|
+
Enabled: false
|
66
|
+
StyleGuide: https://relaxed.ruby.style/#stylenegatedwhile
|
67
|
+
|
68
|
+
Style/ParallelAssignment:
|
69
|
+
Enabled: false
|
70
|
+
StyleGuide: https://relaxed.ruby.style/#styleparallelassignment
|
71
|
+
|
72
|
+
Style/PercentLiteralDelimiters:
|
73
|
+
Enabled: false
|
74
|
+
StyleGuide: https://relaxed.ruby.style/#stylepercentliteraldelimiters
|
75
|
+
|
76
|
+
Style/PerlBackrefs:
|
77
|
+
Enabled: false
|
78
|
+
StyleGuide: https://relaxed.ruby.style/#styleperlbackrefs
|
79
|
+
|
80
|
+
Style/Semicolon:
|
81
|
+
Enabled: false
|
82
|
+
StyleGuide: https://relaxed.ruby.style/#stylesemicolon
|
83
|
+
|
84
|
+
Style/SignalException:
|
85
|
+
Enabled: false
|
86
|
+
StyleGuide: https://relaxed.ruby.style/#stylesignalexception
|
87
|
+
|
88
|
+
Style/SingleLineBlockParams:
|
89
|
+
Enabled: false
|
90
|
+
StyleGuide: https://relaxed.ruby.style/#stylesinglelineblockparams
|
91
|
+
|
92
|
+
Style/SingleLineMethods:
|
93
|
+
Enabled: false
|
94
|
+
StyleGuide: https://relaxed.ruby.style/#stylesinglelinemethods
|
95
|
+
|
96
|
+
Layout/SpaceBeforeBlockBraces:
|
97
|
+
Enabled: false
|
98
|
+
StyleGuide: https://relaxed.ruby.style/#layoutspacebeforeblockbraces
|
99
|
+
|
100
|
+
Layout/SpaceInsideParens:
|
101
|
+
Enabled: false
|
102
|
+
StyleGuide: https://relaxed.ruby.style/#layoutspaceinsideparens
|
103
|
+
|
104
|
+
Style/SpecialGlobalVars:
|
105
|
+
Enabled: false
|
106
|
+
StyleGuide: https://relaxed.ruby.style/#stylespecialglobalvars
|
107
|
+
|
108
|
+
Style/StringLiterals:
|
109
|
+
Enabled: false
|
110
|
+
StyleGuide: https://relaxed.ruby.style/#stylestringliterals
|
111
|
+
|
112
|
+
Style/TrailingCommaInArguments:
|
113
|
+
Enabled: false
|
114
|
+
StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarguments
|
115
|
+
|
116
|
+
Style/TrailingCommaInArrayLiteral:
|
117
|
+
Enabled: false
|
118
|
+
StyleGuide: https://relaxed.ruby.style/#styletrailingcommainarrayliteral
|
119
|
+
|
120
|
+
Style/TrailingCommaInHashLiteral:
|
121
|
+
Enabled: false
|
122
|
+
StyleGuide: https://relaxed.ruby.style/#styletrailingcommainhashliteral
|
123
|
+
|
124
|
+
Style/SymbolArray:
|
125
|
+
Enabled: false
|
126
|
+
StyleGuide: http://relaxed.ruby.style/#stylesymbolarray
|
127
|
+
|
128
|
+
Style/WhileUntilModifier:
|
129
|
+
Enabled: false
|
130
|
+
StyleGuide: https://relaxed.ruby.style/#stylewhileuntilmodifier
|
131
|
+
|
132
|
+
Style/WordArray:
|
133
|
+
Enabled: false
|
134
|
+
StyleGuide: https://relaxed.ruby.style/#stylewordarray
|
135
|
+
|
136
|
+
Lint/AmbiguousRegexpLiteral:
|
137
|
+
Enabled: false
|
138
|
+
StyleGuide: https://relaxed.ruby.style/#lintambiguousregexpliteral
|
139
|
+
|
140
|
+
Lint/AssignmentInCondition:
|
141
|
+
Enabled: false
|
142
|
+
StyleGuide: https://relaxed.ruby.style/#lintassignmentincondition
|
143
|
+
|
144
|
+
Metrics/AbcSize:
|
145
|
+
Enabled: false
|
146
|
+
|
147
|
+
Metrics/BlockNesting:
|
148
|
+
Enabled: false
|
149
|
+
|
150
|
+
Metrics/ClassLength:
|
151
|
+
Enabled: false
|
152
|
+
|
153
|
+
Metrics/ModuleLength:
|
154
|
+
Enabled: false
|
155
|
+
|
156
|
+
Metrics/CyclomaticComplexity:
|
157
|
+
Enabled: false
|
158
|
+
|
159
|
+
Metrics/LineLength:
|
160
|
+
Enabled: false
|
161
|
+
|
162
|
+
Metrics/MethodLength:
|
163
|
+
Enabled: false
|
164
|
+
|
165
|
+
Metrics/ParameterLists:
|
166
|
+
Enabled: false
|
167
|
+
|
168
|
+
Metrics/PerceivedComplexity:
|
169
|
+
Enabled: false
|
170
|
+
|
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
prependers (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.0)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
jaro_winkler (1.5.3)
|
12
|
+
parallel (1.17.0)
|
13
|
+
parser (2.6.3.0)
|
14
|
+
ast (~> 2.4.0)
|
15
|
+
rainbow (3.0.0)
|
16
|
+
rake (10.5.0)
|
17
|
+
rspec (3.8.0)
|
18
|
+
rspec-core (~> 3.8.0)
|
19
|
+
rspec-expectations (~> 3.8.0)
|
20
|
+
rspec-mocks (~> 3.8.0)
|
21
|
+
rspec-core (3.8.1)
|
22
|
+
rspec-support (~> 3.8.0)
|
23
|
+
rspec-expectations (3.8.4)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.8.0)
|
26
|
+
rspec-mocks (3.8.1)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.8.0)
|
29
|
+
rspec-support (3.8.2)
|
30
|
+
rspec_junit_formatter (0.4.1)
|
31
|
+
rspec-core (>= 2, < 4, != 2.12.0)
|
32
|
+
rubocop (0.70.0)
|
33
|
+
jaro_winkler (~> 1.5.1)
|
34
|
+
parallel (~> 1.10)
|
35
|
+
parser (>= 2.6)
|
36
|
+
rainbow (>= 2.2.2, < 4.0)
|
37
|
+
ruby-progressbar (~> 1.7)
|
38
|
+
unicode-display_width (>= 1.4.0, < 1.7)
|
39
|
+
rubocop-performance (1.3.0)
|
40
|
+
rubocop (>= 0.68.0)
|
41
|
+
rubocop-rspec (1.33.0)
|
42
|
+
rubocop (>= 0.60.0)
|
43
|
+
ruby-progressbar (1.10.1)
|
44
|
+
unicode-display_width (1.6.0)
|
45
|
+
|
46
|
+
PLATFORMS
|
47
|
+
ruby
|
48
|
+
|
49
|
+
DEPENDENCIES
|
50
|
+
bundler (~> 1.17)
|
51
|
+
prependers!
|
52
|
+
rake (~> 10.0)
|
53
|
+
rspec (~> 3.0)
|
54
|
+
rspec_junit_formatter (~> 0.4.1)
|
55
|
+
rubocop (~> 0.70.0)
|
56
|
+
rubocop-performance (~> 1.3)
|
57
|
+
rubocop-rspec (~> 1.33)
|
58
|
+
|
59
|
+
BUNDLED WITH
|
60
|
+
1.17.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Nebulab Srls
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
# Prependers
|
2
|
+
|
3
|
+
[![CircleCI](https://circleci.com/gh/nebulab/prependers.svg?style=svg)](https://circleci.com/gh/nebulab/prependers)
|
4
|
+
|
5
|
+
Prependers are a way to easily and cleanly extend third-party code via `Module#prepend`.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'prependers'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
```console
|
18
|
+
$ bundle
|
19
|
+
```
|
20
|
+
|
21
|
+
|
22
|
+
Or install it yourself as:
|
23
|
+
|
24
|
+
```console
|
25
|
+
$ gem install prependers
|
26
|
+
```
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
To define a prepender manually, simply include the `Prependers::Prepender.new` module. For instance,
|
31
|
+
if you have installed an `animals` gem and you want to extend the `Animals::Dog` class, you can
|
32
|
+
define a module like the following:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
module Animals::Dog::AddBarking
|
36
|
+
include Prependers::Prepender.new
|
37
|
+
|
38
|
+
def bark
|
39
|
+
puts 'Woof!'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
Animals::Dog.new.bark # => 'Woof!'
|
44
|
+
```
|
45
|
+
|
46
|
+
### Autoloading prependers
|
47
|
+
|
48
|
+
If you don't want to include `Prependers::Prepender`, you can also autoload prependers from a path.
|
49
|
+
Here's the previous example, but with autoloading:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
# app/prependers/animals/dog/add_barking.rb
|
53
|
+
module Animals::Dog::AddBarking
|
54
|
+
def bark
|
55
|
+
puts 'Woof!'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# somewhere in your initialization code
|
60
|
+
Prependers.load_paths(File.expand_path('app/prependers'))
|
61
|
+
```
|
62
|
+
|
63
|
+
You can pass multiple arguments to `#load_paths`, which is useful if you have subdirectories in
|
64
|
+
`app/prependers`:
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
Prependers.load_paths(
|
68
|
+
File.expand_path('app/prependers/controllers'),
|
69
|
+
File.expand_path('app/prependers/models'),
|
70
|
+
# ...
|
71
|
+
)
|
72
|
+
```
|
73
|
+
|
74
|
+
Note that, in order for autoprepending to work, the paths of your prependers must match the names
|
75
|
+
of the prependers you defined.
|
76
|
+
|
77
|
+
### Using a namespace
|
78
|
+
|
79
|
+
It can be useful to have a prefix namespace for your prependers. That way, you don't have to worry
|
80
|
+
about accidentally overriding any vendor modules. This is actually the recommended way to define
|
81
|
+
your prependers.
|
82
|
+
|
83
|
+
You can accomplish this by passing an argument when including the `Prependers::Prepender` module:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
module MyApp
|
87
|
+
module Animals
|
88
|
+
module Dog
|
89
|
+
module AddBarking
|
90
|
+
include Prependers::Prepender.new(MyApp)
|
91
|
+
|
92
|
+
def bark
|
93
|
+
puts 'Woof!'
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
```
|
100
|
+
|
101
|
+
If you use autoloading, you can pass the base namespace to `#load_paths`:
|
102
|
+
|
103
|
+
```ruby
|
104
|
+
Prependers.load_paths(File.expand_path('app/prependers'), namespace: MyApp)
|
105
|
+
```
|
106
|
+
|
107
|
+
### Integrating with Rails
|
108
|
+
|
109
|
+
To use prependers in your Rails app, simply create them under `app/prependers/models`,
|
110
|
+
`app/prependers/controllers` etc. and add the following to your `config/application.rb`:
|
111
|
+
|
112
|
+
```ruby
|
113
|
+
config.to_prepare do
|
114
|
+
Dir.glob(Rails.root.join('app', 'prependers', '**', '*.rb')) do |c|
|
115
|
+
Rails.configuration.cache_classes ? require(c) : load(c)
|
116
|
+
end
|
117
|
+
|
118
|
+
prepender_paths = Dir.glob(Rails.root.join('app', 'prependers', '*')).map do |p|
|
119
|
+
File.expand_path(p, __FILE__)
|
120
|
+
end
|
121
|
+
|
122
|
+
Prependers.load_paths(*prepender_paths)
|
123
|
+
end
|
124
|
+
```
|
125
|
+
|
126
|
+
If you want to use a namespace, just pass the `:namespace` option to `#load_paths` and name your
|
127
|
+
files and modules accordingly.
|
128
|
+
|
129
|
+
## Development
|
130
|
+
|
131
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run
|
132
|
+
the tests. You can also run `bin/console` for an interactive prompt that will allow you to
|
133
|
+
experiment.
|
134
|
+
|
135
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new
|
136
|
+
version, update the version number in `version.rb`, and then run `bundle exec rake release`, which
|
137
|
+
will create a git tag for the version, push git commits and tags, and push the `.gem` file to
|
138
|
+
[rubygems.org](https://rubygems.org).
|
139
|
+
|
140
|
+
## Contributing
|
141
|
+
|
142
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/nebulab/prependers.
|
143
|
+
|
144
|
+
## License
|
145
|
+
|
146
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "prependers"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Prependers
|
4
|
+
class Loader
|
5
|
+
attr_reader :base_path, :options
|
6
|
+
|
7
|
+
def initialize(base_path, options = {})
|
8
|
+
@base_path = Pathname.new(File.expand_path(base_path))
|
9
|
+
@options = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def load
|
13
|
+
Dir.glob("#{base_path}/**/*.rb") do |path|
|
14
|
+
absolute_path = Pathname.new(File.expand_path(path))
|
15
|
+
relative_path = absolute_path.relative_path_from(base_path)
|
16
|
+
|
17
|
+
prepender_module_name = expected_module_for(relative_path)
|
18
|
+
|
19
|
+
unless Object.const_defined?(prepender_module_name)
|
20
|
+
error = <<~ERROR
|
21
|
+
Expected #{absolute_path} to define #{prepender_module_name}, but module is not defined.
|
22
|
+
|
23
|
+
Note that Prependers does not require files automatically - you will have to do that
|
24
|
+
yourself before calling `#load_paths`.
|
25
|
+
ERROR
|
26
|
+
|
27
|
+
raise NoPrependerError, error
|
28
|
+
end
|
29
|
+
|
30
|
+
prepender_module = Object.const_get(prepender_module_name)
|
31
|
+
prepender_module.include Prepender.new(options[:namespace])
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def expected_module_for(path)
|
38
|
+
path = path.to_s[0..-(File.extname(path).length + 1)]
|
39
|
+
|
40
|
+
return path.camelize if path.respond_to?(:camelize)
|
41
|
+
|
42
|
+
path.to_s.gsub('/', '::').split('::').map do |part|
|
43
|
+
part.split('_').map(&:capitalize).join
|
44
|
+
end.join('::')
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Prependers
|
4
|
+
class Prepender < Module
|
5
|
+
attr_reader :namespace
|
6
|
+
|
7
|
+
def initialize(namespace = nil)
|
8
|
+
@namespace = namespace
|
9
|
+
end
|
10
|
+
|
11
|
+
def included(base)
|
12
|
+
prepended_module_name = base.name.split('::')[0..-2].join('::')
|
13
|
+
|
14
|
+
if namespace
|
15
|
+
prepended_module_name = (prepended_module_name[(namespace.name.length + 2)..-1]).to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
prepended_module = Object.const_get(prepended_module_name)
|
19
|
+
prepended_module.prepend base
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
data/lib/prependers.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "prependers/version"
|
4
|
+
require "prependers/errors"
|
5
|
+
require "prependers/prepender"
|
6
|
+
require "prependers/loader"
|
7
|
+
|
8
|
+
module Prependers
|
9
|
+
class << self
|
10
|
+
def load_paths(*paths, **options)
|
11
|
+
Array(paths).each do |path|
|
12
|
+
Loader.new(path, options).load
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/prependers.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require "prependers/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "prependers"
|
9
|
+
spec.version = Prependers::VERSION
|
10
|
+
spec.authors = ["Alessandro Desantis"]
|
11
|
+
spec.email = ["desa.alessandro@gmail.com"]
|
12
|
+
|
13
|
+
spec.summary = 'Decorate vendor code with style.'
|
14
|
+
spec.homepage = 'https://github.com/nebulab/prependers'
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
spec.add_development_dependency "rspec_junit_formatter", '~> 0.4.1'
|
30
|
+
spec.add_development_dependency "rubocop", '~> 0.70.0'
|
31
|
+
spec.add_development_dependency "rubocop-performance", '~> 1.3'
|
32
|
+
spec.add_development_dependency "rubocop-rspec", '~> 1.33'
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prependers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alessandro Desantis
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-21 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.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec_junit_formatter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.4.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.4.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 0.70.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.70.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-performance
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop-rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.33'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.33'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- desa.alessandro@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".circleci/config.yml"
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".rubocop-https---relaxed-ruby-style-rubocop-yml"
|
122
|
+
- ".rubocop.yml"
|
123
|
+
- ".travis.yml"
|
124
|
+
- Gemfile
|
125
|
+
- Gemfile.lock
|
126
|
+
- LICENSE.txt
|
127
|
+
- README.md
|
128
|
+
- Rakefile
|
129
|
+
- bin/console
|
130
|
+
- bin/setup
|
131
|
+
- lib/prependers.rb
|
132
|
+
- lib/prependers/errors.rb
|
133
|
+
- lib/prependers/loader.rb
|
134
|
+
- lib/prependers/prepender.rb
|
135
|
+
- lib/prependers/version.rb
|
136
|
+
- prependers.gemspec
|
137
|
+
homepage: https://github.com/nebulab/prependers
|
138
|
+
licenses:
|
139
|
+
- MIT
|
140
|
+
metadata: {}
|
141
|
+
post_install_message:
|
142
|
+
rdoc_options: []
|
143
|
+
require_paths:
|
144
|
+
- lib
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: '0'
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
requirements: []
|
156
|
+
rubygems_version: 3.0.3
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Decorate vendor code with style.
|
160
|
+
test_files: []
|