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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9c118ad0fbcea335eee361aa0760db1a996d9369
4
- data.tar.gz: 4d76ee82b1672ba284c875d3b1ddf15667c836cd
3
+ metadata.gz: 662694b3635eb7a13110e1704914cccff1b57aa5
4
+ data.tar.gz: 996a5b17c73f47ea46732e51e1465df0e6feb50d
5
5
  SHA512:
6
- metadata.gz: e7051799891c50fa759c84e759659df93406d138a3b04000c1835bc183fe79e3080f24522e4e7e253b2b247b42142f1729f02ab295f2efb78ecced91330786fc
7
- data.tar.gz: 3ec1278a66a617df022b9f79329c4641aa659b029f861aae221e69fc134e77d1da1d5adce25bdbbe33a3673c939b5c41426921cd8fe5ecf7894aef244dfafd94
6
+ metadata.gz: de3a06fa0917e9172eaf150b752c829c7fbffc52641e00816b97b9e40c51c4ac9912ae3611af77bd39fd150488e3eff932c9533b221f719f661beecf6e942dce
7
+ data.tar.gz: 4611ed1f0ae41f68ad98831fdee4824d80aa7ea2d5bf6e923d5960b180d9e47592b9049fd7e9161c6127fb69ec38800e41c4a0a270e585f5c64b69ba868ad3ed
@@ -24,26 +24,26 @@ Style/BlockDelimiters:
24
24
  Exclude:
25
25
  - 'spec/**/*'
26
26
 
27
- Style/AlignParameters:
27
+ Layout/AlignParameters:
28
28
  EnforcedStyle: with_fixed_indentation
29
29
 
30
- Style/ClosingParenthesisIndentation:
30
+ Layout/ClosingParenthesisIndentation:
31
31
  Enabled: false
32
32
 
33
33
  Metrics/LineLength:
34
34
  Max: 100
35
35
  AllowURI: true
36
36
 
37
- Style/FirstParameterIndentation:
37
+ Layout/FirstParameterIndentation:
38
38
  Enabled: false
39
39
 
40
- Style/MultilineMethodCallIndentation:
40
+ Layout/MultilineMethodCallIndentation:
41
41
  EnforcedStyle: indented
42
42
 
43
- Style/IndentArray:
43
+ Layout/IndentArray:
44
44
  EnforcedStyle: consistent
45
45
 
46
- Style/IndentHash:
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
- AlignWith: variable
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
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in pragma-contract.gemspec
4
4
  gemspec
5
+
6
+ gem 'pry'
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 Post
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 Post
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 Post
83
+ module Article
84
84
  module Contract
85
85
  class Base < Pragma::Contract::Base
86
86
  property :title, type: coercible(:string)
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  require 'dry-validation'
3
4
  require 'dry-types'
4
5
  require 'reform'
5
6
 
6
7
  require 'pragma/contract/version'
8
+ require 'pragma/contract/coercion'
7
9
  require 'pragma/contract/base'
8
10
  require 'pragma/contract/types'
9
11
 
@@ -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
- def build_type(namespace, type)
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
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Pragma
3
4
  module Contract
4
- # This module provides access to coercion types.
5
- #
6
- # @author Alessandro Desantis
7
5
  module Types
8
6
  include Dry::Types.module
9
7
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Pragma
3
4
  module Contract
4
- VERSION = '0.1.0'
5
+ VERSION = '2.0.0'
5
6
  end
6
7
  end
@@ -1,33 +1,34 @@
1
- # coding: utf-8
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 = "pragma-contract"
8
+ spec.name = 'pragma-contract'
8
9
  spec.version = Pragma::Contract::VERSION
9
- spec.authors = ["Alessandro Desantis"]
10
- spec.email = ["desa.alessandro@gmail.com"]
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 = "https://github.com/pragmarb/pragma-contract"
14
- spec.license = "MIT"
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 = "exe"
20
+ spec.bindir = 'exe'
20
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
- spec.require_paths = ["lib"]
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 "bundler"
28
- spec.add_development_dependency "rake"
29
- spec.add_development_dependency "rspec"
30
- spec.add_development_dependency "rubocop"
31
- spec.add_development_dependency "rubocop-rspec"
32
- spec.add_development_dependency "coveralls"
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.1.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: 2016-12-26 00:00:00.000000000 Z
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.5.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.