granite 0.9.1 → 0.9.2

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: bbe5e30c9b3c74f9a703caf9d9a30c6ea0791aaad7b159f8f5e12dd58d1b62d3
4
- data.tar.gz: 5c6751169deb310e651cdeace4ac9612419892f13ec7188b06eee4385bc5f4ba
3
+ metadata.gz: 1b2674022b2612547cab05e27f9c832300b8f7fd6a1c43b26961733e12e9d4aa
4
+ data.tar.gz: 59247c53dadced6268e4d921dae1c2f4ba8522eecf11b0d544c639a784f79c60
5
5
  SHA512:
6
- metadata.gz: c7cf2f66caafc82d058cc9e89404828733fbe5f7798de7016bff4a002454f2275f730e936cd48861e5080d582989be13a411484ee0d12dfd3ed65e5f993aabb0
7
- data.tar.gz: 32530f64d500262d218909f28ce3d27d1845baba024e853b4041a9780b33b87d05824cd0ba32cbde5c12d1f44978e3dc615f448be3c1a6dc3e02c70df3045c9d
6
+ metadata.gz: ecf502f37360a2c10312ec06e28e6d3a6d8f279874ead21e9c51ce8496b0b4c60028c68bfcb1118d0e60f643524eaa2fd0382caa4df7ecfc140397bf812de896
7
+ data.tar.gz: 9b5052b9193ec8038d6184b33bf258ec63dc93157f7f0a4e66f58e6b687cb6fb75ef2068bf8344b41abcc43272ac1b46f8540b2d8a95db28be6dda41548dcaab
@@ -16,9 +16,7 @@ module Granite
16
16
  def projector
17
17
  @projector ||= begin
18
18
  action_projector_class = action_class.public_send(projector_name)
19
- if respond_to?(:projector_performer, true)
20
- action_projector_class = action_projector_class.as(projector_performer)
21
- end
19
+ action_projector_class = action_projector_class.as(projector_performer) if respond_to?(:projector_performer, true)
22
20
  action_projector_class.new(projector_params)
23
21
  end
24
22
  end
@@ -32,9 +32,7 @@ module Granite
32
32
  def assign_attributes(attributes)
33
33
  attributes = attributes.to_unsafe_hash if attributes.respond_to?(:to_unsafe_hash)
34
34
  attributes = attributes.stringify_keys
35
- if attributes.key?(model_name.param_key)
36
- attributes = attributes.merge(attributes.delete(model_name.param_key))
37
- end
35
+ attributes = attributes.merge(attributes.delete(model_name.param_key)) if attributes.key?(model_name.param_key)
38
36
  super(attributes)
39
37
  end
40
38
  end
@@ -82,9 +80,7 @@ module Granite
82
80
  #
83
81
  # @return [Boolean] whether action is performable
84
82
  def performable?
85
- unless instance_variable_defined?(:@performable)
86
- @performable = allowed? && satisfy_preconditions?
87
- end
83
+ @performable = allowed? && satisfy_preconditions? unless instance_variable_defined?(:@performable)
88
84
  @performable
89
85
  end
90
86
 
@@ -7,9 +7,7 @@ module Granite
7
7
  class Action
8
8
  class NotAllowedError < Error
9
9
  def initialize(action)
10
- if action.performer.respond_to?(:id) && action.performer.id.present?
11
- performer_id = "##{action.performer.id}"
12
- end
10
+ performer_id = "##{action.performer.id}" if action.performer.respond_to?(:id) && action.performer.id.present?
13
11
 
14
12
  super("#{action.class} action is not allowed " \
15
13
  "for #{action.performer.class}#{performer_id}", action)
@@ -75,9 +73,7 @@ module Granite
75
73
  # Returns true if any of defined policies returns true
76
74
  #
77
75
  def allowed?
78
- unless instance_variable_defined?(:@allowed)
79
- @allowed = _policies_strategy.allowed?(self)
80
- end
76
+ @allowed = _policies_strategy.allowed?(self) unless instance_variable_defined?(:@allowed)
81
77
  @allowed
82
78
  end
83
79
 
@@ -54,11 +54,9 @@ RSpec::Matchers.define :satisfy_preconditions do
54
54
  if @expected_messages
55
55
  errors = object.errors[:base]
56
56
 
57
- result &&= @expected_messages.all? { |expected| errors.any? { |error| error.match? expected } }
57
+ result &&= @expected_messages.all? { |expected| errors.any? { |error| compare(error, expected) } }
58
58
 
59
- if @exactly
60
- result &&= errors.none? { |error| @expected_messages.none? { |expected| error.match? expected } }
61
- end
59
+ result &&= errors.none? { |error| @expected_messages.none? { |expected| compare(error, expected) } } if @exactly
62
60
  elsif @expected_kind_of_messages
63
61
  error_kinds = object.errors.details[:base].map(&:values).flatten
64
62
  result &&= (@expected_kind_of_messages - error_kinds).empty?
@@ -94,6 +92,16 @@ RSpec::Matchers.define :satisfy_preconditions do
94
92
  message += " with error messages of kind #{expected_kind_of_messages}"
95
93
  message + " but got following kind of error messages:\n #{actual_kind_of_errors.inspect}"
96
94
  end
95
+
96
+ def compare(actual, expected)
97
+ if RSpec::Matchers.is_a_matcher?(expected)
98
+ expected.matches?(actual)
99
+ elsif expected.is_a?(String)
100
+ actual == expected
101
+ else
102
+ actual.match?(expected)
103
+ end
104
+ end
97
105
  end
98
106
 
99
107
  RSpec::Matchers.define_negated_matcher :fail_preconditions, :satisfy_preconditions
@@ -1,3 +1,3 @@
1
1
  module Granite
2
- VERSION = '0.9.1'.freeze
2
+ VERSION = '0.9.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: granite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arkadiy Zabazhanov & friends
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-21 00:00:00.000000000 Z
11
+ date: 2019-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack