gate 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +44 -0
- data/lib/gate/rails.rb +6 -1
- data/lib/gate/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 64401d6617c7ebcde128f5e283695475effec0be39a3089ed1a04cc9dd769ec3
|
4
|
+
data.tar.gz: 4f6192608d2110d1053d2cf1ab0b9afe1973cb65dc60bd556ac37d0d26defce7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
data/lib/gate/rails.rb
CHANGED
@@ -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)
|
data/lib/gate/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2018-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-validation
|