No release in over 3 years
Low commit activity in last 3 years
ValueObject pattern realized in scope of Ruby.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 2.2
~> 0.13
~> 13.0
~> 3.10
~> 0.21

Runtime

 Project Readme

SmartCore::ValueObject · Supported by Cado Labs · Gem Version

Value Object pattern realized in scope of Ruby.


Supported by Cado Labs


Major features

  • attribute and property semantics;
  • primitive immutability based on #freeze invocation;
  • read-only instance attributes and properties;
  • support for hash representation (other formats coming soon);
  • support for:
    • semantic comparability (Comparable, #<=>, #eql?) (based on object's type and object's attributes and parameters);
    • semantic enumerability (Enumerable, #each) (enumerates itself by default);
    • (soon) #clone and #dup;

Installation

gem 'smart_value-object'
bundle install
# --- or ---
gem install smart_value-object
require 'smart_core/value-object'

Synopsis

class Address < SmartCore::ValueObject
  attribute :country, 'value.string' # an alias of SmartCore::Types::Value::String (see smart_initializer gem)
  attribute :city,    'value.string'
  property :location, 'value.string'
  property :capital,  SmartCore::Types::Value::Boolean
end

khabarovsk = Address.new('Russia', 'Khabarovsk', location: '48.4814/135.0721', capital: false)
same_city = Address.new('Russia', 'Khabarovsk', location: '48.4814/135.0721', capital: false)
another_city = Address.new('Russia', 'Moscow', location: '59.9311/30.3609', capital: false)
khabarovsk.frozen? # => true
khabarovsk.country # => 'Russia'
khabarovsk.city # => 'Khabarovsk'
khabarovsk.location # => '48.4814/135.0721'
khabarovsk.capital # => false
khabarovsk.to_h # or #as_hash or #to_hash
# => returns:
{ city: 'Russia', country: 'Khabarovsk', location: '48.4814/135.0721', capital: false }
# comparability:
khabarovsk == same_city # => true
khabarovsk == another_city # => false
# default Enumerable behavior:
khabarovsk.to_a # => [khabarovsk]
khabarovsk.each { |entity| puts entity } # => outputs itself

Roadmap

  • Migrate to GitHub Actions;

Build

  • run tests:
bundle exec rspec
  • run code style checks:
bundle exec rubocop
  • run code style checks with auto-correction:
bundle exec rubocop -A

Contributing

  • Fork it ( https://github.com/smart-rb/smart_value-object )
  • Create your feature branch (git checkout -b feature/my-new-feature)
  • Commit your changes (git commit -am '[feature_context] Add some feature')
  • Push to the branch (git push origin feature/my-new-feature)
  • Create new Pull Request

License

Released under MIT License.

Supporting

Supported by Cado Labs

Authors

Rustam Ibragimov