silueta 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 861f624f086c94b01e49297657e796b2915d9bc3
4
- data.tar.gz: f507a9d070094296b797ba3da57470e4db9049b4
3
+ metadata.gz: bf4b70b89569a496369172703eb371b7c7e00003
4
+ data.tar.gz: 0b375e1a1976e7a97f24dd726d8b1207944a0518
5
5
  SHA512:
6
- metadata.gz: 80870d7eb943d9217eed3c5b1662abcbfdf229be155b8eb6137573b33c0d83e44462a7a780689e776b8d3ca4c218d14bec0e9520b4aaa501ae0344f4215765e6
7
- data.tar.gz: ea7079586d196fd058e7c881912a7f1c6d8e2efc2751a4438e38df2f06752bb31e463c467c45ebcaea1daf4776737be2f12340d915304a54c417a86a83f77701
6
+ metadata.gz: ac673c19f062c080a51fe6f3557b94af9c5fe8d273b98e436033926de7035ab071418ddee921c6bcb684aed453106462087c0f76b66ab7252684e88224df6819
7
+ data.tar.gz: 31fbc471673c0501a43cb276b89cd4d5e77e511b23fd1270ce6ad7b3ffdc971eb309f919f328bbc17c124708e76ca791455d2a77ec7d57d69a9f1fc319fe0206
data/README.md CHANGED
@@ -8,6 +8,7 @@ Inspired by [Ohm's](https://github.com/soveran/ohm) attribute system.
8
8
 
9
9
  ```ruby
10
10
  require "silueta"
11
+ require "silueta/types"
11
12
 
12
13
  class User
13
14
  include Silueta
@@ -16,6 +17,7 @@ class User
16
17
  attribute :last_name
17
18
  attribute :email
18
19
  attribute :age, cast: ->(x) { x && x.to_i }
20
+ attribute :friends, cast: Types::Integer
19
21
  end
20
22
 
21
23
  user = User.new(
@@ -31,12 +33,20 @@ user.email # => "jane@mail.com"
31
33
  user.age = "25"
32
34
  user.age # => 25
33
35
 
36
+ user.friends = "5"
37
+ user.friends # => 5
38
+
34
39
  user.attributes
35
- # => {:first_name=>"Jane", :last_name=>"Doe", :email=>"jane@mail.com", :age=>25 }
40
+ # => {:first_name=>"Jane", :last_name=>"Doe", ... }
41
+
36
42
  ```
37
43
 
44
+ See all types supported by Silueta [here][types].
45
+
38
46
  ## Installation
39
47
 
40
48
  ```
41
49
  $ gem install silueta
42
50
  ```
51
+
52
+ [types]: https://github.com/harmoni/silueta/blob/master/lib/silueta/types.rb
@@ -0,0 +1,12 @@
1
+ require "bigdecimal"
2
+
3
+ module Silueta
4
+ module Types
5
+ Integer = ->(x) { x && Integer(x) }
6
+ Decimal = ->(x) { x && BigDecimal(x.to_s) }
7
+ Float = ->(x) { x && Float(x) }
8
+ String = ->(x) { x && String(x) }
9
+ Symbol = ->(x) { x && x.to_sym }
10
+ Boolean = ->(x) { x && true }
11
+ end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Silueta
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,51 @@
1
+ require "bundler/setup"
2
+ require "cutest"
3
+ require_relative "../lib/silueta"
4
+ require_relative "../lib/silueta/types"
5
+
6
+ class Product
7
+ include Silueta
8
+
9
+ attribute :item_number, cast: Types::String
10
+ attribute :stock, cast: Types::Integer
11
+ attribute :price, cast: Types::Decimal
12
+ attribute :rating, cast: Types::Float
13
+ attribute :published, cast: Types::Boolean
14
+ attribute :state, cast: Types::Symbol
15
+ end
16
+
17
+ test "String" do
18
+ product = Product.new(item_number: 12345678)
19
+
20
+ assert product.item_number.kind_of?(String)
21
+ end
22
+
23
+ test "Integer" do
24
+ product = Product.new(stock: "1")
25
+
26
+ assert product.stock.kind_of?(Integer)
27
+ end
28
+
29
+ test "Decimal" do
30
+ product = Product.new(price: 0.001)
31
+
32
+ assert product.price.kind_of?(BigDecimal)
33
+ end
34
+
35
+ test "Float" do
36
+ product = Product.new(rating: "4.5")
37
+
38
+ assert product.rating.kind_of?(Float)
39
+ end
40
+
41
+ test "Boolean" do
42
+ product = Product.new(published: "1")
43
+
44
+ assert product.published.kind_of?(TrueClass)
45
+ end
46
+
47
+ test "Symbol" do
48
+ product = Product.new(state: "available")
49
+
50
+ assert product.state.kind_of?(Symbol)
51
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: silueta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mayn Ektvedt Kjær
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-31 00:00:00.000000000 Z
11
+ date: 2015-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -50,10 +50,12 @@ files:
50
50
  - LICENSE
51
51
  - README.md
52
52
  - lib/silueta.rb
53
+ - lib/silueta/types.rb
53
54
  - lib/silueta/version.rb
54
55
  - makefile
55
56
  - silueta.gemspec
56
57
  - test/silueta_test.rb
58
+ - test/types_test.rb
57
59
  homepage: https://github.com/harmoni/silueta
58
60
  licenses:
59
61
  - MIT