Project

silueta

0.0
No commit activity in last 3 years
No release in over 3 years
Initialize an object with a hash of attributes
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.2
 Project Readme

silueta

Initialize an object with a hash of attributes.

Inspired by Ohm's attribute system.

Usage

require "silueta"
require "silueta/types"

class User
  include Silueta

  attribute :first_name
  attribute :last_name
  attribute :email
  attribute :age, cast: ->(x) { x && x.to_i }
  attribute :friends, cast: Types::Integer
end

user = User.new(
  first_name: "Jane",
  last_name: "Doe",
  email: "jane@mail.com"
)

user.first_name # => "Jane"
user.last_name # => "Doe"
user.email # => "jane@mail.com"

user.age = "25"
user.age # => 25

user.friends = "5"
user.friends # => 5

user.attributes
# => {:first_name=>"Jane", :last_name=>"Doe", ... }

See all types supported by Silueta here.

Contributing

  • Fork the project.
  • Use make install to install dependencies.
  • Use make test to run the test suite.
  • Create a pull request with your changes.

Installation

$ gem install silueta