Module: IncludeWithRespect
- Defined in:
- lib/include_with_respect.rb,
lib/include_with_respect/version.rb,
lib/include_with_respect/configuration.rb,
lib/include_with_respect/module_with_respect.rb,
lib/include_with_respect/concern_with_respect.rb
Overview
This is an ActiveSupport::Concern that will make other concerns “include with respect” Usage:
module MyConcern
extend ActiveSupport::Concern
included do
include IncludeWithRespect::ConcernWithRespect
include SomeOtherConcern
end
end
Defined Under Namespace
Modules: ConcernWithRespect, ModuleWithRespect Classes: Configuration, Error
Constant Summary collapse
- VERSION =
'1.0.1'.freeze
Class Attribute Summary collapse
-
.include_with_respect_configuration ⇒ Object
Returns the value of attribute include_with_respect_configuration.
Class Method Summary collapse
-
.configuration ⇒ Object
For single statement global config in an initializer e.g.
-
.configure {|configuration| ... } ⇒ Object
For global config in an initializer with a block.
- .extend_with_respect(receiver, module1, *smth) ⇒ Object
- .have_respect(action, receiver, module1, *smth) ⇒ Object
- .include_with_respect(receiver, module1, *smth) ⇒ Object
Class Attribute Details
.include_with_respect_configuration ⇒ Object
Returns the value of attribute include_with_respect_configuration.
54 55 56 |
# File 'lib/include_with_respect.rb', line 54 def include_with_respect_configuration @include_with_respect_configuration end |
Class Method Details
.configuration ⇒ Object
For single statement global config in an initializer e.g. IncludeWithRespect.configuration.level = :error
43 44 45 |
# File 'lib/include_with_respect.rb', line 43 def self.configuration self.include_with_respect_configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
For global config in an initializer with a block
48 49 50 |
# File 'lib/include_with_respect.rb', line 48 def self.configure yield(configuration) end |
.extend_with_respect(receiver, module1, *smth) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/include_with_respect.rb', line 33 def extend_with_respect(receiver, module1, *smth) @skip_include = false have_respect('extended', receiver, module1, skip, *smth) if receiver.singleton_class.include?(module1) receiver.send(:extend_without_respect, module1, *smth) unless @skip_include end |
.have_respect(action, receiver, module1, *smth) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/include_with_respect.rb', line 59 def have_respect(action, receiver, module1, *smth) = "#{module1}#{smth.any? ? " with #{smth}" : ''} already #{action} in #{receiver}" puts "message: #{}" if configuration.level == [:error] configuration.level.each do |level| case level when :error raise ::IncludeWithRespect::Error, when :warning puts when :skip @skip_include = true else # :silent # NOOP end end end |
.include_with_respect(receiver, module1, *smth) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/include_with_respect.rb', line 25 def include_with_respect(receiver, module1, *smth) @skip_include = false have_respect('included', receiver, module1, *smth) if receiver.include?(module1) receiver.send(:include_without_respect, module1, *smth) unless @skip_include end |