pavlov 0.1.8.1 → 0.1.9.0

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
  SHA1:
3
- metadata.gz: 99aecac1d59af7be3c174ffef73dfa388bcc4303
4
- data.tar.gz: a24bd54ec64f2825b1b7b5983eb19a0444de4086
3
+ metadata.gz: 7016775c6f4c49897e44a7cbb1d47d1fc284737b
4
+ data.tar.gz: 704dd818710d73271e7d0f0862a4e24f2a2950d6
5
5
  SHA512:
6
- metadata.gz: b9fccb36eb44d786b958af7b4becf26563c14f61850873bec7f1529b79d6ae10ae87b137e5c32f3e9f0b4551b5e5c013b72cc6c50e0b904565230b3cf547c84b
7
- data.tar.gz: 59d5f566ffd250268b0ad8597c8b870e2ec0e1855eaa6dfaf32633f1580ca26d9f59ae9a081b38101c692788a84baaced11a712873853c47ea1851903efa030d
6
+ metadata.gz: 7cdee8b6889becdc1c16a2b99d7e5a62c5248727c97917045e170dff6760599051e5d91bfb696ce4955374874e1f1dc9d4894fd9f683c71a42f05bee01a5ad98
7
+ data.tar.gz: 9eb0569bd7484a6165ba338c28989019127cc21f40a2a7411d0fede73e53fb7a6a415cb7416f98d307e61cfa02be6c57021082aaef3dfc2650899610faee4629
@@ -1,33 +1,36 @@
1
1
  require 'pavlov/support/inflector'
2
2
 
3
3
  module Pavlov
4
- def self.command command_name, *args
5
- klass = class_for_command(command_name)
6
- klass.new(*args).call
7
- end
4
+ def self.command command_name, *args, &block
5
+ command = get_instance(Commands, command_name, *args)
8
6
 
9
- def self.interactor interactor_name, *args
10
- klass = class_for_interactor(interactor_name)
11
- klass.new(*args).call
7
+ call_or_yield_instance command, &block
12
8
  end
13
9
 
14
- def self.query query_name, *args
15
- klass = class_for_query(query_name)
16
- klass.new(*args).call
10
+ def self.interactor interactor_name, *args, &block
11
+ interactor = get_instance(Interactors, interactor_name, *args)
12
+
13
+ call_or_yield_instance interactor, &block
17
14
  end
18
15
 
19
- private
16
+ def self.query query_name, *args, &block
17
+ query = get_instance(Queries, query_name, *args)
20
18
 
21
- def self.class_for_command command_name
22
- OperationFinder.find(Commands, command_name)
19
+ call_or_yield_instance query, &block
23
20
  end
24
21
 
25
- def self.class_for_interactor interactor_name
26
- OperationFinder.find(Interactors, interactor_name)
22
+ private
23
+
24
+ def self.get_instance(klass, name, *args)
25
+ OperationFinder.find(klass, name).new(*args)
27
26
  end
28
27
 
29
- def self.class_for_query query_name
30
- OperationFinder.find(Queries, query_name)
28
+ def self.call_or_yield_instance operation, &block
29
+ if block.nil?
30
+ operation.call
31
+ else
32
+ block.call operation
33
+ end
31
34
  end
32
35
  end
33
36
 
@@ -1,15 +1,15 @@
1
1
  module Pavlov
2
2
  module Helpers
3
- def interactor name, hash = {}
4
- Pavlov.interactor name, with_pavlov_options(hash)
3
+ def interactor name, hash = {}, &block
4
+ Pavlov.interactor name, with_pavlov_options(hash), &block
5
5
  end
6
6
 
7
- def query name, hash = {}
8
- Pavlov.query name, with_pavlov_options(hash)
7
+ def query name, hash = {}, &block
8
+ Pavlov.query name, with_pavlov_options(hash), &block
9
9
  end
10
10
 
11
- def command name, hash = {}
12
- Pavlov.command name, with_pavlov_options(hash)
11
+ def command name, hash = {}, &block
12
+ Pavlov.command name, with_pavlov_options(hash), &block
13
13
  end
14
14
 
15
15
  def pavlov_options
@@ -35,7 +35,7 @@ module Pavlov
35
35
  end
36
36
 
37
37
  def call(*args, &block)
38
- raise Pavlov::ValidationError, 'Some validations fail, cannot execute' unless valid?
38
+ fail Pavlov::ValidationError, 'Some validations fail, cannot execute' unless valid?
39
39
  check_authorization
40
40
  execute(*args, &block)
41
41
  end
@@ -47,11 +47,11 @@ module Pavlov
47
47
  end
48
48
 
49
49
  def raise_unauthorized(message = 'Unauthorized')
50
- raise Pavlov::AccessDenied, message
50
+ fail Pavlov::AccessDenied, message
51
51
  end
52
52
 
53
53
  def check_validation
54
- raise Pavlov::ValidationError, "Missing arguments: #{missing_arguments.inspect}" if missing_arguments.any?
54
+ fail Pavlov::ValidationError, "Missing arguments: #{missing_arguments.inspect}" if missing_arguments.any?
55
55
  validate
56
56
  end
57
57
 
@@ -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.8.1'
5
+ VERSION = '0.1.9.0'
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.8.1
4
+ version: 0.1.9.0
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-10-01 00:00:00.000000000 Z
16
+ date: 2013-10-08 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: virtus