gate 0.3.0 → 0.4.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: c1951613a4b68d99db41f71852db4e2b100ded40
4
- data.tar.gz: 1112aaf87c2fa1453e31be28aa38149b6ad167ed
3
+ metadata.gz: a99614096253f58fc609869e6b95d28a8643fbc2
4
+ data.tar.gz: 0cec6ed9368095959790395fbc670ae2bb16e79f
5
5
  SHA512:
6
- metadata.gz: 99c9230b9aae1f1cd7bd319ad08d93671423ab4bb11f807118a20139d4578eb420cd9399f147045025565ba3380474a6f362637957c4bc7af0bd227bc100863b
7
- data.tar.gz: ad095bcd11b76c9fa802fc8e0b145dd9d0086a0e0f466231809136bbbd7f9da111b817764f0daa5ed5a5689e4a504dd6ab80f516c343a194bbd08750a8d9f596
6
+ metadata.gz: 4c4148b37275f4fd92cf3303f407dbdc408506bd075e68447eb92d73a6359d5df91dc7c7fe19fce9887b90d9ab9cca53c3cb7997372a7c5394573087f360cd03
7
+ data.tar.gz: cac664ec646262b832f802997938583a6b0d348cd7e8c96d7d1eea7c9daeb938790a64edabe2b9bc00bf04a48e5a0ef7cd9da4e21881ca99cf047863b74ec80f
data/README.md CHANGED
@@ -34,6 +34,7 @@ gate = Gate.rules do
34
34
  required :message do
35
35
  required :title # :String by default
36
36
  optional :value, :Decimal
37
+ optional :anything, :Any # Just pass through original value
37
38
  end
38
39
  end
39
40
  ```
@@ -0,0 +1,7 @@
1
+ require 'coercible'
2
+
3
+ class Gate::Coercer::Any < Coercible::Coercer::Object
4
+ def to_any(value)
5
+ value
6
+ end
7
+ end
data/lib/gate/coercer.rb CHANGED
@@ -1,14 +1,13 @@
1
1
  module Gate
2
2
  class Coercer
3
3
  def initialize(engine, type, allow_nil: false)
4
- unless Axiom::Types.const_defined?(type)
4
+ unless coercible?(type)
5
5
  fail CoercionError, "Doesn't know how to coerce into #{type}"
6
6
  end
7
7
 
8
8
  @engine = engine
9
9
  @type = type
10
10
  @allow_nil = allow_nil
11
- @coercion_method = Axiom::Types.const_get(type).coercion_method
12
11
  end
13
12
 
14
13
  def coerce(input)
@@ -23,15 +22,25 @@ module Gate
23
22
 
24
23
  private
25
24
 
26
- attr_reader :engine, :type, :coercion_method
25
+ attr_reader :engine, :type
26
+
27
+ def coercible?(type)
28
+ type == :Any or Axiom::Types.const_defined?(type)
29
+ end
27
30
 
28
31
  def detect_input_type(input)
29
32
  case input
30
- when TrueClass, FalseClass, Array, Hash
33
+ when TrueClass, FalseClass, Array, Hash, Any
31
34
  input.class
32
35
  else
33
36
  String
34
37
  end
35
38
  end
39
+
40
+ def coercion_method
41
+ return :to_any if type == :Any
42
+
43
+ Axiom::Types.const_get(type).coercion_method
44
+ end
36
45
  end
37
46
  end
data/lib/gate/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Gate
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/gate.rb CHANGED
@@ -14,6 +14,7 @@ require "forwardable"
14
14
  require "set"
15
15
 
16
16
  require "gate/coercer"
17
+ require "gate/coercer/any"
17
18
  require "gate/configuration"
18
19
  require "gate/guard"
19
20
  require "gate/result"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gate
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Dudulski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-07 00:00:00.000000000 Z
11
+ date: 2015-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: coercible
@@ -129,6 +129,7 @@ files:
129
129
  - gate.gemspec
130
130
  - lib/gate.rb
131
131
  - lib/gate/coercer.rb
132
+ - lib/gate/coercer/any.rb
132
133
  - lib/gate/configuration.rb
133
134
  - lib/gate/guard.rb
134
135
  - lib/gate/result.rb
@@ -153,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
154
  version: '0'
154
155
  requirements: []
155
156
  rubyforge_project:
156
- rubygems_version: 2.4.5
157
+ rubygems_version: 2.4.5.1
157
158
  signing_key:
158
159
  specification_version: 4
159
160
  summary: Handling user input with ease