diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..37a9318 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,27 @@ +name: Ruby + +on: + push: + branches: + - main + + pull_request: + +jobs: + build: + runs-on: ubuntu-latest + name: Ruby ${{ matrix.ruby }} + strategy: + matrix: + ruby: + - '3.3.0' + + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Run the default task + run: bundle exec rake diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9106b2a --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +/.bundle/ +/.yardoc +/_yardoc/ +/coverage/ +/doc/ +/pkg/ +/spec/reports/ +/tmp/ diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..d969faf --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,30 @@ +require: + - rubocop-minitest + - rubocop-rake + +AllCops: + TargetRubyVersion: 3.1 + NewCops: enable + +Naming/VariableNumber: + Enabled: false + +Style/EndlessMethod: + Enabled: false + +Style/CommentedKeyword: + Enabled: false + +Style/StringLiterals: + Enabled: true + EnforcedStyle: double_quotes + +Style/StringLiteralsInInterpolation: + Enabled: true + EnforcedStyle: double_quotes + +Layout/LineLength: + Max: 120 + +Metrics/MethodLength: + Max: 20 diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..0aec50e --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +3.1.4 diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..b200d65 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +## [Unreleased] + +## [1.0.0] - 2024-06-30 + +- Initial release diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..c980c72 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,84 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience +* Focusing on what is best not just for us as individuals, but for the overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at jared@jaredwhite.com. All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series of actions. + +**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, +available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..634e2ea --- /dev/null +++ b/Gemfile @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +source "https://rubygems.org" + +# Specify your gem's dependencies in inclusive.gemspec +gemspec + +gem "rake", "~> 13.0" + +gem "minitest", "~> 5.16" + +gem "rubocop", "~> 1.21" + +gem "solargraph", "~> 0.50.0" + +gem "rubocop-minitest", "~> 0.35.0" + +gem "rubocop-rake", "~> 0.6.0" diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..0f0e73d --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,96 @@ +PATH + remote: . + specs: + inclusive (0.1.0) + +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.2) + backport (1.2.0) + benchmark (0.3.0) + diff-lcs (1.5.1) + e2mmap (0.1.0) + jaro_winkler (1.5.6) + json (2.7.2) + kramdown (2.4.0) + rexml + kramdown-parser-gfm (1.1.0) + kramdown (~> 2.0) + language_server-protocol (3.17.0.3) + mini_portile2 (2.8.6) + minitest (5.23.0) + nokogiri (1.16.5) + mini_portile2 (~> 2.8.2) + racc (~> 1.4) + nokogiri (1.16.5-arm64-darwin) + racc (~> 1.4) + parallel (1.24.0) + parser (3.3.1.0) + ast (~> 2.4.1) + racc + racc (1.7.3) + rainbow (3.1.1) + rake (13.2.1) + rbs (2.8.4) + regexp_parser (2.9.2) + reverse_markdown (2.1.1) + nokogiri + rexml (3.2.8) + strscan (>= 3.0.9) + rubocop (1.63.5) + json (~> 2.3) + language_server-protocol (>= 3.17.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.31.1, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.3) + parser (>= 3.3.1.0) + rubocop-minitest (0.35.0) + rubocop (>= 1.61, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + ruby-progressbar (1.13.0) + solargraph (0.50.0) + backport (~> 1.2) + benchmark + bundler (~> 2.0) + diff-lcs (~> 1.4) + e2mmap + jaro_winkler (~> 1.5) + kramdown (~> 2.3) + kramdown-parser-gfm (~> 1.1) + parser (~> 3.0) + rbs (~> 2.0) + reverse_markdown (~> 2.0) + rubocop (~> 1.38) + thor (~> 1.0) + tilt (~> 2.0) + yard (~> 0.9, >= 0.9.24) + strscan (3.1.0) + thor (1.3.1) + tilt (2.3.0) + unicode-display_width (2.5.0) + yard (0.9.36) + +PLATFORMS + arm64-darwin-23 + ruby + +DEPENDENCIES + inclusive! + minitest (~> 5.16) + rake (~> 13.0) + rubocop (~> 1.21) + rubocop-minitest (~> 0.35.0) + rubocop-rake (~> 0.6.0) + solargraph (~> 0.50.0) + +BUNDLED WITH + 2.5.6 diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..369df9b --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2024 Jared White & Bridgetown maintainers + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..0c7a02f --- /dev/null +++ b/README.md @@ -0,0 +1,136 @@ +# Inclusive + +Compose globally-scoped Ruby modules into local packages. This makes it easy to access utility methods (aka functions) without having to type lengthy namespaces or remember which modules provide with functions at each call site (or alternatively include modules in your classes which pollute the method space). + +## Installation + +Install the gem and add to the application's Gemfile by executing: + + $ bundle add inclusive + +If bundler is not being used to manage dependencies, install the gem by executing: + + $ gem install inclusive + +## Usage + +To start with, you can write your "package" (aka a standard Ruby module) containing a set of discrete functions. It's recommended you namespace your packages within higher-level modules. + +```ruby +module MyOrg + module MyPackages + module WorkHardAtIt + def just_do_it = puts "Don't let your dreams be dreams" + end + end +end +``` + +Then in any standard Ruby class, you can include the `Inclusive` module and use the `packages` class helper to "import" the package: + +```ruby +require "inclusive" +# require the file(s) containing your package(s) + +class GetToThePoint + include Inclusive + + packages def work_hard = [MyOrg::MyPackages::WorkHardAtIt] + + def nothing_is_impossible + work_hard.just_do_it # this will print out the motivational speech + end +end +``` + +The import syntax is an array because you can import multiple packages. The imported packages will "compose" together, meaning the methods from the various package modules will all be available simultaneously. + +In addition to creating instance methods using the `packages` class helper, you can use the `packages` method inline: + +```ruby +def some_method + my_math = packages[MyOrg::Math] + + my_math.multiply_by_100(5) +end +``` + +This approach isn't recommended unless you're in a context where using the class helper is impossible, such as a template (ERB, etc.) or a block which is executed by a framework. You can also call the `packages` method directly on the `Inclusive` module: + +```ruby +my_math = Inclusive.packages(MyOrg::Math) +``` + +If you want to be able to call a package method directly on its own module, you can extend your module and use the `public_function` helper: + +```ruby +module Packages + module MyPackage + extend Inclusive::Public + + def some_method + # code + end + + public_function :some_method + end +end +``` + +Now in addition to using package imports via Inclusive, you can call the module method directly: + +```ruby +Packages::MyPackage.some_method +``` + +This is only recommended if you need to mantain an existing module's legacy behavior in a codebase while incrementally adopting Inclusive. + +### Packages Are Duplicated + +One of the aspects of Inclusive which make it more useful than merely using standard Ruby modules is each imported package is actually a cloned module. This means a module can actually contain internal state, much like an object: + +```ruby +module Packages + module Ownership + attr_accessor :owner + + def owner_classname + owner.class.name + end + end +end + +class SomeObject + def try_out_ownership + ownership = packages[Package::Ownership].tap { _1.owner = self } + + puts ownership.owner_classname # this will be `SomeObject` + end +end + +class SomeOtherObject + def try_out_ownership + ownership = packages[Package::Ownership].tap { _1.owner = self } + + puts ownership.owner_classname # this will be `SomeOtherObject` + end +end +``` + +## Development + +After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. + +To install this gem onto your local machine, run `bin/rake install`. To release a new version, update the version number in `version.rb`, and then run `bin/rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org). + +## Contributing + +Bug reports and pull requests are welcome on GitHub at https://github.com/bridgetownrb/inclusive. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/bridgetownrb/inclusive/blob/main/CODE_OF_CONDUCT.md). + +## License + +The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT). + +## Code of Conduct + +Everyone interacting in the Inclusive project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/bridgetownrb/inclusive/blob/main/CODE_OF_CONDUCT.md). diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..2bf771f --- /dev/null +++ b/Rakefile @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require "bundler/gem_tasks" +require "minitest/test_task" + +Minitest::TestTask.create + +require "rubocop/rake_task" + +RuboCop::RakeTask.new + +task default: %i[test rubocop] diff --git a/bin/console b/bin/console new file mode 100755 index 0000000..d408611 --- /dev/null +++ b/bin/console @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require "bundler/setup" +require "inclusive" + +# You can add fixtures and/or initialization code here to make experimenting +# with your gem easier. You can also use a different console, if you like. + +require "irb" +IRB.start(__FILE__) diff --git a/bin/rake b/bin/rake new file mode 100755 index 0000000..4eb7d7b --- /dev/null +++ b/bin/rake @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rake' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rake", "rake") diff --git a/bin/rubocop b/bin/rubocop new file mode 100755 index 0000000..369a05b --- /dev/null +++ b/bin/rubocop @@ -0,0 +1,27 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rubocop' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) + +bundle_binstub = File.expand_path("bundle", __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rubocop", "rubocop") diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..dce67d8 --- /dev/null +++ b/bin/setup @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' +set -vx + +bundle install + +# Do any other automated setup that you need to do here diff --git a/inclusive.gemspec b/inclusive.gemspec new file mode 100644 index 0000000..528c027 --- /dev/null +++ b/inclusive.gemspec @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require_relative "lib/inclusive/version" + +Gem::Specification.new do |spec| + spec.name = "inclusive" + spec.version = Inclusive::VERSION + spec.author = "Bridgetown Team" + spec.email = "maintainers@bridgetownrb.com" + + spec.summary = "Compose globally-scoped Ruby modules into local packages" + spec.homepage = "https://github.com/bridgetownrb/inclusive" + spec.license = "MIT" + spec.required_ruby_version = ">= 3.1.0" + + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = spec.homepage + spec.metadata["rubygems_mfa_required"] = "true" + + # Specify which files should be added to the gem when it is released. + # The `git ls-files -z` loads the files in the RubyGem that have been added into git. + spec.files = Dir.chdir(__dir__) do + `git ls-files -z`.split("\x0").reject do |f| + (File.expand_path(f) == __FILE__) || + f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile]) + end + end + spec.bindir = "exe" + spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) } + spec.require_paths = ["lib"] +end diff --git a/lib/inclusive.rb b/lib/inclusive.rb new file mode 100644 index 0000000..fd31171 --- /dev/null +++ b/lib/inclusive.rb @@ -0,0 +1,124 @@ +# frozen_string_literal: true + +require "set" + +require_relative "inclusive/version" + +# Include this in any class so you have access to the `packages` method (both class and instance). +module Inclusive + # You can extend a module with this in order to use `public_function`, which is the same as + # Ruby's native `module_function` except the instance method retains public visibility—a necessity + # for packaging via Inclusive. + module Public + def public_function(method_name) + module_function method_name + public method_name # reset back to public visibility + end + end + + extend Inclusive::Public + + # This is the base module which will be cloned for each individual import scenario. You should + # never need to reference this module directly. + module ModuleWithPackages + # Use this for the inline packages syntax. + # + # @example importing packages + # utils = packages[UtilitiesPackage, Another::Package] + # utils.make_it(:so) + def self.[](*packages) + packages.each { |package| extend_with_package(package) } + self + end + + 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 + + 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 + + def self.to_s = "#{name}<#{@package_names.join(", ")}>" + + def self.inspect = to_s + + def self.loaded_packages + singleton_class.included_modules.reverse.select { @package_names.include? _1.name } + end + + def self.package_methods + loaded_packages.flat_map(&:instance_methods) + end + end + + # This will extend your class by default if you `include Inclusive`, but if for some reason you + # don't want the `packages` instance method in your class, you can simply + # `extend Inclusive::Class` + module Class + # Use this as a decorator for an instance method which you will use to access your package + # imports. + # + # @example method definition + # packages def utilities = [Package1, Package2] + # + # def some_logic_here + # utilities.do_stuff # from Package1 + # utilities.convert(x) # from Package2 + # end + # + # This new method will be set to private, unless you use `public_packages` instead of `packages`. + # + # @return [void] + def packages(method_name) + old_method_name = :"__old_#{method_name}__" + ivar_name = :"@_#{method_name}" + + alias_method old_method_name, method_name + + define_method method_name do + return instance_variable_get(ivar_name) if instance_variable_defined?(ivar_name) + + packages_to_extend = send(old_method_name) + ModuleWithPackages.dup.tap do |mod| + mod.module_eval do + def self.name = "ModuleWithPackages" # preserve module name + end + packages_to_extend.each { |package| mod.extend_with_package(package) } + instance_variable_set(ivar_name, mod) + end + end + + private method_name unless __callee__ == :public_packages + end + + alias public_packages packages + end + + def self.included(klass) + klass.extend self::Class + end + + # Returns a blank module ready for package imports, useful for inline package access when an + # instance method is not suitable (perhaps you're in a template or block context). + # + # @return [ModuleWithPackages] + def packages = ModuleWithPackages.dup.tap do |mod| + mod.module_eval do + def self.name = "ModuleWithPackages" # preserve module name + end + end + + public_function :packages +end diff --git a/lib/inclusive/version.rb b/lib/inclusive/version.rb new file mode 100644 index 0000000..d228115 --- /dev/null +++ b/lib/inclusive/version.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +module Inclusive + VERSION = "1.0.0" +end diff --git a/test/test_helper.rb b/test/test_helper.rb new file mode 100644 index 0000000..c277138 --- /dev/null +++ b/test/test_helper.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +$LOAD_PATH.unshift File.expand_path("../lib", __dir__) +require "inclusive" + +require "minitest/autorun" +require "minitest/pride" diff --git a/test/test_inclusive.rb b/test/test_inclusive.rb new file mode 100644 index 0000000..3527168 --- /dev/null +++ b/test/test_inclusive.rb @@ -0,0 +1,64 @@ +# frozen_string_literal: true + +require "test_helper" + +module Package + module Math + extend Inclusive::Public + + # This takes a number and multiplies it by one hundred. + # + # @param int [Integer] + # @return [Integer] + def multiply_by_100(int) = int * 100 + + public_function :multiply_by_100 # optional, just here for testing purposes + end + + module Ownership + attr_accessor :owner + + def owner_classname + owner.class.name + end + end +end + +class TestInclusive < Minitest::Test + include Inclusive + + def test_that_it_has_a_version_number + refute_nil ::Inclusive::VERSION + end + + # @return [Package::Math] + packages def math = [Package::Math] + + def test_packages + assert_equal 400, math.multiply_by_100(4) + end + + def test_inline_packages + my_math = packages[Package::Math] + + assert_equal 800, my_math.multiply_by_100(8) + assert_equal my_math.method(:multiply_by_100).source_location, + Package::Math.method(:multiply_by_100).source_location + end + + def test_public_module_function + public_math = Inclusive.packages[Package::Math] + + assert_equal 1200, public_math.multiply_by_100(12) + end + + def test_package_ownership + bare_mod = Module.new do + extend Package::Ownership + end + ownership = Inclusive.packages[Package::Ownership].tap { _1.owner = self } + + assert_equal "TestInclusive", ownership.owner_classname + assert_equal "NilClass", bare_mod.owner_classname + end +end