Giter Site home page Giter Site logo

smart_value-object's Introduction

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

smart_value-object's People

Contributors

0exp avatar egorbarakhov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.