Hello World Hex Ruby is a simple Ruby gem that demonstrates the principles of Hexagonal Architecture (also known as Ports and Adaptors) using a "Hello World" example.
Add this line to your application's Gemfile:
gem 'hello_world_hex_ruby'
And then execute:
$ bundle install
Or install it yourself with:
$ gem sources --add https://USERNAME:TOKEN@rubygems.pkg.github.com/adambonsu/
$ gem install hello_world_hex_ruby
USERNAME
with your GitHub username.TOKEN
with your personal access token (classic).Here's an example of how to use the gem:
# Create an adaptor
console_adaptor = HelloWorldHexRuby::Adaptors::ConsoleUserInterface.new
# Create the core application with the adaptor
core = HelloWorldHexRuby::Core::HelloWorldCore.new(console_adaptor)
# Use the core application
core.say_hello("World") # Outputs: Hello, World!
# Use a different adaptor
file_adaptor = HelloWorldHexRuby::Adaptors::FileUserInterface.new(File.open('output.txt', 'w'))
core_with_file = HelloWorldHexRuby::Core::HelloWorldCore.new(file_adaptor)
core_with_file.say_hello("Ruby") # Writes "Hello, Ruby!" to output.txt
Hexagonal Architecture, also known as Ports and Adaptors, is a software design pattern that aims to create loosly coupled application components. It separates the core logic of an application from its external concerns.
Key components in this architecture are:
HelloWorldCore
)UserInterface
)ConsoleUserInterface
, FileUserInterface
)Benefits of this architecture include:
After checking out the repo, run bin/setup
to install dependencies. Then run rake spec
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 bundle exec rake install
.
To release a new version, update the version number in version.rb, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to the package repo
Bug reports and pull requests are welcome Github. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT Licence.
Everyone interacting in the HelloWorldHexRuby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.