pragma-contract 0.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +17 -7
- data/Gemfile +2 -0
- data/README.md +3 -3
- data/lib/pragma/contract.rb +2 -0
- data/lib/pragma/contract/base.rb +5 -35
- data/lib/pragma/contract/coercion.rb +54 -0
- data/lib/pragma/contract/types.rb +1 -3
- data/lib/pragma/contract/version.rb +2 -1
- data/pragma-contract.gemspec +15 -14
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 662694b3635eb7a13110e1704914cccff1b57aa5
|
4
|
+
data.tar.gz: 996a5b17c73f47ea46732e51e1465df0e6feb50d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de3a06fa0917e9172eaf150b752c829c7fbffc52641e00816b97b9e40c51c4ac9912ae3611af77bd39fd150488e3eff932c9533b221f719f661beecf6e942dce
|
7
|
+
data.tar.gz: 4611ed1f0ae41f68ad98831fdee4824d80aa7ea2d5bf6e923d5960b180d9e47592b9049fd7e9161c6127fb69ec38800e41c4a0a270e585f5c64b69ba868ad3ed
|
data/.rubocop.yml
CHANGED
@@ -24,26 +24,26 @@ Style/BlockDelimiters:
|
|
24
24
|
Exclude:
|
25
25
|
- 'spec/**/*'
|
26
26
|
|
27
|
-
|
27
|
+
Layout/AlignParameters:
|
28
28
|
EnforcedStyle: with_fixed_indentation
|
29
29
|
|
30
|
-
|
30
|
+
Layout/ClosingParenthesisIndentation:
|
31
31
|
Enabled: false
|
32
32
|
|
33
33
|
Metrics/LineLength:
|
34
34
|
Max: 100
|
35
35
|
AllowURI: true
|
36
36
|
|
37
|
-
|
37
|
+
Layout/FirstParameterIndentation:
|
38
38
|
Enabled: false
|
39
39
|
|
40
|
-
|
40
|
+
Layout/MultilineMethodCallIndentation:
|
41
41
|
EnforcedStyle: indented
|
42
42
|
|
43
|
-
|
43
|
+
Layout/IndentArray:
|
44
44
|
EnforcedStyle: consistent
|
45
45
|
|
46
|
-
|
46
|
+
Layout/IndentHash:
|
47
47
|
EnforcedStyle: consistent
|
48
48
|
|
49
49
|
Style/SignalException:
|
@@ -53,7 +53,7 @@ Style/BracesAroundHashParameters:
|
|
53
53
|
EnforcedStyle: context_dependent
|
54
54
|
|
55
55
|
Lint/EndAlignment:
|
56
|
-
|
56
|
+
EnforcedStyleAlignWith: variable
|
57
57
|
AutoCorrect: true
|
58
58
|
|
59
59
|
Style/AndOr:
|
@@ -67,3 +67,13 @@ RSpec/NamedSubject:
|
|
67
67
|
|
68
68
|
RSpec/ExampleLength:
|
69
69
|
Enabled: false
|
70
|
+
|
71
|
+
Metrics/BlockLength:
|
72
|
+
Enabled: False
|
73
|
+
|
74
|
+
Style/Documentation:
|
75
|
+
Enabled: false
|
76
|
+
|
77
|
+
Style/FileName:
|
78
|
+
Exclude:
|
79
|
+
- '*.gemspec'
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -36,7 +36,7 @@ To create a contract, simply inherit from `Pragma::Contract::Base`:
|
|
36
36
|
```ruby
|
37
37
|
module API
|
38
38
|
module V1
|
39
|
-
module
|
39
|
+
module Article
|
40
40
|
module Contract
|
41
41
|
class Base < Pragma::Contract::Base
|
42
42
|
property :title
|
@@ -62,7 +62,7 @@ You can access types with the `Pragma::Contract::Types` module.
|
|
62
62
|
```ruby
|
63
63
|
module API
|
64
64
|
module V1
|
65
|
-
module
|
65
|
+
module Article
|
66
66
|
module Contract
|
67
67
|
class Base < Pragma::Contract::Base
|
68
68
|
property :title, type: Pragma::Contract::Types::Coercible::String
|
@@ -80,7 +80,7 @@ Helpers are also provided as a shorthand syntax:
|
|
80
80
|
```ruby
|
81
81
|
module API
|
82
82
|
module V1
|
83
|
-
module
|
83
|
+
module Article
|
84
84
|
module Contract
|
85
85
|
class Base < Pragma::Contract::Base
|
86
86
|
property :title, type: coercible(:string)
|
data/lib/pragma/contract.rb
CHANGED
data/lib/pragma/contract/base.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
require 'reform/form/coercion'
|
3
4
|
require 'reform/form/dry'
|
4
5
|
|
@@ -10,42 +11,11 @@ module Pragma
|
|
10
11
|
#
|
11
12
|
# @author Alessandro Desantis
|
12
13
|
class Base < Reform::Form
|
13
|
-
feature Coercion
|
14
|
-
feature Dry
|
15
|
-
|
16
|
-
class << self
|
17
|
-
protected
|
18
|
-
|
19
|
-
def strict(type)
|
20
|
-
build_type 'Strict', type
|
21
|
-
end
|
22
|
-
|
23
|
-
def coercible(type)
|
24
|
-
build_type 'Coercible', type
|
25
|
-
end
|
26
|
-
|
27
|
-
def form(type)
|
28
|
-
build_type 'Form', type
|
29
|
-
end
|
30
|
-
|
31
|
-
def json(type)
|
32
|
-
build_type 'Json', type
|
33
|
-
end
|
34
|
-
|
35
|
-
def maybe_strict(type)
|
36
|
-
build_type 'Maybe::Strict', type
|
37
|
-
end
|
38
|
-
|
39
|
-
def maybe_coercible(type)
|
40
|
-
build_type 'Maybe::Coercible', type
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
14
|
+
feature Reform::Form::Coercion
|
15
|
+
feature Reform::Form::Dry
|
16
|
+
include Pragma::Contract::Coercion
|
44
17
|
|
45
|
-
|
46
|
-
Object.const_get "Pragma::Contract::Types::#{namespace}::#{type.to_s.capitalize}"
|
47
|
-
end
|
48
|
-
end
|
18
|
+
property :current_user, virtual: true
|
49
19
|
end
|
50
20
|
end
|
51
21
|
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pragma
|
4
|
+
module Contract
|
5
|
+
module Coercion
|
6
|
+
def self.included(klass)
|
7
|
+
klass.extend ClassMethods
|
8
|
+
end
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def property(*args, &block)
|
12
|
+
if block_given?
|
13
|
+
super(*args) do
|
14
|
+
include Pragma::Contract::Coercion
|
15
|
+
instance_eval(&block)
|
16
|
+
end
|
17
|
+
else
|
18
|
+
super(*args)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def strict(type)
|
25
|
+
build_type 'Strict', type
|
26
|
+
end
|
27
|
+
|
28
|
+
def coercible(type)
|
29
|
+
build_type 'Coercible', type
|
30
|
+
end
|
31
|
+
|
32
|
+
def form(type)
|
33
|
+
build_type 'Form', type
|
34
|
+
end
|
35
|
+
|
36
|
+
def json(type)
|
37
|
+
build_type 'Json', type
|
38
|
+
end
|
39
|
+
|
40
|
+
def maybe_strict(type)
|
41
|
+
build_type 'Maybe::Strict', type
|
42
|
+
end
|
43
|
+
|
44
|
+
def maybe_coercible(type)
|
45
|
+
build_type 'Maybe::Coercible', type
|
46
|
+
end
|
47
|
+
|
48
|
+
def build_type(namespace, type)
|
49
|
+
Object.const_get "Pragma::Contract::Types::#{namespace}::#{type.to_s.capitalize}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/pragma-contract.gemspec
CHANGED
@@ -1,33 +1,34 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
2
3
|
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
5
|
require 'pragma/contract/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'pragma-contract'
|
8
9
|
spec.version = Pragma::Contract::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
10
|
+
spec.authors = ['Alessandro Desantis']
|
11
|
+
spec.email = ['desa.alessandro@gmail.com']
|
11
12
|
|
12
13
|
spec.summary = 'Form objects on steroids for your HTTP API.'
|
13
|
-
spec.homepage =
|
14
|
-
spec.license =
|
14
|
+
spec.homepage = 'https://github.com/pragmarb/pragma-contract'
|
15
|
+
spec.license = 'MIT'
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
17
18
|
f.match(%r{^(test|spec|features)/})
|
18
19
|
end
|
19
|
-
spec.bindir =
|
20
|
+
spec.bindir = 'exe'
|
20
21
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
-
spec.require_paths = [
|
22
|
+
spec.require_paths = ['lib']
|
22
23
|
|
23
24
|
spec.add_dependency 'reform', '~> 2.2'
|
24
25
|
spec.add_dependency 'dry-types', '~> 0.9'
|
25
26
|
spec.add_dependency 'dry-validation', '~> 0.10'
|
26
27
|
|
27
|
-
spec.add_development_dependency
|
28
|
-
spec.add_development_dependency
|
29
|
-
spec.add_development_dependency
|
30
|
-
spec.add_development_dependency
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
28
|
+
spec.add_development_dependency 'bundler'
|
29
|
+
spec.add_development_dependency 'rake'
|
30
|
+
spec.add_development_dependency 'rspec'
|
31
|
+
spec.add_development_dependency 'rubocop'
|
32
|
+
spec.add_development_dependency 'rubocop-rspec'
|
33
|
+
spec.add_development_dependency 'coveralls'
|
33
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pragma-contract
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alessandro Desantis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-09-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: reform
|
@@ -155,6 +155,7 @@ files:
|
|
155
155
|
- bin/setup
|
156
156
|
- lib/pragma/contract.rb
|
157
157
|
- lib/pragma/contract/base.rb
|
158
|
+
- lib/pragma/contract/coercion.rb
|
158
159
|
- lib/pragma/contract/types.rb
|
159
160
|
- lib/pragma/contract/version.rb
|
160
161
|
- pragma-contract.gemspec
|
@@ -178,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
179
|
version: '0'
|
179
180
|
requirements: []
|
180
181
|
rubyforge_project:
|
181
|
-
rubygems_version: 2.
|
182
|
+
rubygems_version: 2.6.13
|
182
183
|
signing_key:
|
183
184
|
specification_version: 4
|
184
185
|
summary: Form objects on steroids for your HTTP API.
|