pragma-rails 2.1.1 → 2.2.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: a548529aa67d6c5aaaf15602352b826b582199d3b8d394f7e93c5c56bf11fa21
4
- data.tar.gz: 2120108c5a744376010475acb19b4df95eaebdd6a423b73dccb373d16f09bd99
3
+ metadata.gz: a6e2a68743a821815f7829d534b473c0d7ea6586c6090d2b238ec2de1e2b43fe
4
+ data.tar.gz: 1ef22df33406ca6611526d3c080895c5ae1412ead86d4f2b9529bd5ab6a607fa
5
5
  SHA512:
6
- metadata.gz: 1b37bbe8992df14b2931a747d9b8d14c5ba78da2b33b9ec942eb9c5e6a8cd658267d748936dde6ac6e410595e663898d734e30b1f1507d37a13a30891ed5350e
7
- data.tar.gz: bcdd84367813babc076039c5f3f9b061db5a3b178a3186b2bad9c3a55a2473c00a993be3d78773aca2ab0bb48114af199ce444f5fa49e7c3276732624a2d780e
6
+ metadata.gz: 02c720a8770b02cc61ad7ee352b895c317f5d04c9871dd324a6e28048df8ab663bc86542dc6af1c550377ae31b1eb6904b8fd9d1f1b98ba735d255a3ea68b5f9
7
+ data.tar.gz: 657e38ecf81f45f9cf98523a4e7eb20a60670116d48704881893d69bb1011c77a939235365ecdffa2ea796c5cca40d71a89a5e8f48977674e1d014d950587bae
data/.rubocop.yml CHANGED
@@ -3,8 +3,9 @@ require: rubocop-rspec
3
3
  AllCops:
4
4
  TargetRubyVersion: 2.3
5
5
  Include:
6
- - '**/Gemfile'
6
+ - '**/*.rb'
7
7
  - '**/Rakefile'
8
+ - '**/Gemfile'
8
9
  Exclude:
9
10
  - 'bin/*'
10
11
  - 'db/**/*'
@@ -14,8 +15,6 @@ AllCops:
14
15
  - 'spec/support/**/*'
15
16
  - 'spec/dummy/**/*'
16
17
  - 'config/**/*'
17
- - '**/Rakefile'
18
- - '**/Gemfile'
19
18
 
20
19
  RSpec/DescribeClass:
21
20
  Exclude:
@@ -57,7 +56,7 @@ Style/SignalException:
57
56
  Style/BracesAroundHashParameters:
58
57
  EnforcedStyle: context_dependent
59
58
 
60
- Lint/EndAlignment:
59
+ Layout/EndAlignment:
61
60
  EnforcedStyleAlignWith: variable
62
61
  AutoCorrect: true
63
62
 
data/.travis.yml CHANGED
@@ -3,4 +3,7 @@ language: ruby
3
3
  rvm:
4
4
  - 2.3.0
5
5
  - 2.4.0
6
+ - 2.5.0
6
7
  before_install: gem install bundler -v 1.13.3
8
+ script:
9
+ - cd spec/dummy/ && bundle exec rake db:schema:load && bundle exec rake db:test:prepare && bundle exec rake spec
data/CHANGELOG.md CHANGED
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.2.0]
11
+
12
+ ## Added
13
+
14
+ - Added support for passing additional context to policies via `#policy_context`
15
+
16
+ ## Fixed
17
+
18
+ - Allowed support for accessing operation params by either string or symbol
19
+
10
20
  ## [2.1.1]
11
21
 
12
22
  ### Fixed
@@ -31,7 +41,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
31
41
 
32
42
  First Pragma 2 release.
33
43
 
34
- [Unreleased]: https://github.com/pragmarb/pragma-rails/compare/v2.1.1...HEAD
44
+ [Unreleased]: https://github.com/pragmarb/pragma-rails/compare/v2.2.0...HEAD
45
+ [2.2.0]: https://github.com/pragmarb/pragma-rails/compare/v2.1.1...v2.2.0
35
46
  [2.1.1]: https://github.com/pragmarb/pragma-rails/compare/v2.1.0...v2.1.1
36
47
  [2.1.0]: https://github.com/pragmarb/pragma-rails/compare/v2.0.0...v2.1.0
37
48
  [2.0.0]: https://github.com/pragmarb/pragma-rails/compare/v1.2.4...v2.0.0
data/Gemfile CHANGED
@@ -1,4 +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-rails.gemspec
4
6
  gemspec
7
+
8
+ gem 'kaminari'
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  # Pragma on Rails
2
2
 
3
3
  [![Build Status](https://travis-ci.org/pragmarb/pragma-rails.svg?branch=master)](https://travis-ci.org/pragmarb/pragma-rails)
4
- [![Dependency Status](https://gemnasium.com/badges/github.com/pragmarb/pragma-rails.svg)](https://gemnasium.com/github.com/pragmarb/pragma-rails)
5
4
  [![Coverage Status](https://coveralls.io/repos/github/pragmarb/pragma-rails/badge.svg?branch=master)](https://coveralls.io/github/pragmarb/pragma-rails?branch=master)
6
5
  [![Maintainability](https://api.codeclimate.com/v1/badges/e51e8d7489eb72ab97ba/maintainability)](https://codeclimate.com/github/pragmarb/pragma-rails/maintainability)
7
6
 
@@ -131,6 +130,9 @@ module API
131
130
  end
132
131
  ```
133
132
 
133
+ You may also define `#policy_context` to [pass additional context](https://github.com/pragmarb/pragma-policy#passing-additional-context)
134
+ to your policies.
135
+
134
136
  ### Resource Controllers
135
137
 
136
138
  Resource controllers (provided by the `Pragma::Rails::ResourceController` module) abstract even more
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
3
5
 
4
6
  RSpec::Core::RakeTask.new(:spec)
5
7
 
6
- task :default => :spec
8
+ task default: :spec
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Pragma
4
4
  class ResourceGenerator < ::Rails::Generators::NamedBase # :nodoc:
5
- source_root File.expand_path('../templates', __FILE__)
5
+ source_root File.expand_path('templates', __dir__)
6
6
 
7
7
  class_option :version, type: :numeric, default: 1, desc: 'The API version to use', aliases: '-v'
8
8
 
@@ -16,7 +16,7 @@ module Pragma
16
16
  private
17
17
 
18
18
  def factory_name
19
- [namespace, class_name].join.underscore.gsub('/', '_')
19
+ [namespace, class_name].join.underscore.tr('/', '_')
20
20
  end
21
21
 
22
22
  def full_class_name
@@ -60,9 +60,7 @@ module Pragma
60
60
  write("namespace :#{namespace} do", index + 1)
61
61
  end
62
62
 
63
- path_fragment = if file_name.include?('_')
64
- ", path: '#{file_name.pluralize.tr('_', '-')}'"
65
- end
63
+ path_fragment = (", path: '#{file_name.pluralize.tr('_', '-')}'" if file_name.include?('_'))
66
64
 
67
65
  # rubocop:disable Metrics/LineLength
68
66
  write(
@@ -24,7 +24,8 @@ module Pragma
24
24
 
25
25
  result = operation_const.call(
26
26
  operation_params,
27
- 'current_user' => operation_user
27
+ 'current_user' => operation_user,
28
+ 'policy.context' => policy_context
28
29
  )
29
30
 
30
31
  result['result.response'].headers.each_pair do |key, value|
@@ -49,7 +50,7 @@ module Pragma
49
50
  #
50
51
  # @return [Hash]
51
52
  def operation_params
52
- params.to_unsafe_h
53
+ params.to_unsafe_h.with_indifferent_access
53
54
  end
54
55
 
55
56
  # Returns the currently authenticated user (for policies).
@@ -61,6 +62,15 @@ module Pragma
61
62
  current_user if respond_to?(:current_user)
62
63
  end
63
64
 
65
+ # Returns the context to pass to Pragma policies.
66
+ #
67
+ # By default, calls {#operation_user}.
68
+ #
69
+ # @return [Object]
70
+ def policy_context
71
+ operation_user
72
+ end
73
+
64
74
  private
65
75
 
66
76
  def entity_to_hash(entity)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Pragma
4
4
  module Rails
5
- VERSION = '2.1.1'
5
+ VERSION = '2.2.0'
6
6
  end
7
7
  end
data/pragma-rails.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- lib = File.expand_path('../lib', __FILE__)
3
+ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require 'pragma/rails/version'
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pragma-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.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-02-23 00:00:00.000000000 Z
11
+ date: 2018-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pragma