mixture 0.5.1 → 0.6.0

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: e1e558743b9d8f1d1f09e6c6c1b0d4e7538899af
4
- data.tar.gz: 480dceba4398548eaca958595e179ebdcb9cfea3
3
+ metadata.gz: 95cabd50c1d706133dba24ed86abdcf09ed87031
4
+ data.tar.gz: 0863af8affcc701628bc018238811f25dbd20ecb
5
5
  SHA512:
6
- metadata.gz: 1347606586ddd8eb0dfab2801ee28255f37b6fbcfcc7edf84ae91290e7fb39574f4f5cb5016ab1c56946a7a64226471595819ee6fd5c969e8f4f0a0a27ba7bc8
7
- data.tar.gz: 3f21402c2c17caa3ff49d886330553335dff85e2f6763adf7083f1fe8ab2364c8b9bbdd50120df424e364398b385b26e13acfeddf9871bce643f095df18b6f05
6
+ metadata.gz: 1f981a3f52d15b01f9516cc7f64b1c6121dce13150c08eae8df621dfd8a269b17920ee20858aff73be253c7613d05d376ee23ec96e49e6be96f94db407bc9b49
7
+ data.tar.gz: 2e40d5329d7b8966d01f270efd5f071923864f2755ab10d3fe51d3ca75a392a2e6ca2137353fb8b898ea906907e712f579e6ba8eb92e7819cd9e9d41abd28a28
@@ -7,6 +7,7 @@ module Mixture
7
7
  type Types::Array
8
8
 
9
9
  coerce_to(Types::Object, Itself)
10
+ coerce_to(Types::Boolean, :any?)
10
11
 
11
12
  coerce_to(Types::Array) do |value, type|
12
13
  member = type.options.fetch(:members).first
@@ -0,0 +1,14 @@
1
+ # encoding: utf-8
2
+
3
+ module Mixture
4
+ module Coerce
5
+ # Handles coercion of the boolean classes.
6
+ class Boolean < Base
7
+ type Types::Array
8
+
9
+ coerce_to(Types::Object, Itself)
10
+ coerce_to(Types::Boolean, Itself)
11
+ coerce_to(Types::Integer) { |value| value ? 1 : 0 }
12
+ end
13
+ end
14
+ end
@@ -11,6 +11,7 @@ module Mixture
11
11
  coerce_to(Types::Float, Itself)
12
12
  coerce_to(Types::Integer, :to_i)
13
13
  coerce_to(Types::Rational, :to_r)
14
+ coerce_to(Types::Boolean) { |value| !value.zero? }
14
15
  coerce_to(Types::Time) { |value| ::Time.at(value) }
15
16
  coerce_to(Types::Date) { |value| ::Time.at(value).to_date }
16
17
  coerce_to(Types::DateTime) { |value| ::Time.at(value).to_datetime }
@@ -7,6 +7,7 @@ module Mixture
7
7
  type Types::Hash
8
8
 
9
9
  coerce_to(Types::Object, Itself)
10
+ coerce_to(Types::Boolean, :any?)
10
11
 
11
12
  coerce_to(Types::Hash) do |value, type|
12
13
  members = type.options.fetch(:members)
@@ -11,6 +11,7 @@ module Mixture
11
11
  coerce_to(Types::Float, :to_f)
12
12
  coerce_to(Types::Rational, :to_r)
13
13
  coerce_to(Types::Integer, Itself)
14
+ coerce_to(Types::Boolean) { |value| !value.zero? }
14
15
  coerce_to(Types::Time) { |value| ::Time.at(value) }
15
16
  coerce_to(Types::Date) { |value| ::Time.at(value).to_date }
16
17
  coerce_to(Types::DateTime) { |value| ::Time.at(value).to_datetime }
@@ -8,6 +8,7 @@ module Mixture
8
8
 
9
9
  coerce_to(Types::Object, Itself)
10
10
  coerce_to(Types::Nil, Itself)
11
+ coerce_to(Types::Boolean, Refute)
11
12
  coerce_to(Types::String) { "" }
12
13
  coerce_to(Types::Array) { [] }
13
14
  coerce_to(Types::Float) { 0.0 }
@@ -22,6 +22,7 @@ module Mixture
22
22
  end
23
23
 
24
24
  coerce_to(Types::Object, Itself)
25
+ coerce_to(Types::Boolean, Prove)
25
26
  coerce_to(Types::Array, TryMethods[:to_a, :to_ary, :to_array])
26
27
  coerce_to(Types::Date, TryMethods[:to_date])
27
28
  coerce_to(Types::DateTime, TryMethods[:to_datetime])
@@ -8,6 +8,7 @@ module Mixture
8
8
 
9
9
  coerce_to(Types::Object, Itself)
10
10
  coerce_to(Types::Rational, Itself)
11
+ coerce_to(Types::Boolean) { |value| !value.zero? }
11
12
  coerce_to(Types::Time) { |value| ::Time.at(value) }
12
13
  coerce_to(Types::Date) { |value| ::Time.at(value).to_date }
13
14
  coerce_to(Types::DateTime) { |value| ::Time.at(value).to_datetime }
@@ -7,6 +7,7 @@ module Mixture
7
7
  type Types::Set
8
8
 
9
9
  coerce_to(Types::Object, Itself)
10
+ coerce_to(Types::Boolean, :any?)
10
11
 
11
12
  coerce_to(Types::Set) do |value, type|
12
13
  member = type.options.fetch(:members).first
@@ -11,6 +11,7 @@ module Mixture
11
11
  coerce_to(Types::Symbol, :to_sym)
12
12
  coerce_to(Types::Integer, :to_i)
13
13
  coerce_to(Types::Float, :to_f)
14
+ coerce_to(Types::Boolean) { |value| !value.empty? }
14
15
  coerce_to(Types::Time) { |value| ::Time.parse(value) }
15
16
  coerce_to(Types::Date) { |value| ::Date.parse(value) }
16
17
  coerce_to(Types::DateTime) { |value| ::DateTime.parse(value) }
@@ -10,6 +10,7 @@ module Mixture
10
10
  class Boolean < Object
11
11
  register
12
12
  options[:primitive] = nil
13
+ options[:method] = :to_boolean
13
14
  as :bool, :boolean, true, false
14
15
 
15
16
  constraints.clear
@@ -5,5 +5,5 @@ module Mixture
5
5
  # The current version of Mixture.
6
6
  #
7
7
  # @return [String]
8
- VERSION = "0.5.1"
8
+ VERSION = "0.6.0"
9
9
  end
data/lib/mixture.rb CHANGED
@@ -27,6 +27,16 @@ module Mixture
27
27
  # @return [Proc{(Object) => Object}]
28
28
  Itself = proc { |value| value }
29
29
 
30
+ # A proc that returns true.
31
+ #
32
+ # @return [Proc{() => true}]
33
+ Prove = proc { true }
34
+
35
+ # A proc that returns false.
36
+ #
37
+ # @return [Proc{() => false}]
38
+ Refute = proc { false }
39
+
30
40
  # Finalizes all of the Mixture modules.
31
41
  #
32
42
  # @return [void]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mixture
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Rodi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-26 00:00:00.000000000 Z
11
+ date: 2015-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -90,6 +90,7 @@ files:
90
90
  - lib/mixture/coerce.rb
91
91
  - lib/mixture/coerce/array.rb
92
92
  - lib/mixture/coerce/base.rb
93
+ - lib/mixture/coerce/boolean.rb
93
94
  - lib/mixture/coerce/class.rb
94
95
  - lib/mixture/coerce/date.rb
95
96
  - lib/mixture/coerce/datetime.rb
@@ -167,3 +168,4 @@ signing_key:
167
168
  specification_version: 4
168
169
  summary: Handle validation, coercion, and attributes.
169
170
  test_files: []
171
+ has_rdoc: