pavlov 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pavlov/alpha_compatibility.rb +0 -54
- data/lib/pavlov/helpers.rb +0 -2
- data/lib/pavlov/operation.rb +15 -11
- data/lib/pavlov/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32f5a2414ffc45283f8602bafb5f8715a4e99a26
|
4
|
+
data.tar.gz: 642831b040f9a90ebe6b8633488a7ffbbb9dc797
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
|
data/lib/pavlov/helpers.rb
CHANGED
data/lib/pavlov/operation.rb
CHANGED
@@ -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
|
-
|
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
|
40
|
-
|
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)
|
data/lib/pavlov/version.rb
CHANGED
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.
|
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-
|
16
|
+
date: 2013-08-15 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: virtus
|