include_with_respect 1.0.1 → 1.0.3
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +173 -0
- data/LICENSE.md +10 -0
- data/README.md +468 -73
- data/lib/include_with_respect/concern_with_respect.rb +2 -2
- data/lib/include_with_respect/configuration.rb +2 -2
- data/lib/include_with_respect/ext/active_record/base.rb +1 -1
- data/lib/include_with_respect/ext/active_support/concern.rb +1 -1
- data/lib/include_with_respect/version.rb +9 -1
- data/lib/include_with_respect.rb +13 -13
- data/sig/include_with_respect.rbs +12 -0
- data.tar.gz.sig +0 -0
- metadata +432 -232
- metadata.gz.sig +5 -0
- data/.gitignore +0 -13
- data/.rspec +0 -3
- data/.ruby-version +0 -1
- data/.travis.yml +0 -38
- data/CODE_OF_CONDUCT.md +0 -74
- data/Gemfile +0 -4
- data/LICENSE +0 -7
- data/Rakefile +0 -6
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/gemfiles/ruby_2.0.gemfile +0 -11
- data/gemfiles/ruby_2.1.gemfile +0 -11
- data/gemfiles/ruby_2.2.gemfile +0 -11
- data/gemfiles/ruby_2.3.gemfile +0 -11
- data/gemfiles/ruby_2.4.gemfile +0 -11
- data/gemfiles/ruby_2.5.gemfile +0 -11
- data/gemfiles/ruby_2.6.gemfile +0 -11
- data/include_with_respect.gemspec +0 -41
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module IncludeWithRespect
|
|
2
|
-
|
|
4
|
+
# Version namespace for this gem.
|
|
5
|
+
module Version
|
|
6
|
+
# Current gem version.
|
|
7
|
+
VERSION = "1.0.3"
|
|
8
|
+
end
|
|
9
|
+
# Current gem version exposed at the traditional constant location.
|
|
10
|
+
VERSION = Version::VERSION # Traditional Constant Location
|
|
3
11
|
end
|
data/lib/include_with_respect.rb
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require
|
|
4
|
-
require 'include_with_respect/configuration'
|
|
3
|
+
require "include_with_respect/configuration"
|
|
5
4
|
|
|
6
5
|
# How to automatically inject into ActiveSupport::Concern,
|
|
7
6
|
# or other module dependency trees?
|
|
8
7
|
# Refer to inline documentation in each file.
|
|
9
|
-
require
|
|
10
|
-
|
|
8
|
+
require "include_with_respect/module_with_respect"
|
|
9
|
+
require_relative "include_with_respect/version"
|
|
10
|
+
|
|
11
|
+
require "include_with_respect/concern_with_respect" if defined?(ActiveSupport)
|
|
11
12
|
|
|
12
13
|
# [Sometimes] We should respect our ancestors.
|
|
13
14
|
#
|
|
@@ -23,18 +24,16 @@ module IncludeWithRespect
|
|
|
23
24
|
class Error < StandardError; end
|
|
24
25
|
|
|
25
26
|
def include_with_respect(receiver, module1, *smth)
|
|
26
|
-
|
|
27
|
-
have_respect('included', receiver, module1, *smth) if receiver.include?(module1)
|
|
27
|
+
skip = receiver.include?(module1) && have_respect("included", receiver, module1, *smth)
|
|
28
28
|
|
|
29
|
-
receiver.send(:include_without_respect, module1, *smth) unless
|
|
29
|
+
receiver.send(:include_without_respect, module1, *smth) unless skip
|
|
30
30
|
end
|
|
31
31
|
module_function :include_with_respect
|
|
32
32
|
|
|
33
33
|
def extend_with_respect(receiver, module1, *smth)
|
|
34
|
-
|
|
35
|
-
have_respect('extended', receiver, module1, skip, *smth) if receiver.singleton_class.include?(module1)
|
|
34
|
+
skip = receiver.singleton_class.include?(module1) && have_respect("extended", receiver, module1, *smth)
|
|
36
35
|
|
|
37
|
-
receiver.send(:extend_without_respect, module1, *smth) unless
|
|
36
|
+
receiver.send(:extend_without_respect, module1, *smth) unless skip
|
|
38
37
|
end
|
|
39
38
|
module_function :extend_with_respect
|
|
40
39
|
|
|
@@ -57,18 +56,19 @@ module IncludeWithRespect
|
|
|
57
56
|
private
|
|
58
57
|
|
|
59
58
|
def have_respect(action, receiver, module1, *smth)
|
|
60
|
-
message = "#{module1}#{
|
|
59
|
+
message = "#{module1}#{" with #{smth}" if smth.any?} already #{action} in #{receiver}"
|
|
61
60
|
puts "message: #{message}" if configuration.level == [:error]
|
|
62
|
-
configuration.level.
|
|
61
|
+
configuration.level.any? do |level|
|
|
63
62
|
case level
|
|
64
63
|
when :error
|
|
65
64
|
raise ::IncludeWithRespect::Error, message
|
|
66
65
|
when :warning
|
|
67
66
|
puts message
|
|
68
67
|
when :skip
|
|
69
|
-
|
|
68
|
+
true
|
|
70
69
|
else # :silent
|
|
71
70
|
# NOOP
|
|
71
|
+
false
|
|
72
72
|
end
|
|
73
73
|
end
|
|
74
74
|
end
|
data.tar.gz.sig
ADDED
|
Binary file
|