pavlov 0.1.7.1 → 0.1.8

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: 9758ce291059ff9041789760c3859314ca2dfd25
4
- data.tar.gz: 74b504eed67d6d0f91811dfe78c88b1142c6dad0
3
+ metadata.gz: c1b5c84ab82aad4e0ff3231c23c2ecb6c8511165
4
+ data.tar.gz: b031d26eb86570328beee0ace26d0594cb2bffd2
5
5
  SHA512:
6
- metadata.gz: 09587b7f4e809ef8050ce7ebac50bd91d557352382f8a648861ab3c65025d8900871e5258db93ed94a4b0a03e7cb33df3e198257f1372f37408ea63f39908158
7
- data.tar.gz: 66f927ebc21ce5168f01796d9c4eefa8986a969838d04f24e375726ebd76dbc13bd4ba073f857400875058ad75115f018bc04f95b7b9a75bbcce82d1cf975f2a
6
+ metadata.gz: 0db1daccbeaac3214a1383fa6efe0e883cd3f32d5c7fd201ffe4903c4889fbbd23e70c0e80988c6c245ea4bc1e985b68e6a20fa26d4bda17b2382ef2f77f15b1
7
+ data.tar.gz: 4a599d76b32385939a5699a3d6082753436691303d68e894108ada5ab3bd5639b1f4fe1bff6a18f3812643db4000ac4a9a6e67306901e92521de60d8464ee055
@@ -14,4 +14,4 @@ module Pavlov
14
14
  application "config.autoload_paths += %W(\#{config.root}/app/backend)"
15
15
  end
16
16
  end
17
- end
17
+ end
@@ -1,3 +1,3 @@
1
1
  class Backend
2
2
  # This class is a placeholder that will be expanded by a later feature branch
3
- end
3
+ end
@@ -1,14 +1,6 @@
1
- module Pavlov
2
- # this method is also available as constantize in Rails,
3
- # but we want to be able to write classes and/or tests without Rails
4
- def self.get_class_by_string classname
5
- classname.constantize
6
- end
7
-
8
- def self.string_to_classname string
9
- string.to_s.camelize
10
- end
1
+ require 'pavlov/support/inflector'
11
2
 
3
+ module Pavlov
12
4
  def self.command command_name, *args
13
5
  klass = class_for_command(command_name)
14
6
  klass.new(*args).call
@@ -27,22 +19,20 @@ module Pavlov
27
19
  private
28
20
 
29
21
  def self.class_for_command command_name
30
- class_name = 'Commands::' + string_to_classname(command_name)
31
- get_class_by_string(class_name)
22
+ OperationFinder.find(Commands, command_name)
32
23
  end
33
24
 
34
25
  def self.class_for_interactor interactor_name
35
- class_name = 'Interactors::' + string_to_classname(interactor_name)
36
- get_class_by_string(class_name)
26
+ OperationFinder.find(Interactors, interactor_name)
37
27
  end
38
28
 
39
29
  def self.class_for_query query_name
40
- class_name = 'Queries::' + string_to_classname(query_name)
41
- get_class_by_string(class_name)
30
+ OperationFinder.find(Queries, query_name)
42
31
  end
43
32
  end
44
33
 
45
34
  require_relative 'pavlov/engine' if defined?(Rails)
35
+ require_relative 'pavlov/operation_finder'
46
36
  require_relative 'pavlov/helpers'
47
37
  require_relative 'pavlov/access_denied'
48
38
  require_relative 'pavlov/operation'
@@ -8,50 +8,50 @@ module Pavlov
8
8
  def validate_hexadecimal_string param_name, param
9
9
  return if param.is_a?(String) && /\A[\da-fA-F]+\Z/.match(param)
10
10
 
11
- raise Pavlov::ValidationError, "#{param_name.to_s} should be an hexadecimal string."
11
+ errors.add param_name, 'should be an hexadecimal string.'
12
12
  end
13
13
 
14
14
  def validate_regex param_name, param, regex, message
15
15
  return if regex.match param
16
16
 
17
- raise Pavlov::ValidationError, "#{param_name.to_s} #{message}"
17
+ errors.add param_name, "#{message}"
18
18
  end
19
19
 
20
20
  def validate_integer param_name, param, opts = {}
21
21
  return if opts[:allow_blank] && param.blank?
22
22
  return if param.is_a?(Integer)
23
23
 
24
- raise Pavlov::ValidationError, "#{param_name.to_s} should be an integer."
24
+ errors.add param_name, 'should be an integer.'
25
25
  end
26
26
 
27
27
  def validate_in_set param_name, param, set
28
28
  return if set.include? param
29
29
 
30
- raise Pavlov::ValidationError, "#{param_name.to_s} should be on of these values: #{set.inspect}."
30
+ errors.add param_name, 'should be on of these values: #{set.inspect}.'
31
31
  end
32
32
 
33
33
  def validate_string param_name, param
34
34
  return if param.is_a?(String)
35
35
 
36
- raise Pavlov::ValidationError, "#{param_name.to_s} should be a string."
36
+ errors.add param_name, 'should be a string.'
37
37
  end
38
38
 
39
39
  def validate_nonempty_string param_name, param
40
40
  return if param.is_a?(String) && !param.empty?
41
41
 
42
- raise Pavlov::ValidationError, "#{param_name.to_s} should be a nonempty string."
42
+ errors.add param_name, 'should be a nonempty string.'
43
43
  end
44
44
 
45
45
  def validate_integer_string param_name, param
46
46
  return if param.is_a?(String) && /\A\d+\Z/.match(param)
47
47
 
48
- raise Pavlov::ValidationError, "#{param_name.to_s} should be an integer string."
48
+ errors.add param_name, 'should be an integer string.'
49
49
  end
50
50
 
51
51
  def validate_not_nil param_name, param
52
52
  return unless param.nil?
53
53
 
54
- raise Pavlov::ValidationError, "#{param_name.to_s} should not be nil."
54
+ errors.add param_name, 'should not be nil.'
55
55
  end
56
56
  end
57
57
 
@@ -63,9 +63,6 @@ module Pavlov
63
63
  args.each do |argument|
64
64
  attribute argument, Object, default: nil
65
65
  end
66
-
67
- # Add attribute for pavlov_options
68
- attribute :pavlov_options, Hash, default: {}
69
66
  end
70
67
  end
71
68
  end
@@ -3,4 +3,4 @@ require 'rails'
3
3
  module Pavlov
4
4
  class Engine < Rails::Engine
5
5
  end
6
- end
6
+ end
@@ -20,7 +20,7 @@ module Pavlov
20
20
 
21
21
  def with_pavlov_options hash
22
22
  if pavlov_options != {}
23
- if hash.has_key? 'pavlov_options'
23
+ if hash.key? 'pavlov_options'
24
24
  hash[:pavlov_options] = pavlov_options.merge(hash[:pavlov_options])
25
25
  else
26
26
  hash[:pavlov_options] = pavlov_options
@@ -3,6 +3,10 @@ require 'pavlov/helpers'
3
3
  require 'virtus'
4
4
  require_relative 'access_denied'
5
5
 
6
+ require 'active_model'
7
+ require 'active_model/naming'
8
+ require 'active_model/errors'
9
+
6
10
  module Pavlov
7
11
  class ValidationError < StandardError
8
12
  end
@@ -10,17 +14,28 @@ module Pavlov
10
14
  module Operation
11
15
  extend Pavlov::Concern
12
16
  include Pavlov::Helpers
13
- include Virtus
17
+
18
+ included do
19
+ include Virtus
20
+ extend ActiveModel::Naming
21
+ extend ActiveModel::Translation
22
+
23
+ attribute :pavlov_options, Hash, default: {}
24
+ end
25
+
26
+ def errors
27
+ @errors ||= ActiveModel::Errors.new(self)
28
+ end
14
29
 
15
30
  def valid?
16
31
  check_validation
17
- true
32
+ errors.empty?
18
33
  rescue Pavlov::ValidationError
19
34
  false
20
35
  end
21
36
 
22
37
  def call(*args, &block)
23
- check_validation
38
+ raise Pavlov::ValidationError, 'Some validations fail, cannot execute' unless valid?
24
39
  check_authorization
25
40
  execute(*args, &block)
26
41
  end
@@ -42,7 +57,7 @@ module Pavlov
42
57
 
43
58
  def missing_arguments
44
59
  attribute_set.select do |attribute|
45
- !attribute.options.has_key?(:default) && send(attribute.name).nil?
60
+ !attribute.options.key?(:default) && send(attribute.name).nil?
46
61
  end
47
62
  end
48
63
 
@@ -0,0 +1,32 @@
1
+ require 'pavlov/support/inflector'
2
+
3
+ module Pavlov
4
+ class OperationFinder
5
+ attr_reader :namespace
6
+
7
+ def self.find(namespace, operation_name)
8
+ operation_lookup_list = Inflector.camelize(operation_name.to_s).split('::')
9
+ operation_lookup_list.reduce(namespace) do |current_namespace, namespace_or_operation_name|
10
+ new(current_namespace).send(namespace_or_operation_name)
11
+ end
12
+ end
13
+
14
+ def initialize(namespace)
15
+ @namespace = namespace
16
+ end
17
+
18
+ def method_missing(name, attributes = {})
19
+ find_klass(name)
20
+ end
21
+
22
+ def respond_to_missing?(name, include_private = false)
23
+ find_klass(name)
24
+ end
25
+
26
+ private
27
+
28
+ def find_klass(name)
29
+ namespace.const_get(Inflector.camelize(name.to_s), false)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,15 @@
1
+ require 'backports/rails/string'
2
+
3
+ module Pavlov
4
+ class Inflector
5
+ def self.camelize(string, first_letter = :upper)
6
+ # Feel free to reimplement if you want to get rid of backports dependency.
7
+ string.camelize
8
+ end
9
+
10
+ def self.constantize(string)
11
+ # Feel free to reimplement if you want to get rid of backports dependency.
12
+ string.constantize
13
+ end
14
+ end
15
+ end
@@ -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.7.1'
5
+ VERSION = '0.1.8'
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.7.1
4
+ version: 0.1.8
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-19 00:00:00.000000000 Z
16
+ date: 2013-10-01 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: virtus
@@ -29,6 +29,34 @@ dependencies:
29
29
  - - '='
30
30
  - !ruby/object:Gem::Version
31
31
  version: 0.5.5
32
+ - !ruby/object:Gem::Dependency
33
+ name: backports
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: '3.3'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '3.3'
46
+ - !ruby/object:Gem::Dependency
47
+ name: activemodel
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: 3.2.7
53
+ type: :runtime
54
+ prerelease: false
55
+ version_requirements: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - '>='
58
+ - !ruby/object:Gem::Version
59
+ version: 3.2.7
32
60
  - !ruby/object:Gem::Dependency
33
61
  name: rspec
34
62
  requirement: !ruby/object:Gem::Requirement
@@ -187,7 +215,9 @@ files:
187
215
  - lib/pavlov/helpers.rb
188
216
  - lib/pavlov/interactor.rb
189
217
  - lib/pavlov/operation.rb
218
+ - lib/pavlov/operation_finder.rb
190
219
  - lib/pavlov/query.rb
220
+ - lib/pavlov/support/inflector.rb
191
221
  - lib/pavlov/version.rb
192
222
  homepage: https://github.com/Factlink/pavlov/
193
223
  licenses: