Module: Inclusive::ModuleWithPackages
- Defined in:
- lib/inclusive.rb
Overview
This is the base module which will be cloned for each individual import scenario. You should never need to reference this module directly.
Class Method Summary collapse
-
.[](*packages) ⇒ Object
Use this for the inline packages syntax.
- .extend_with_package(package) ⇒ Object
- .inspect ⇒ Object
- .loaded_packages ⇒ Object
- .package_methods ⇒ Object
- .to_s ⇒ Object
- .warn_on_overwritten_methods(package) ⇒ Object
Class Method Details
.[](*packages) ⇒ Object
Use this for the inline packages syntax.
29 30 31 32 |
# File 'lib/inclusive.rb', line 29 def self.[](*packages) packages.each { |package| extend_with_package(package) } self end |
.extend_with_package(package) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/inclusive.rb', line 34 def self.extend_with_package(package) @package_names ||= Set.new @package_methods ||= Set.new warn_on_overwritten_methods(package) package.instance_methods.each { @package_methods << _1 } @package_names << package.name extend package end |
.inspect ⇒ Object
55 |
# File 'lib/inclusive.rb', line 55 def self.inspect = to_s |
.loaded_packages ⇒ Object
57 58 59 |
# File 'lib/inclusive.rb', line 57 def self.loaded_packages singleton_class.included_modules.reverse.select { @package_names.include? _1.name } end |
.package_methods ⇒ Object
61 62 63 |
# File 'lib/inclusive.rb', line 61 def self.package_methods loaded_packages.flat_map(&:instance_methods) end |
.to_s ⇒ Object
53 |
# File 'lib/inclusive.rb', line 53 def self.to_s = "#{name}<#{@package_names.join(", ")}>" |
.warn_on_overwritten_methods(package) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/inclusive.rb', line 45 def self.warn_on_overwritten_methods(package) overwriting_methods = @package_methods.select { package.instance_methods.include? _1 } return unless overwriting_methods.length.positive? warn "Inclusive <#{@package_names.join(", ")}> - The following methods will be overridden by " \ "'#{package.name}':\n #{overwriting_methods.join(", ")}" end |