pavlov 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 28147e53a9ec3060b50d87d0ffa15929c17f006c
4
- data.tar.gz: 4f508eb3d010a7f276f68ff269d71ca86e200549
3
+ metadata.gz: 32f5a2414ffc45283f8602bafb5f8715a4e99a26
4
+ data.tar.gz: 642831b040f9a90ebe6b8633488a7ffbbb9dc797
5
5
  SHA512:
6
- metadata.gz: c9c8cb195850d0e8deb4f8e70c08ba86a587104b66a8f78b920678d0bcf903ebfde8f51dea33e26ce22cd87dda1a7a6a41ad4da5db8090b87d1216ed27385b66
7
- data.tar.gz: 8bb36fef06d09c8ef8c4a0e91bfb402dee5c95f863aac3aff77200619f69631c1ce371009e120d108556aa693b068a5461f9a1ffc294a09d57088a7e6e94ed77
6
+ metadata.gz: c2e4a6194b6717b64c7f475ee255d07a8078f1b0643a61e5bc86c7c2934765880c12c6cdee9979b1aca6cc5a8c0754e9d9c64c4322cda1806b1e104c530a74c6
7
+ data.tar.gz: b185b09010c0551e84bf1a25c9a8eca765ec4ffeb9fa73c19c97e017068145718610e3698aba31ec3d4b4a7efc5b446fd8083d89f5528e3f9cd484b0844a9254
@@ -1,60 +1,6 @@
1
1
  require 'pavlov'
2
2
 
3
3
  module Pavlov
4
- def self.old_command command_name, *args
5
- klass = class_for_command(command_name)
6
- command command_name, arguments_to_attributes(klass, args)
7
- end
8
-
9
- def self.old_interactor interactor_name, *args
10
- klass = class_for_interactor(interactor_name)
11
- interactor interactor_name, arguments_to_attributes(klass, args)
12
- end
13
-
14
- def self.old_query query_name, *args
15
- klass = class_for_query(query_name)
16
- query query_name, arguments_to_attributes(klass, args)
17
- end
18
-
19
- def self.arguments_to_attributes(operation_class, arguments)
20
- attribute_keys = operation_class.attribute_set.map(&:name)
21
-
22
- # TODO: this can be done so much better, but I don't know how.
23
- hash = {}
24
- arguments.each_with_index do |value, index|
25
- hash[attribute_keys[index].to_sym] = value
26
- end
27
- hash
28
- end
29
-
30
- module Helpers
31
- def old_interactor name, *args
32
- args = add_compatibility_pavlov_options args
33
- Pavlov.old_interactor name, *args
34
- end
35
-
36
- def old_query name, *args
37
- args = add_compatibility_pavlov_options args
38
- Pavlov.old_query name, *args
39
- end
40
-
41
- def old_command name, *args
42
- args = add_compatibility_pavlov_options args
43
- Pavlov.old_command name, *args
44
- end
45
-
46
- private
47
-
48
- def add_compatibility_pavlov_options args
49
- # TODO: we should do this at a point where we know how many arguments we need
50
- # so we can decide if we need to merge with another options object or
51
- # just add it.
52
- new_args = Array(args)
53
- new_args << pavlov_options unless pavlov_options == {}
54
- new_args
55
- end
56
- end
57
-
58
4
  class ValidationError < StandardError
59
5
  end
60
6
 
@@ -20,8 +20,6 @@ module Pavlov
20
20
 
21
21
  def with_pavlov_options hash
22
22
  if pavlov_options != {}
23
- hash ||= {}
24
-
25
23
  if hash.has_key? 'pavlov_options'
26
24
  hash[:pavlov_options] = pavlov_options.merge(hash[:pavlov_options])
27
25
  else
@@ -12,32 +12,32 @@ module Pavlov
12
12
  include Pavlov::Helpers
13
13
  include Virtus
14
14
 
15
- def validate
16
- return false if attributes_without_defaults_missing_values?
17
-
18
- raise Pavlov::ValidationError, 'an argument is invalid' unless valid?
19
-
20
- true
21
- end
22
-
23
15
  def valid?
16
+ check_validation
24
17
  true
18
+ rescue Pavlov::ValidationError
19
+ false
25
20
  end
26
21
 
27
22
  def call(*args, &block)
28
- validate
23
+ check_validation
29
24
  check_authorization
30
25
  execute(*args, &block)
31
26
  end
32
27
 
33
28
  private
34
29
 
30
+ def check_authorization
31
+ raise_unauthorized unless authorized?
32
+ end
33
+
35
34
  def raise_unauthorized(message = 'Unauthorized')
36
35
  raise Pavlov::AccessDenied, message
37
36
  end
38
37
 
39
- def check_authorization
40
- raise_unauthorized unless authorized?
38
+ def check_validation
39
+ raise Pavlov::ValidationError, 'some arguments were not given' if attributes_without_defaults_missing_values?
40
+ raise Pavlov::ValidationError, 'an argument is invalid' unless validate
41
41
  end
42
42
 
43
43
  def attributes_without_defaults_missing_values?
@@ -46,6 +46,10 @@ module Pavlov
46
46
  end
47
47
  end
48
48
 
49
+ def validate
50
+ true # no-op, users should override this
51
+ end
52
+
49
53
  module ClassMethods
50
54
  # make our interactors behave as Resque jobs
51
55
  def perform(*args)
@@ -2,5 +2,5 @@ module Pavlov
2
2
  # We're doing this because we might write tests that deal
3
3
  # with other versions of bundler and we are unsure how to
4
4
  # handle this better.
5
- VERSION = '0.1.6'
5
+ VERSION = '0.1.7'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pavlov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marten Veldthuis
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2013-08-13 00:00:00.000000000 Z
16
+ date: 2013-08-15 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: virtus