10000 GitHub - tonchis/silueta: Initialize an object with a hash of attributes
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

tonchis/silueta

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

silueta

Initialize an object with a hash of attributes.

Inspir 7075 ed 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

About

Initialize an object with a hash of attributes

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 97.1%
  • Makefile 2.9%
0