pragma 2.3.0 → 2.4.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 +2 -3
- data/CHANGELOG.md +17 -2
- data/Gemfile +2 -5
- data/README.md +7 -2
- data/Rakefile +5 -3
- data/lib/pragma.rb +1 -0
- data/lib/pragma/filter/boolean.rb +18 -0
- data/lib/pragma/macro/classes.rb +3 -2
- data/lib/pragma/macro/filtering.rb +1 -1
- data/lib/pragma/macro/pagination.rb +1 -3
- data/lib/pragma/macro/policy.rb +4 -1
- data/lib/pragma/operation/index.rb +6 -2
- data/lib/pragma/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 474ef14673089ce28a581b260a0c8913b3e1afe462eeb7cb840c406a29195316
|
4
|
+
data.tar.gz: 15174e9df88e96007f15475464d023eab01c92e3b791f8c0289382f65a01c279
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1a710dd54c3a2aff7fa789293d160e0061c61e9d3fd86d3b00c8360efa6171de79719803c89a352ac6059895d3e1b4fdfe5d6c54e5e73e6ea0cbcdf68e0bc8c
|
7
|
+
data.tar.gz: 62440fa3450e7e40314e92d6a771c072657130cfd785b05cabf2becf736fb2429be7f012882308572791c2e6e113f52a206f199b5b549cc7385ac91d8d79748d
|
data/.rubocop.yml
CHANGED
@@ -5,6 +5,7 @@ AllCops:
|
|
5
5
|
Include:
|
6
6
|
- '**/Gemfile'
|
7
7
|
- '**/Rakefile'
|
8
|
+
- '**/*.rb'
|
8
9
|
Exclude:
|
9
10
|
- 'bin/*'
|
10
11
|
- 'db/**/*'
|
@@ -13,8 +14,6 @@ AllCops:
|
|
13
14
|
- 'spec/rails_helper.rb'
|
14
15
|
- 'spec/support/**/*'
|
15
16
|
- 'config/**/*'
|
16
|
-
- '**/Rakefile'
|
17
|
-
- '**/Gemfile'
|
18
17
|
|
19
18
|
RSpec/DescribeClass:
|
20
19
|
Exclude:
|
@@ -52,7 +51,7 @@ Style/SignalException:
|
|
52
51
|
Style/BracesAroundHashParameters:
|
53
52
|
EnforcedStyle: context_dependent
|
54
53
|
|
55
|
-
|
54
|
+
Layout/EndAlignment:
|
56
55
|
EnforcedStyleAlignWith: variable
|
57
56
|
AutoCorrect: true
|
58
57
|
|
data/CHANGELOG.md
CHANGED
@@ -5,11 +5,25 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
6
6
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## [Unreleased]
|
9
|
+
|
10
|
+
## [2.4.0]
|
11
|
+
|
12
|
+
### Added
|
13
|
+
|
14
|
+
- Implemented `Boolean` scope
|
15
|
+
- Added support for additional policy context via `policy.context`
|
16
|
+
|
17
|
+
### Fixed
|
18
|
+
|
19
|
+
- Added support for different capitalizations of API namespace
|
20
|
+
- Fixed an issue where each filter would override the previous one
|
21
|
+
|
8
22
|
## [2.3.0]
|
9
23
|
|
10
24
|
### Added
|
11
25
|
|
12
|
-
-
|
26
|
+
- Added support for Kaminari in `Pagination` macro
|
13
27
|
|
14
28
|
### Changed
|
15
29
|
|
@@ -62,7 +76,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
62
76
|
|
63
77
|
First Pragma 2 release.
|
64
78
|
|
65
|
-
[Unreleased]: https://github.com/pragmarb/pragma/compare/v2.
|
79
|
+
[Unreleased]: https://github.com/pragmarb/pragma/compare/v2.4.0...HEAD
|
80
|
+
[2.4.0]: https://github.com/pragmarb/pragma/compare/v2.3.0...v2.4.0
|
66
81
|
[2.3.0]: https://github.com/pragmarb/pragma/compare/v2.2.0...v2.3.0
|
67
82
|
[2.2.0]: https://github.com/pragmarb/pragma/compare/v2.1.1...v2.2.0
|
68
83
|
[2.1.1]: https://github.com/pragmarb/pragma/compare/v2.1.0...v2.1.1
|
data/Gemfile
CHANGED
@@ -1,11 +1,8 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
source 'https://rubygems.org'
|
2
4
|
|
3
5
|
# Specify your gem's dependencies in pragma.gemspec
|
4
6
|
gemspec
|
5
7
|
|
6
8
|
gem 'pry'
|
7
|
-
|
8
|
-
gem 'pragma-policy', github: 'pragmarb/pragma-policy'
|
9
|
-
gem 'pragma-operation', github: 'pragmarb/pragma-operation'
|
10
|
-
gem 'pragma-contract', github: 'pragmarb/pragma-contract'
|
11
|
-
gem 'pragma-decorator', github: 'pragmarb/pragma-decorator'
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# Pragma
|
2
2
|
|
3
3
|
[![Build Status](https://travis-ci.org/pragmarb/pragma.svg?branch=master)](https://travis-ci.org/pragmarb/pragma)
|
4
|
-
[![Dependency Status](https://gemnasium.com/badges/github.com/pragmarb/pragma.svg)](https://gemnasium.com/github.com/pragmarb/pragma)
|
5
4
|
[![Coverage Status](https://coveralls.io/repos/github/pragmarb/pragma/badge.svg?branch=master)](https://coveralls.io/github/pragmarb/pragma?branch=master)
|
6
5
|
[![Maintainability](https://api.codeclimate.com/v1/badges/e51e8d7489eb72ab97ba/maintainability)](https://codeclimate.com/github/pragmarb/pragma/maintainability)
|
7
6
|
|
@@ -296,6 +295,11 @@ If the user is not authorized to perform the operation (i.e. if the policy's `#s
|
|
296
295
|
to override the error handling logic, you can remove the `fail_fast` option and instead implement
|
297
296
|
your own `failure` step.
|
298
297
|
|
298
|
+
The macro accepts the following options, which can be defined on the operation or at runtime:
|
299
|
+
|
300
|
+
- `policy.context`: the context to use for the policy (optional, `current_user` is used if not
|
301
|
+
provided).
|
302
|
+
|
299
303
|
### Filtering
|
300
304
|
|
301
305
|
**Used in:** Index
|
@@ -338,7 +342,8 @@ The following filters are available for ActiveRecord currently:
|
|
338
342
|
- `Where`: adds a generic `WHERE` clause (requires `:condition` and passes the parameter's value as
|
339
343
|
`:value`).
|
340
344
|
- `Scope`: calls a method on the collection (requires `:scope` and passes the parameter's value as
|
341
|
-
the first argument)
|
345
|
+
the first argument);
|
346
|
+
- `Boolean`: calls a method on the collection (requires `:scope` and doesn't pass any arguments).
|
342
347
|
|
343
348
|
Support for more clauses as well as more ORMs will come soon.
|
344
349
|
|
data/Rakefile
CHANGED
data/lib/pragma.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Pragma
|
4
|
+
module Filter
|
5
|
+
class Boolean < Base
|
6
|
+
attr_reader :scope
|
7
|
+
|
8
|
+
def initialize(scope:, **other)
|
9
|
+
super(**other)
|
10
|
+
@scope = scope
|
11
|
+
end
|
12
|
+
|
13
|
+
def apply(relation:, **)
|
14
|
+
relation.public_send(scope)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/pragma/macro/classes.rb
CHANGED
@@ -47,8 +47,9 @@ module Pragma
|
|
47
47
|
|
48
48
|
def root_namespace(input, options)
|
49
49
|
resource_namespace = resource_namespace(input, options)
|
50
|
-
return [] if resource_namespace.first
|
51
|
-
|
50
|
+
return [] if %w[API Api].include?(resource_namespace.first)
|
51
|
+
api_index = (resource_namespace.index('API') || resource_namespace.index('Api') || 1)
|
52
|
+
resource_namespace[0..(api_index - 1)]
|
52
53
|
end
|
53
54
|
|
54
55
|
def expected_model_class(input, options)
|
@@ -50,9 +50,7 @@ module Pragma
|
|
50
50
|
# can't distinguish. Maybe there's a better way to do it?
|
51
51
|
options['params'].tap do |p|
|
52
52
|
%w[pagination.page_param pagination.per_page_param].each do |key|
|
53
|
-
|
54
|
-
p[options[key]] = p[options[key]].to_i
|
55
|
-
end
|
53
|
+
p[options[key]] = p[options[key]].to_i if p[options[key]]&.respond_to?(:to_i)
|
56
54
|
end
|
57
55
|
end
|
58
56
|
end
|
data/lib/pragma/macro/policy.rb
CHANGED
@@ -10,7 +10,10 @@ module Pragma
|
|
10
10
|
module Policy
|
11
11
|
class << self
|
12
12
|
def for(input, name, options, action = nil)
|
13
|
-
policy = options["policy.#{name}.class"].new(
|
13
|
+
policy = options["policy.#{name}.class"].new(
|
14
|
+
options['policy.context'] || options['current_user'],
|
15
|
+
options['model']
|
16
|
+
)
|
14
17
|
|
15
18
|
action_name = action.is_a?(Proc) ? action.call(options) : action
|
16
19
|
action_name ||= input.class.operation_name
|
@@ -20,8 +20,12 @@ module Pragma
|
|
20
20
|
options['model'] = options['model.class'].all
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
# TODO: Turn this into a macro.
|
24
|
+
def scope!(options, model:, **)
|
25
|
+
options['model'] = options['policy.default.scope.class'].new(
|
26
|
+
options['policy.context'] || options['current_user'],
|
27
|
+
model
|
28
|
+
).resolve
|
25
29
|
end
|
26
30
|
|
27
31
|
def respond!(options, **)
|
data/lib/pragma/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pragma
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.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: 2018-
|
11
|
+
date: 2018-06-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pragma-contract
|
@@ -199,6 +199,7 @@ files:
|
|
199
199
|
- lib/pragma.rb
|
200
200
|
- lib/pragma/decorator/error.rb
|
201
201
|
- lib/pragma/filter/base.rb
|
202
|
+
- lib/pragma/filter/boolean.rb
|
202
203
|
- lib/pragma/filter/equals.rb
|
203
204
|
- lib/pragma/filter/ilike.rb
|
204
205
|
- lib/pragma/filter/like.rb
|