Primitive
This library contains the most root objects I found myself re-implementing over and over. It is meant to serve as an abstract base for object modeling a domain.
Installation
To install through Rubygems:
gem install primitive
You can also add this to your Gemfile using:
bundle add primitive
Primitive::Entity
Base class for objects identified by a string value (ID). Extension examples:
class Team < Primitive::Entity
attr_reader :name
def initialize(id:, name:)
super(id)
@name = name
end
end
class Player < Primitive::Entity
attr_reader :name
def initialize(name:)
super()
@name = name
end
end
Several features are now provided by its base-class via the ID attribute:
- Case-insensitive equality:
#eql?
and #==
- Object hashing:
#hash
- Sorting:
#<=>
- Outputting:
#to_s
Primitive::Repository
An interface that describes how a repository should function for loading/saving entities. A concrete example (albeit simple) is the Primitive::CompactFile
class which leverages YAML for serialization. Note that ID, in this case, is representative of the file path.
Contributing
Development Environment Configuration
Basic steps to take to get this repository compiling:
- Install Ruby (check primitive.gemspec for versions supported)
- Install bundler (gem install bundler)
- Clone the repository (git clone git@github.com:mattruggio/primitive.git)
- Navigate to the root folder (cd primitive)
- Install dependencies (bundle)
Running Tests
To execute the test suite run:
bin/rspec spec --format documentation
Alternatively, you can have Guard watch for changes:
bin/guard
Also, do not forget to run Rubocop:
bin/rubocop
And auditing the dependencies:
bin/bundler-audit check --update
And Sorbet:
bin/srb
Publishing
Note: ensure you have proper authorization before trying to publish new versions.
After code changes have successfully gone through the Pull Request review process then the following steps should be followed for publishing new versions:
- Merge Pull Request into main
- Update
version.rb
using semantic versioning - Install dependencies:
bundle
- Update
CHANGELOG.md
with release notes - Commit & push main to remote and ensure CI builds main successfully
- Run
bin/rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Code of Conduct
Everyone interacting in this codebase, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
License
This project is MIT Licensed.