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 +4 -4
- data/lib/mixture/coerce/array.rb +1 -0
- data/lib/mixture/coerce/boolean.rb +14 -0
- data/lib/mixture/coerce/float.rb +1 -0
- data/lib/mixture/coerce/hash.rb +1 -0
- data/lib/mixture/coerce/integer.rb +1 -0
- data/lib/mixture/coerce/nil.rb +1 -0
- data/lib/mixture/coerce/object.rb +1 -0
- data/lib/mixture/coerce/rational.rb +1 -0
- data/lib/mixture/coerce/set.rb +1 -0
- data/lib/mixture/coerce/string.rb +1 -0
- data/lib/mixture/types/boolean.rb +1 -0
- data/lib/mixture/version.rb +1 -1
- data/lib/mixture.rb +10 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 95cabd50c1d706133dba24ed86abdcf09ed87031
|
4
|
+
data.tar.gz: 0863af8affcc701628bc018238811f25dbd20ecb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f981a3f52d15b01f9516cc7f64b1c6121dce13150c08eae8df621dfd8a269b17920ee20858aff73be253c7613d05d376ee23ec96e49e6be96f94db407bc9b49
|
7
|
+
data.tar.gz: 2e40d5329d7b8966d01f270efd5f071923864f2755ab10d3fe51d3ca75a392a2e6ca2137353fb8b898ea906907e712f579e6ba8eb92e7819cd9e9d41abd28a28
|
data/lib/mixture/coerce/array.rb
CHANGED
@@ -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
|
data/lib/mixture/coerce/float.rb
CHANGED
@@ -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 }
|
data/lib/mixture/coerce/hash.rb
CHANGED
@@ -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 }
|
data/lib/mixture/coerce/nil.rb
CHANGED
@@ -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 }
|
data/lib/mixture/coerce/set.rb
CHANGED
@@ -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) }
|
data/lib/mixture/version.rb
CHANGED
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.
|
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-
|
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:
|