tram-policy 0.2.0 → 0.2.1

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: 23e70750c9bc2efd4c816ae3e9dfb609ffe5d35f
4
- data.tar.gz: 4ef00e68121a27bd67d58a883098a7732f4129f2
3
+ metadata.gz: 0f05aaf4884e7456c1649ac556bdb9510596e69b
4
+ data.tar.gz: a7179cf1a45d8fa9a637bbf1114e9368ebbcb998
5
5
  SHA512:
6
- metadata.gz: ed5ab03576fcc938f987c3908b739f026508a6be32f0e8c6b14492054538fe4731a366bc4425875771784160a7e007eadb8fafdb73376ee470ea50760a881251
7
- data.tar.gz: 320d14ef10562cd8a78e682a0d9989f9d9a3c15e60509862800ce7fc2fb185dc66d52345c19645e997d3ca34e670b4c91e8e3f6955f0e40e733d32e61b2d68f9
6
+ metadata.gz: 1f8c7ca5fdf009cad77ccc6b622c36111304c2db5221cb6a109c59b0bd89e443e3521d0e41b0b5c73a0b3c31bffee8a169968bf1aaedf9eb5ae681c047a6284f
7
+ data.tar.gz: bb4d737514915ca82b2947b014c6542f8342bb32375ff1a8b604ddc3e96c608279a44ad47fcf808097ccac0cdab7859a9aadd0702f3911762128557969e50904
data/.travis.yml CHANGED
@@ -6,19 +6,16 @@ bundler_args: --without benchmarks tools
6
6
  script:
7
7
  - bundle exec rake spec
8
8
  rvm:
9
- - 2.2
10
9
  - 2.3.0
11
10
  - 2.4.0
12
- - jruby-9000
13
- - rbx-2
14
- - rbx-3
15
11
  - ruby-head
12
+ - jruby-9.1.0.0
13
+ - rbx-3
16
14
  env:
17
15
  global:
18
16
  - JRUBY_OPTS='--dev -J-Xmx1024M'
19
17
  matrix:
20
18
  allow_failures:
21
- - rvm: rbx-2
22
19
  - rvm: rbx-3
23
20
  - rvm: ruby-head
24
21
  - rvm: jruby-head
data/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## [0.2.1] - [2017-08-28]
8
+
9
+ ### Changed
10
+ - Updated dependency from [dry-initializer] to v2.0.0 (nepalez)
11
+
7
12
  ## [0.2.0] - [2017-08-19]
8
13
 
9
14
  ### Added
@@ -88,10 +93,12 @@ The gem is battle-tested for production (in a real commertial project).
88
93
  ## [0.0.1] - [2017-04-18]
89
94
  This is a first public release (@nepalez, @charlie-wasp, @JewelSam, @sergey-chechaev)
90
95
 
96
+ [dry-initializer]: https://github.com/dry-rb/dry-initializer
91
97
  [Unreleased]: https://github.com/tram-rb/tram-policy
92
98
  [0.0.1]: https://github.com/tram-rb/tram-policy/releases/tag/v0.0.1
93
99
  [0.0.2]: https://github.com/tram-rb/tram-policy/compare/v0.0.1...v0.0.2
94
100
  [0.0.3]: https://github.com/tram-rb/tram-policy/compare/v0.0.2...v0.0.3
95
101
  [0.1.0]: https://github.com/tram-rb/tram-policy/compare/v0.0.3...v0.1.0
96
102
  [0.1.1]: https://github.com/tram-rb/tram-policy/compare/v0.1.0...v0.1.1
97
- [0.1.2]: https://github.com/tram-rb/tram-policy/compare/v0.1.1...v0.2.0
103
+ [0.2.0]: https://github.com/tram-rb/tram-policy/compare/v0.1.1...v0.2.0
104
+ [0.2.1]: https://github.com/tram-rb/tram-policy/compare/v0.2.0...v0.2.1
data/README.md CHANGED
@@ -8,7 +8,6 @@ Policy Object Pattern
8
8
  [![Gem Version][gem-badger]][gem]
9
9
  [![Build Status][travis-badger]][travis]
10
10
  [![Dependency Status][gemnasium-badger]][gemnasium]
11
- [![Code Climate][codeclimate-badger]][codeclimate]
12
11
  [![Inline docs][inch-badger]][inch]
13
12
 
14
13
  ## Intro
@@ -132,7 +131,7 @@ class Article::PublicationPolicy < Tram::Policy
132
131
  end
133
132
  ```
134
133
 
135
- As mentioned above, sending a symbolic key to the `errors#add` means the key should be translated by [I18n][i18n]. The only magic under the hood concerns a scope for the translation. By default it is taken from the full name of current class prepended with `"evil.client.errors"`.
134
+ As mentioned above, sending a symbolic key to the `errors#add` means the key should be translated by [I18n][i18n]. The only magic under the hood concerns a scope for the translation. By default it is taken from the full name of current class prepended with `"tram-policy"`.
136
135
 
137
136
  > You can redefine the scope by reloading private method `.scope` of the policy.
138
137
 
@@ -6,6 +6,7 @@ class Tram::Policy
6
6
  # from one collection of [Tram::Policy::Errors] to another.
7
7
  #
8
8
  class Error
9
+ # @!method self.new(value, opts)
9
10
  # Builds an error
10
11
  #
11
12
  # If another error is send to the constructor, the error returned unchanged
@@ -14,6 +14,7 @@ class Tram::Policy
14
14
  #
15
15
  attr_reader :policy
16
16
 
17
+ # @!method add(message, tags)
17
18
  # Adds error message to the collection
18
19
  #
19
20
  # @param [#to_s] message Either a message, or a symbolic key for translation
@@ -37,9 +38,10 @@ class Tram::Policy
37
38
  @set.each { |error| yield(error) }
38
39
  end
39
40
 
41
+ # @!method by_tags(filter)
40
42
  # Selects errors filtered by tags
41
43
  #
42
- # @param [Hash<Symbol, Object>] filter
44
+ # @param [Hash<Symbol, Object>] filter List of options to filter by
43
45
  # @return [Hash<Symbol, Object>]
44
46
  #
45
47
  def by_tags(**filter)
@@ -47,6 +49,7 @@ class Tram::Policy
47
49
  reject { |error| (filter - error.to_h.to_a).any? }
48
50
  end
49
51
 
52
+ # @!method empty?
50
53
  # Checks whether a collection is empty
51
54
  #
52
55
  # @return [Boolean]
@@ -71,11 +74,14 @@ class Tram::Policy
71
74
  @set.map(&:full_message).sort
72
75
  end
73
76
 
77
+ # @!method merge(other, options)
74
78
  # Merges other collection to the current one and returns new collection
75
79
  # with the current scope
76
80
  #
77
- # param [Tram::Policy::Errors] other Collection to be merged
78
- # yieldparam [Hash<Symbol, Object>]
81
+ # @param [Tram::Policy::Errors] other Collection to be merged
82
+ # @param [Hash<Symbol, Object>] options Options to be added to merged errors
83
+ # @yieldparam [Hash<Symbol, Object>] hash of error options
84
+ # @return [self]
79
85
  #
80
86
  # @example Add some tag to merged errors
81
87
  # policy.merge(other) { |err| err[:source] = "other" }
@@ -5,6 +5,7 @@ module Tram
5
5
  class Policy
6
6
  require_relative "inflector"
7
7
 
8
+ # @private
8
9
  class Generator < Thor::Group
9
10
  include Thor::Actions
10
11
 
@@ -1,9 +1,12 @@
1
1
  class Tram::Policy
2
2
  if Object.const_defined? "ActiveSupport::Inflector"
3
+ # @private
3
4
  Inflector = ActiveSupport::Inflector
4
5
  elsif Object.const_defined? "Inflecto"
6
+ # @private
5
7
  Inflector = ::Inflecto
6
8
  else
9
+ # @private
7
10
  module Inflector
8
11
  def self.underscore(name)
9
12
  name&.dup&.tap do |n|
@@ -1,5 +1,5 @@
1
1
  class Tram::Policy
2
- # Describes a validator
2
+ # @private
3
3
  class Validator
4
4
  attr_reader :scope, :name, :block, :stop_on_failure
5
5
 
data/lib/tram/policy.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "dry-initializer"
2
2
  require "i18n"
3
3
 
4
+ # Top-level scope for Tram collection of gems
4
5
  module Tram
5
6
  # Base class for policy objects with composable validation errors
6
7
  class Policy
@@ -13,9 +14,10 @@ module Tram
13
14
  extend Dry::Initializer
14
15
 
15
16
  class << self
17
+ # @!method validate(name, opts)
16
18
  # Registers a validator
17
19
  #
18
- # @param [#to_sym, Array<#to_sym>] names
20
+ # @param [#to_sym, nil] name (nil)
19
21
  # @option opts [Boolean] :stop_on_failure
20
22
  # @return [self]
21
23
  #
@@ -44,7 +46,7 @@ module Tram
44
46
  end
45
47
 
46
48
  def all
47
- ((self == Tram::Policy) ? [] : superclass.send(:all)) + local
49
+ (((self == Tram::Policy) ? [] : superclass.send(:all)) + local).uniq
48
50
  end
49
51
  end
50
52
 
@@ -54,7 +56,7 @@ module Tram
54
56
  # @param [Hash<Symbol, Object>] options
55
57
  # @return [String]
56
58
  #
57
- def t(message, **options)
59
+ def t(message, options = {})
58
60
  return message.to_s unless message.is_a? Symbol
59
61
  I18n.t message, options.merge(scope: @__scope__)
60
62
  end
@@ -111,6 +113,9 @@ module Tram
111
113
 
112
114
  def initialize(*)
113
115
  super
116
+
117
+ @__options__ = self.class.dry_initializer.attributes(self)
118
+
114
119
  self.class.send(:all).each do |validator|
115
120
  size = errors.count
116
121
  validator.check(self)
@@ -1,5 +1,3 @@
1
- require_relative "user_policy"
2
-
3
1
  class Test::AdminPolicy < Test::UserPolicy
4
2
  validate :login
5
3
  validate :name
@@ -1,7 +1,7 @@
1
1
  class Test::UserPolicy < Tram::Policy
2
2
  param :user
3
3
 
4
- validate :name
4
+ validate "name"
5
5
  validate "email"
6
6
  validate "name"
7
7
 
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,3 @@
1
- begin
2
- require "pry"
3
- rescue
4
- nil
5
- end
6
1
  require "bundler/setup"
7
2
  require "tram/policy"
8
3
  require "tram/policy/rspec"
data/tram-policy.gemspec CHANGED
@@ -1,8 +1,8 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "tram-policy"
3
- gem.version = "0.2.0"
3
+ gem.version = "0.2.1"
4
4
  gem.author = ["Viktor Sokolov (gzigzigzeo)", "Andrew Kozin (nepalez)"]
5
- gem.email = ["andrew.kozin@gmail.com"]
5
+ gem.email = "andrew.kozin@gmail.com"
6
6
  gem.homepage = "https://github.com/tram/tram-policy"
7
7
  gem.summary = "Policy Object Pattern"
8
8
  gem.license = "MIT"
@@ -12,9 +12,9 @@ Gem::Specification.new do |gem|
12
12
  gem.extra_rdoc_files = Dir["README.md", "LICENSE", "CHANGELOG.md"]
13
13
  gem.executables = %w[tram-policy]
14
14
 
15
- gem.required_ruby_version = ">= 2.2"
15
+ gem.required_ruby_version = ">= 2.3"
16
16
 
17
- gem.add_runtime_dependency "dry-initializer", "~> 1.4"
17
+ gem.add_runtime_dependency "dry-initializer", "~> 2.0"
18
18
  gem.add_runtime_dependency "i18n", "~> 0.8"
19
19
 
20
20
  gem.add_development_dependency "rake", "> 10"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tram-policy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Viktor Sokolov (gzigzigzeo)
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-08-19 00:00:00.000000000 Z
12
+ date: 2017-08-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dry-initializer
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: '1.4'
20
+ version: '2.0'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: '1.4'
27
+ version: '2.0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: i18n
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -110,8 +110,7 @@ dependencies:
110
110
  - !ruby/object:Gem::Version
111
111
  version: '0.19'
112
112
  description:
113
- email:
114
- - andrew.kozin@gmail.com
113
+ email: andrew.kozin@gmail.com
115
114
  executables:
116
115
  - tram-policy
117
116
  extensions: []
@@ -166,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
165
  requirements:
167
166
  - - ">="
168
167
  - !ruby/object:Gem::Version
169
- version: '2.2'
168
+ version: '2.3'
170
169
  required_rubygems_version: !ruby/object:Gem::Requirement
171
170
  requirements:
172
171
  - - ">="