pavlov 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pavlov.rb +22 -8
- data/lib/pavlov/alpha_compatibility.rb +36 -27
- data/lib/pavlov/concern.rb +5 -5
- data/lib/pavlov/helpers.rb +5 -7
- data/lib/pavlov/operation.rb +4 -4
- 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: 31594240b64696361ea5deeb4a506ba17c5cd1c8
|
4
|
+
data.tar.gz: 1e8ccb1439a90046a11496bb6fa35c68209f5752
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ddbe50610a56b8b4d0b52c4875cd3b3b2cd1652fe535fa179143316db2ed1254edce5fa3de0ab3b0c3c3f32f19869939e129d3c7206152ba85aadc032d46307
|
7
|
+
data.tar.gz: 83bd809253f41acaa8a3c11931950a4d6585ff99151b4919a7138c1d4c92884c5616cdaead48be9c91982c4e10966eb0eea8ec9e52df12545da93d5986490192
|
data/lib/pavlov.rb
CHANGED
@@ -10,22 +10,36 @@ module Pavlov
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.command command_name, *args
|
13
|
-
|
14
|
-
klass = get_class_by_string(class_name)
|
13
|
+
klass = class_for_command(command_name)
|
15
14
|
klass.new(*args).call
|
16
15
|
end
|
17
16
|
|
18
|
-
def self.interactor
|
19
|
-
|
20
|
-
klass = get_class_by_string class_name
|
17
|
+
def self.interactor interactor_name, *args
|
18
|
+
klass = class_for_interactor(interactor_name)
|
21
19
|
klass.new(*args).call
|
22
20
|
end
|
23
21
|
|
24
|
-
def self.query
|
25
|
-
|
26
|
-
klass = get_class_by_string class_name
|
22
|
+
def self.query query_name, *args
|
23
|
+
klass = class_for_query(query_name)
|
27
24
|
klass.new(*args).call
|
28
25
|
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def self.class_for_command command_name
|
30
|
+
class_name = 'Commands::' + string_to_classname(command_name)
|
31
|
+
get_class_by_string(class_name)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.class_for_interactor interactor_name
|
35
|
+
class_name = 'Interactors::' + string_to_classname(interactor_name)
|
36
|
+
get_class_by_string(class_name)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.class_for_query query_name
|
40
|
+
class_name = 'Queries::' + string_to_classname(query_name)
|
41
|
+
get_class_by_string(class_name)
|
42
|
+
end
|
29
43
|
end
|
30
44
|
|
31
45
|
require_relative 'pavlov/engine' if defined?(Rails)
|
@@ -2,35 +2,29 @@ require 'pavlov'
|
|
2
2
|
|
3
3
|
module Pavlov
|
4
4
|
def self.old_command command_name, *args
|
5
|
-
|
6
|
-
|
7
|
-
attributes = arguments_to_attributes(klass, args)
|
8
|
-
klass.new(attributes).call
|
5
|
+
klass = class_for_command(command_name)
|
6
|
+
command command_name, arguments_to_attributes(klass, args)
|
9
7
|
end
|
10
8
|
|
11
|
-
def self.old_interactor
|
12
|
-
|
13
|
-
|
14
|
-
attributes = arguments_to_attributes(klass, args)
|
15
|
-
klass.new(attributes).call
|
9
|
+
def self.old_interactor interactor_name, *args
|
10
|
+
klass = class_for_interactor(interactor_name)
|
11
|
+
interactor interactor_name, arguments_to_attributes(klass, args)
|
16
12
|
end
|
17
13
|
|
18
|
-
def self.old_query
|
19
|
-
|
20
|
-
|
21
|
-
attributes = arguments_to_attributes(klass, args)
|
22
|
-
klass.new(attributes).call
|
14
|
+
def self.old_query query_name, *args
|
15
|
+
klass = class_for_query(query_name)
|
16
|
+
query query_name, arguments_to_attributes(klass, args)
|
23
17
|
end
|
24
18
|
|
25
19
|
def self.arguments_to_attributes(operation_class, arguments)
|
26
20
|
attribute_keys = operation_class.attribute_set.map(&:name)
|
27
21
|
|
28
22
|
# TODO: this can be done so much better, but I don't know how.
|
29
|
-
hash={}
|
23
|
+
hash = {}
|
30
24
|
arguments.each_with_index do |value, index|
|
31
25
|
hash[attribute_keys[index].to_sym] = value
|
32
26
|
end
|
33
|
-
|
27
|
+
hash
|
34
28
|
end
|
35
29
|
|
36
30
|
module Helpers
|
@@ -50,14 +44,13 @@ module Pavlov
|
|
50
44
|
end
|
51
45
|
|
52
46
|
private
|
47
|
+
|
53
48
|
def add_compatibility_pavlov_options args
|
54
49
|
# TODO: we should do this at a point where we know how many arguments we need
|
55
50
|
# so we can decide if we need to merge with another options object or
|
56
51
|
# just add it.
|
57
52
|
new_args = Array(args)
|
58
|
-
|
59
|
-
new_args << pavlov_options
|
60
|
-
end
|
53
|
+
new_args << pavlov_options unless pavlov_options == {}
|
61
54
|
new_args
|
62
55
|
end
|
63
56
|
end
|
@@ -67,36 +60,52 @@ module Pavlov
|
|
67
60
|
|
68
61
|
module Validations
|
69
62
|
def validate_hexadecimal_string param_name, param
|
70
|
-
|
63
|
+
return if param.is_a?(String) && /\A[\da-fA-F]+\Z/.match(param)
|
64
|
+
|
65
|
+
raise Pavlov::ValidationError, "#{param_name.to_s} should be an hexadecimal string."
|
71
66
|
end
|
72
67
|
|
73
68
|
def validate_regex param_name, param, regex, message
|
74
|
-
|
69
|
+
return if regex.match param
|
70
|
+
|
71
|
+
raise Pavlov::ValidationError, "#{param_name.to_s} #{message}"
|
75
72
|
end
|
76
73
|
|
77
74
|
def validate_integer param_name, param, opts = {}
|
78
75
|
return if opts[:allow_blank] && param.blank?
|
79
|
-
|
76
|
+
return if param.is_a?(Integer)
|
77
|
+
|
78
|
+
raise Pavlov::ValidationError, "#{param_name.to_s} should be an integer."
|
80
79
|
end
|
81
80
|
|
82
81
|
def validate_in_set param_name, param, set
|
83
|
-
|
82
|
+
return if set.include? param
|
83
|
+
|
84
|
+
raise Pavlov::ValidationError, "#{param_name.to_s} should be on of these values: #{set.inspect}."
|
84
85
|
end
|
85
86
|
|
86
87
|
def validate_string param_name, param
|
87
|
-
|
88
|
+
return if param.is_a?(String)
|
89
|
+
|
90
|
+
raise Pavlov::ValidationError, "#{param_name.to_s} should be a string."
|
88
91
|
end
|
89
92
|
|
90
93
|
def validate_nonempty_string param_name, param
|
91
|
-
|
94
|
+
return if param.is_a?(String) && !param.empty?
|
95
|
+
|
96
|
+
raise Pavlov::ValidationError, "#{param_name.to_s} should be a nonempty string."
|
92
97
|
end
|
93
98
|
|
94
99
|
def validate_integer_string param_name, param
|
95
|
-
|
100
|
+
return if param.is_a?(String) && /\A\d+\Z/.match(param)
|
101
|
+
|
102
|
+
raise Pavlov::ValidationError, "#{param_name.to_s} should be an integer string."
|
96
103
|
end
|
97
104
|
|
98
105
|
def validate_not_nil param_name, param
|
99
|
-
|
106
|
+
return unless param.nil?
|
107
|
+
|
108
|
+
raise Pavlov::ValidationError, "#{param_name.to_s} should not be nil."
|
100
109
|
end
|
101
110
|
end
|
102
111
|
|
data/lib/pavlov/concern.rb
CHANGED
@@ -27,19 +27,19 @@
|
|
27
27
|
module Pavlov
|
28
28
|
module Concern
|
29
29
|
def self.extended(base)
|
30
|
-
base.instance_variable_set(
|
30
|
+
base.instance_variable_set('@_dependencies', [])
|
31
31
|
end
|
32
32
|
|
33
33
|
def append_features(base)
|
34
|
-
if base.instance_variable_defined?(
|
35
|
-
base.instance_variable_get(
|
34
|
+
if base.instance_variable_defined?('@_dependencies')
|
35
|
+
base.instance_variable_get('@_dependencies') << self
|
36
36
|
return false
|
37
37
|
else
|
38
38
|
return false if base < self
|
39
39
|
@_dependencies.each { |dep| base.send(:include, dep) }
|
40
40
|
super
|
41
|
-
base.extend const_get(
|
42
|
-
base.class_eval(&@_included_block) if instance_variable_defined?(
|
41
|
+
base.extend const_get('ClassMethods') if const_defined?('ClassMethods')
|
42
|
+
base.class_eval(&@_included_block) if instance_variable_defined?('@_included_block')
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
data/lib/pavlov/helpers.rb
CHANGED
@@ -1,18 +1,15 @@
|
|
1
1
|
module Pavlov
|
2
2
|
module Helpers
|
3
3
|
def interactor name, hash
|
4
|
-
|
5
|
-
Pavlov.interactor name, hash
|
4
|
+
Pavlov.interactor name, with_pavlov_options(hash)
|
6
5
|
end
|
7
6
|
|
8
7
|
def query name, hash
|
9
|
-
|
10
|
-
Pavlov.query name, hash
|
8
|
+
Pavlov.query name, with_pavlov_options(hash)
|
11
9
|
end
|
12
10
|
|
13
11
|
def command name, hash
|
14
|
-
|
15
|
-
Pavlov.command name, hash
|
12
|
+
Pavlov.command name, with_pavlov_options(hash)
|
16
13
|
end
|
17
14
|
|
18
15
|
def pavlov_options
|
@@ -20,7 +17,8 @@ module Pavlov
|
|
20
17
|
end
|
21
18
|
|
22
19
|
private
|
23
|
-
|
20
|
+
|
21
|
+
def with_pavlov_options hash
|
24
22
|
if pavlov_options != {}
|
25
23
|
hash ||= {}
|
26
24
|
|
data/lib/pavlov/operation.rb
CHANGED
@@ -12,7 +12,7 @@ module Pavlov
|
|
12
12
|
def validate
|
13
13
|
return false unless attributes_without_defaults_have_values
|
14
14
|
if respond_to? :valid?
|
15
|
-
raise Pavlov::ValidationError,
|
15
|
+
raise Pavlov::ValidationError, 'an argument is invalid' unless valid?
|
16
16
|
else
|
17
17
|
true
|
18
18
|
end
|
@@ -26,17 +26,17 @@ module Pavlov
|
|
26
26
|
|
27
27
|
private
|
28
28
|
|
29
|
-
def raise_unauthorized(message='Unauthorized')
|
29
|
+
def raise_unauthorized(message = 'Unauthorized')
|
30
30
|
raise Pavlov::AccessDenied, message
|
31
31
|
end
|
32
32
|
|
33
33
|
def check_authorization
|
34
|
-
raise_unauthorized if respond_to?
|
34
|
+
raise_unauthorized if respond_to?(:authorized?, true) && !authorized?
|
35
35
|
end
|
36
36
|
|
37
37
|
def attributes_without_defaults_have_values
|
38
38
|
attributes_without_value = attribute_set.select do |attribute|
|
39
|
-
|
39
|
+
!attribute.options.has_key?(:default) && send(attribute.name).nil?
|
40
40
|
end
|
41
41
|
attributes_without_value.empty?
|
42
42
|
end
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- marten@veldthuis.com
|
@@ -13,7 +13,7 @@ authors:
|
|
13
13
|
autorequire:
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
|
-
date: 2013-08-
|
16
|
+
date: 2013-08-07 00:00:00.000000000 Z
|
17
17
|
dependencies:
|
18
18
|
- !ruby/object:Gem::Dependency
|
19
19
|
name: virtus
|