gate 0.9.0 → 0.10.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
  SHA256:
3
- metadata.gz: c22d3f53ed88e1d283f720231af1c4a8021a1be6e0a622344b6060cf5b205f21
4
- data.tar.gz: d796d15296a46a91024811b362338d35c53dca326955f561609861518a0844ec
3
+ metadata.gz: 64401d6617c7ebcde128f5e283695475effec0be39a3089ed1a04cc9dd769ec3
4
+ data.tar.gz: 4f6192608d2110d1053d2cf1ab0b9afe1973cb65dc60bd556ac37d0d26defce7
5
5
  SHA512:
6
- metadata.gz: d3ec912ce725441be96af00f68272dc069be63c035e26999d2d8c63ae3376402b9960d66646ae0891b87614d8c28c7f96f95ed77cba38b85965e73f25cb43fa2
7
- data.tar.gz: 4e9eaf0e4c2bde5ed8ae01815e62737622f4bfba29ef6e045e1c9ae3fc163224996d213c35feb5ff1d695cb9ee50d47b25ad2cbf65e905e5feb79cc6ce97ccf1
6
+ metadata.gz: 76c705ee8b4c09b172b73433487376781683fb1b6619168ad1972557046f2e6f4d831e776ffd91746f4b9b17a2f36a7b6831768453208a61857076602f991b8d
7
+ data.tar.gz: 0bf7be2a899cf05f60eeaea97703944ed563f4f7e5dd46565e77858455d65832ed21a11f50dd8b774ca56df8d3db3ae722e9554df47bd3d097349134c68c32a9
data/README.md CHANGED
@@ -89,6 +89,50 @@ class ExampleController < ActionController::Base
89
89
  end
90
90
  ```
91
91
 
92
+ ## Configuration
93
+
94
+ Gate gives a possibility to create global, inherited configuration and separated setup in each one schema definition.
95
+
96
+ ### Inheriting base setup
97
+
98
+ In order to configure the library according to the whole application, create a file under `config/initializers/gate.rb`. There is a possibility of creating a base configuration, defining shared, custom predicates and a lot more useful things. The full list of supported configuration options is consistent with available options in [dry-validation](https://dry-rb.org/gems/dry-validation/) gem.
99
+
100
+ ```ruby
101
+ Gate::Rails.configure do
102
+ configure do |config|
103
+ config.messages_file = Rails.root.join("config", "locales" "en.yml")
104
+
105
+ predicates(SharedPredicates)
106
+
107
+ def foo?(value)
108
+ value == "FOO"
109
+ end
110
+ end
111
+ end
112
+ ```
113
+
114
+ ### Separated setup
115
+
116
+ Sometimes there is a requirement to have a very specific configuration or behaviour in a one schema validation. The easiest way is to do it in a special `configure` block.
117
+
118
+ ```ruby
119
+ class DoSomethingCommand
120
+ include Gate::Command
121
+
122
+ schema do
123
+ configure do
124
+ config.messages_file = Rails.root.join("config", "locales" "special_en.yml")
125
+ predicates(SharedPredicates)
126
+ end
127
+ required(:id).filled
128
+ required(:message).schema do
129
+ required(:title).filled
130
+ optional(:value).maybe(:decimal?)
131
+ end
132
+ end
133
+ end
134
+ ```
135
+
92
136
  ## Development
93
137
 
94
138
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -5,11 +5,16 @@ module Gate
5
5
  attr_reader :validated_params
6
6
 
7
7
  SchemaNotDefined = Class.new(StandardError)
8
+ @base_schema = nil
8
9
 
9
10
  def self.included(base)
10
11
  base.send(:extend, ClassMethods)
11
12
  end
12
13
 
14
+ def self.configure(&block)
15
+ @base_schema = Class.new(Dry::Validation::Schema, &block)
16
+ end
17
+
13
18
  module ClassMethods
14
19
  def params_schemas
15
20
  @params_schemas ||= {}
@@ -22,7 +27,7 @@ module Gate
22
27
  end
23
28
 
24
29
  def def_schema(&block)
25
- @_schema = Dry::Validation.Params(&block)
30
+ @_schema = Dry::Validation.Params(Gate::Rails::instance_variable_get(:@base_schema), &block)
26
31
  end
27
32
 
28
33
  def method_added(method_name)
@@ -1,3 +1,3 @@
1
1
  module Gate
2
- VERSION = "0.9.0"
2
+ VERSION = "0.10.0"
3
3
  end
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.9.0
4
+ version: 0.10.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: 2018-06-18 00:00:00.000000000 Z
11
+ date: 2018-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-validation