internal_api 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +2 -0
- data/.travis.yml +8 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +85 -0
- data/Rakefile +11 -0
- data/VERSION +1 -0
- data/bin/setup +8 -0
- data/internal_api.gemspec +37 -0
- data/lib/internal_api.rb +131 -0
- data/lib/internal_api/full_method_source_location.rb +37 -0
- data/lib/internal_api/rewriter.rb +52 -0
- data/lib/internal_api/version.rb +5 -0
- metadata +144 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1beab71c3746aca2c7edab9b64c200b5242e278ae99066ae2dcbc3e1600f1736
|
4
|
+
data.tar.gz: 2157b3450386d5b938f9eaf3eda39afa117fbff7d316a9554695ec49ffb144c7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1d3ffa8c4e28c54c87b34900a164e2ecf1effe6678abeef87a103676283bf82d5886643b1b6ce886c0d0fc2933ccb3421a9806f44e914702f50d2dfff4cbd1df
|
7
|
+
data.tar.gz: 6f49f5eac3cb632817fabc03a7b041bc55db12e1cebdd5aec2b831754933dfe33f8c8a94e5ed0f476b659de056ffabde33c3e64aa5e209e199c462e5c3f62d23
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at github@jackcanty.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Jack Danger
|
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,85 @@
|
|
1
|
+
# Ruby internal_api
|
2
|
+
|
3
|
+
This is a gem for decomposing monolithic Rails apps. It allows you to specify an internal class or module that serves as the internal api for another class or module.
|
4
|
+
|
5
|
+
Example:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
# Any class or module can be the interface for a portion of your app.
|
9
|
+
# Imagine trying to collect all payment-related code in your app such that you
|
10
|
+
# can guarantee none of it used except in the way you expect.
|
11
|
+
#
|
12
|
+
# You'll want to somehow encapsulate your models
|
13
|
+
class PaymentRecord < ActiveRecord::Base
|
14
|
+
internal_api PaymentApi
|
15
|
+
end
|
16
|
+
|
17
|
+
# And any helper modules or classes
|
18
|
+
module Payments
|
19
|
+
class Issue
|
20
|
+
internal_api PaymentApi
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# And all you need is some object that you specify as the internal_api for all your code.
|
25
|
+
module PaymentApi
|
26
|
+
def charge(amount_cents, options = {})
|
27
|
+
# This is whatever bespoke, ugly code you've inherited in your existing app.
|
28
|
+
record = PaymentRecord.create(amount_cents)
|
29
|
+
issue = Payments::Issue.new(record).complete!
|
30
|
+
log(issue)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# So when someone adds a new dependency to your internal code they fail their unit tests:
|
35
|
+
module Onboarding
|
36
|
+
def self.complete!(user)
|
37
|
+
PaymentRecord.create(1_00, type: auth)
|
38
|
+
# other onboarding stuff
|
39
|
+
end
|
40
|
+
end
|
41
|
+
Onboarding.complete(@user) #! Only `PaymentApi` methods can execute PaymentApi code.
|
42
|
+
```
|
43
|
+
|
44
|
+
The `internal_api` call rewrites the public methods on your internal code to
|
45
|
+
ensure that it can only be called if `PaymentApi` is somewhere in the call
|
46
|
+
stack. This allows you to hide an entire portion of your application behind an
|
47
|
+
interface of some kind and have confidence it's reasonable well encapsulated.
|
48
|
+
|
49
|
+
## Installation
|
50
|
+
|
51
|
+
Add this line to your application's Gemfile:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
gem 'internal_api'
|
55
|
+
```
|
56
|
+
|
57
|
+
## Performance
|
58
|
+
|
59
|
+
This API enforcement is purely dyamic - `internal_api` modified the runtime
|
60
|
+
execution of code and checks for correct access patterns. This has a nonzero
|
61
|
+
but completely negligible impact on performance and therefore can safely be run
|
62
|
+
in production.
|
63
|
+
|
64
|
+
If you come from a Java background you may be used to thinking of backtraces as
|
65
|
+
very expensive. In Ruby they're quite cheap - the backtrace is always available
|
66
|
+
in memory and accessing it only requires [turning](https://github.com/ruby/ruby/blob/c3cf1ef9bbacac6ae5abc99046db173e258dc7ca/vm_backtrace.c#L549-L566) the C stack into (simple) Ruby
|
67
|
+
objects.
|
68
|
+
|
69
|
+
Constructing a single backtrace in running production code takes only a few microseconds on any
|
70
|
+
modern CPU:
|
71
|
+
|
72
|
+
>> Benchmark.measure { 1_000_000.times { Kernel.caller_locations }}.real
|
73
|
+
=> 5.190758000011556
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
Patches welcome, forks celebrated. This project is a safe, welcoming space for collaboration, and contributors will adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
78
|
+
|
79
|
+
## License
|
80
|
+
|
81
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
82
|
+
|
83
|
+
## Code of Conduct
|
84
|
+
|
85
|
+
Everyone interacting in the InternalApi project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/internal_api/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/setup
ADDED
@@ -0,0 +1,37 @@
|
|
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 'internal_api/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'internal_api'
|
9
|
+
spec.version = InternalApi::VERSION
|
10
|
+
spec.authors = ['Jack Danger']
|
11
|
+
spec.email = ['github@jackcanty.com']
|
12
|
+
|
13
|
+
spec.summary = 'Carve up your Rails monolith via internal APIs'
|
14
|
+
spec.description = 'Create code boundaries within your Rails monolith'
|
15
|
+
spec.homepage = 'https://github.com/JackDanger/ruby_internal_api'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
|
18
|
+
# Specify which files should be added to the gem when it is released.
|
19
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
20
|
+
# into git.
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
23
|
+
f.match(%r{^(test|spec|features)/})
|
24
|
+
end
|
25
|
+
end
|
26
|
+
spec.bindir = 'exe'
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
spec.add_dependency 'method_source'
|
31
|
+
|
32
|
+
spec.add_development_dependency 'bundler'
|
33
|
+
spec.add_development_dependency 'pry-byebug'
|
34
|
+
spec.add_development_dependency 'rake'
|
35
|
+
spec.add_development_dependency 'rspec'
|
36
|
+
spec.add_development_dependency 'rubocop'
|
37
|
+
end
|
data/lib/internal_api.rb
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'internal_api/version'
|
4
|
+
require 'internal_api/full_method_source_location'
|
5
|
+
require 'internal_api/rewriter'
|
6
|
+
|
7
|
+
# The InternalApi module provides one public method (`.internal_api`) available
|
8
|
+
# on any Ruby module.
|
9
|
+
# This method takes as its single argument any object has public methods. When
|
10
|
+
# called, the (public) methods of the caller will no longer be directly
|
11
|
+
# accessible.
|
12
|
+
#
|
13
|
+
# This is deliberately designed to not depend on any gems, C-extensions, or any
|
14
|
+
# Ruby features specific to a minor version.
|
15
|
+
module InternalApi
|
16
|
+
extend self
|
17
|
+
|
18
|
+
LoaderMutex = Mutex.new
|
19
|
+
|
20
|
+
# ViolationError is raised when protected code is called from code not behind
|
21
|
+
# the internal api
|
22
|
+
class ViolationError < StandardError; end
|
23
|
+
|
24
|
+
# This is the only public API method
|
25
|
+
module RubyCoreExtension
|
26
|
+
def internal_api(protector)
|
27
|
+
InternalApi.protect(self, protector)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Rewrites all public methods on the protectee (the Ruby class or module that
|
32
|
+
# received the 'internal_api' message), replacing them with a method that
|
33
|
+
# checks the backtrace and ensures at least one line matches one of the
|
34
|
+
# public methods of the protector.
|
35
|
+
def protect(protectee, protector)
|
36
|
+
calculate_public_methods!(protector)
|
37
|
+
|
38
|
+
# Extract the eigenclass of any object
|
39
|
+
# https://medium.com/@ethan.reid.roberts/rubys-anonymous-eigenclass-putting-the-ei-in-team-ebc1e8f8d668
|
40
|
+
eigenclass = (class << protectee; self; end)
|
41
|
+
|
42
|
+
# Rewrite future public singleton methods
|
43
|
+
Rewriter.add_singleton_rewrite_hooks!(protectee, protector)
|
44
|
+
# Rewrite eigenclass' future public instance methods
|
45
|
+
Rewriter.add_instance_rewrite_hooks!(eigenclass, protector)
|
46
|
+
# Rewrite eigenclass' future public singleton methods
|
47
|
+
Rewriter.add_singleton_rewrite_hooks!(eigenclass, protector)
|
48
|
+
end
|
49
|
+
|
50
|
+
def check_caller!(protector)
|
51
|
+
allowed_caller_methods = InternalApi.public_method_cache[protector]
|
52
|
+
# NB: `caller` is much slower than `caller_locations`
|
53
|
+
caller_locations.each do |location|
|
54
|
+
# This calculation is quadratic but as the backtrace is finite and these
|
55
|
+
# comparisons take only tens of nanoseconds each this is fast enough for
|
56
|
+
# production use.
|
57
|
+
allowed_caller_methods.each do |path, range|
|
58
|
+
if location.path == path && range.include?(location.lineno)
|
59
|
+
return path, range
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
raise_violation!(caller_locations[1].label, protector)
|
64
|
+
end
|
65
|
+
|
66
|
+
def rewrite_method!(protectee, internal_method, protector)
|
67
|
+
protectee.instance_eval do
|
68
|
+
# We create a new pointer to the original method
|
69
|
+
alias_method "_internal_api_#{internal_method}", internal_method
|
70
|
+
|
71
|
+
# And overwrite it
|
72
|
+
define_method internal_method do |*args, &block|
|
73
|
+
InternalApi.check_caller!(protector)
|
74
|
+
send("_internal_api_#{internal_method}", *args, &block)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def public_method_cache
|
80
|
+
@public_method_cache ||= {}
|
81
|
+
end
|
82
|
+
|
83
|
+
def debug(line)
|
84
|
+
puts "InternalApi: #{line}" if $DEBUG
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def raise_violation!(label, protector)
|
90
|
+
message = "#{label.inspect} is protected by `#{protector.name}`" \
|
91
|
+
" and can only execute when a `#{protector.name}`" \
|
92
|
+
' method is in the backtrace'
|
93
|
+
raise InternalApi::ViolationError, message
|
94
|
+
end
|
95
|
+
|
96
|
+
def calculate_public_methods!(mod)
|
97
|
+
LoaderMutex.synchronize do
|
98
|
+
return if InternalApi.public_method_cache.key?(mod)
|
99
|
+
|
100
|
+
# We cache the public methods because this requires a fairly exhaustive,
|
101
|
+
# recursive lookup of Ruby method hierarchy to perform:
|
102
|
+
#
|
103
|
+
# https://github.com/ruby/ruby/blob/c3cf1ef9bbacac6ae5abc99046db173e258dc7ca/class.c#L1206-L1238
|
104
|
+
#
|
105
|
+
# > Benchmark.measure { 10_000.times { Object.new }}.real
|
106
|
+
# => 0.0033939999993890524
|
107
|
+
# >> Benchmark.measure { 10_000.times { Object.public_methods }}.real
|
108
|
+
# => 0.1327720000408589800
|
109
|
+
#
|
110
|
+
# It's up to the user to avoid adding new public methods to the protected
|
111
|
+
# code after app initialization.
|
112
|
+
|
113
|
+
source_ranges = FullMethodSourceLocation.public_method_source_ranges(mod)
|
114
|
+
unless source_ranges
|
115
|
+
raise InternalApi::UnreachableCodeError,
|
116
|
+
"#{self} is protected by #{protector}," \
|
117
|
+
' which has no public methods'
|
118
|
+
end
|
119
|
+
|
120
|
+
InternalApi.public_method_cache[mod] = source_ranges
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Make this generally available
|
126
|
+
Module.include InternalApi::RubyCoreExtension
|
127
|
+
Class.include InternalApi::RubyCoreExtension
|
128
|
+
|
129
|
+
# Time to #dogfood.
|
130
|
+
# Protect the internal parts of InternalAPI
|
131
|
+
# InternalApi.internal_api(InternalApi::RubyCoreExtension)
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'method_source'
|
4
|
+
module InternalApi
|
5
|
+
# Ruby gives us the start location of a method but not the end. We need to
|
6
|
+
# know the full range so we can verify any calls made anywhere in a method
|
7
|
+
# have originated from that method.
|
8
|
+
#
|
9
|
+
# We lean on the MethodSource gem (the library underneath Pry's method
|
10
|
+
# inspection) for this as it does some wild trickery with attempting to
|
11
|
+
# parse raw Ruby code without actually using a parser.
|
12
|
+
module FullMethodSourceLocation
|
13
|
+
extend self
|
14
|
+
|
15
|
+
def range(method)
|
16
|
+
source_location = method.source_location
|
17
|
+
return unless source_location
|
18
|
+
|
19
|
+
path, start = source_location
|
20
|
+
|
21
|
+
source = MethodSource.source_helper(source_location)
|
22
|
+
[path, (start..(start + source.lines.size - 1))]
|
23
|
+
end
|
24
|
+
|
25
|
+
# Find the file path and the start and end line numbers of all public class
|
26
|
+
# methods and public instance methods
|
27
|
+
def public_method_source_ranges(mod)
|
28
|
+
class_ranges = mod.public_methods(false).map do |m|
|
29
|
+
FullMethodSourceLocation.range(mod.method(m))
|
30
|
+
end.compact
|
31
|
+
instance_ranges = mod.public_instance_methods(false).map do |m|
|
32
|
+
FullMethodSourceLocation.range(mod.instance_method(m))
|
33
|
+
end.compact
|
34
|
+
class_ranges + instance_ranges
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module InternalApi
|
4
|
+
# This uses the built-in Ruby callbacks for when new methods are defined:
|
5
|
+
# https://github.com/ruby/ruby/blob/c3cf1ef9bbacac6ae5abc99046db173e258dc7ca/object.c#L940-L954
|
6
|
+
module Rewriter
|
7
|
+
extend self
|
8
|
+
|
9
|
+
# rubocop:disable Metrics/MethodLength
|
10
|
+
SKIP_PATTERN = /(^_internal_api)|(^(singleton_)?method_added$)/.freeze
|
11
|
+
def add_instance_rewrite_hooks!(protectee, protector)
|
12
|
+
protectee.class_eval do
|
13
|
+
define_method(:method_added) do |method_name|
|
14
|
+
return unless InternalApi::Rewriter.should_overwrite?(
|
15
|
+
method_name,
|
16
|
+
instance_methods,
|
17
|
+
public_instance_methods
|
18
|
+
)
|
19
|
+
|
20
|
+
InternalApi.debug "#{self}##{method_name} protected by #{protector}"
|
21
|
+
InternalApi.rewrite_method!(self, method_name, protector)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def add_singleton_rewrite_hooks!(protectee, protector)
|
27
|
+
protectee.class_eval do
|
28
|
+
define_method(:singleton_method_added) do |method_name|
|
29
|
+
return unless InternalApi::Rewriter.should_overwrite?(
|
30
|
+
method_name,
|
31
|
+
methods,
|
32
|
+
public_methods
|
33
|
+
)
|
34
|
+
|
35
|
+
eigen = (class << self; self; end)
|
36
|
+
InternalApi.debug "#{eigen}.#{method_name} protected by #{protector}"
|
37
|
+
InternalApi.rewrite_method!(eigen, method_name, protector)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
# rubocop:enable Metrics/MethodLength
|
42
|
+
|
43
|
+
def should_overwrite?(method_name, methods, public_methods)
|
44
|
+
# Don't interfere with the metaprogramming
|
45
|
+
return false if method_name.to_s =~ SKIP_PATTERN
|
46
|
+
# And definitely don't try to do this twice
|
47
|
+
return false if methods.include?("_internal_api_#{method_name}".to_sym)
|
48
|
+
|
49
|
+
public_methods.include?(method_name)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: internal_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jack Danger
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-05-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: method_source
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: pry-byebug
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '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'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Create code boundaries within your Rails monolith
|
98
|
+
email:
|
99
|
+
- github@jackcanty.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- ".rspec"
|
106
|
+
- ".rubocop.yml"
|
107
|
+
- ".travis.yml"
|
108
|
+
- CODE_OF_CONDUCT.md
|
109
|
+
- Gemfile
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- VERSION
|
114
|
+
- bin/setup
|
115
|
+
- internal_api.gemspec
|
116
|
+
- lib/internal_api.rb
|
117
|
+
- lib/internal_api/full_method_source_location.rb
|
118
|
+
- lib/internal_api/rewriter.rb
|
119
|
+
- lib/internal_api/version.rb
|
120
|
+
homepage: https://github.com/JackDanger/ruby_internal_api
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
124
|
+
post_install_message:
|
125
|
+
rdoc_options: []
|
126
|
+
require_paths:
|
127
|
+
- lib
|
128
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
requirements: []
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 2.7.6
|
141
|
+
signing_key:
|
142
|
+
specification_version: 4
|
143
|
+
summary: Carve up your Rails monolith via internal APIs
|
144
|
+
test_files: []
|