riker 0.1.0.pre5 → 0.1.0.pre6

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
  SHA256:
3
- metadata.gz: fd3f7e1ef08e3dd6db6362747a86a4adbff4acd42a90bd251bbde583c01d5eca
4
- data.tar.gz: 57c823093ded9ae1ec66fa7dcb6741385fd450072aa59eac0cf962ed0e32b74e
3
+ metadata.gz: bd22e31d55bf8c4144736d6b657463e2550b8a602711adfcc4e8339a164d16c6
4
+ data.tar.gz: 83b5819f498d4f86f89531f81df7ca845540b108a5cac03274a0fc9d9f0b1ede
5
5
  SHA512:
6
- metadata.gz: 92ae6575db90c03567fac3aa2b31d7350c1f616c011dc77c4a17c1cbb4cabc7ab2d630ac7a2311a8f6e341e08ec9fc1c26f162db047034f5122407bf0455185c
7
- data.tar.gz: 90d6f23aa9224096af1b06a7aaa53a2290e4f125076fedcc58a685829b05e75b68e3d46218842e7ea1d337db01583a149d4f4363a1f7271fec115cbf5ea79f65
6
+ metadata.gz: 7777cf030f8bf79ceaabd4da1a826b32be8cfcc8be0f32b262d1219839dd1268d24596ad3d83320d5eb6da2f15eb9dd31a870ef3f3d12eea53eec61f8bd27982
7
+ data.tar.gz: 818646ea533fefd5fe79580127585ed365af10352ee0f467aa84017a967a6afcdb0ed639f3933fc6c371bd0535b57c8d156b9b6d5066f32ea168e2372ed9bfbe
data/README.md CHANGED
@@ -12,7 +12,7 @@ High-Performance, Dependency-Free Command Pattern For Ruby
12
12
  ### In your gemfile:
13
13
 
14
14
  ```ruby
15
- gem 'riker', '0.1.0.pre5'
15
+ gem 'riker', '0.1.0.pre6'
16
16
  ```
17
17
 
18
18
  ### In your code:
@@ -95,3 +95,39 @@ CaptainsLog.run!(message: "The Borg are attacking!")
95
95
  CaptainsLog.run(message: "We've traveled back in time!", stardate: 42.1337)
96
96
  # => "Captain's Log; Stardate: 42.1337\n\nWe've traveled back in time!"
97
97
  ```
98
+
99
+ ## Measurement Code
100
+
101
+ Sometimes you'll want to do some logic around your commands to record
102
+ their performance, number of calls, etc. Rike allows for this with `around`.
103
+ The result of your measurement code in no way effects the result from
104
+ the command.
105
+
106
+ ```ruby
107
+ module SensorArray
108
+ class << self
109
+ # the class and args of the command are provided
110
+ def deep_scan(klass, args)
111
+ # anything before code runs
112
+
113
+ # code runs here
114
+ yield
115
+
116
+ # anything after you want
117
+ end
118
+ end
119
+ end
120
+
121
+ class CheckWarpDrive
122
+ extend Riker
123
+
124
+ param :stardate
125
+ param :engineer
126
+
127
+ around &SensorArray.method(:deep_scan)
128
+
129
+ execute do
130
+ "WarpDrive checked by #{engineer} on #{stardate}"
131
+ end
132
+ end
133
+ ```
@@ -14,6 +14,17 @@ module Riker
14
14
 
15
15
  # @return [Riker::Command::FunctionDetails]
16
16
  def details
17
+ if command.around_block
18
+ with_around_function_block
19
+ else
20
+ without_around_block_function
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ # @return [Riker::Command::FunctionDetails]
27
+ def without_around_block_function
17
28
  FunctionDetails.new(<<~RUBY, __FILE__, __LINE__ + 1)
18
29
  def self.run!(**arguments) # def self.run!(**arguments)
19
30
  command = new(**arguments) # command = new(**arguments)
@@ -25,6 +36,23 @@ module Riker
25
36
  end # end
26
37
  RUBY
27
38
  end
39
+
40
+ # @return [Riker::Command::FunctionDetails]
41
+ def with_around_function_block
42
+ FunctionDetails.new(<<~RUBY, __FILE__, __LINE__ + 1)
43
+ def self.run!(**arguments) # def self.run!(**arguments)
44
+ result = nil # result = nil
45
+ self.command.around_block.call(self, arguments) do # self.command.around_block.call(klass, arguments) do
46
+ command = new(**arguments) # command = new(**arguments)
47
+ result = command.execute # result = command.execute
48
+ if command.errored? # if command.errored?
49
+ command.errors.raise! # command.errors.raise!
50
+ end # end
51
+ end # end
52
+ result # result
53
+ end # end
54
+ RUBY
55
+ end
28
56
  end
29
57
  end
30
58
  end
@@ -14,6 +14,16 @@ module Riker
14
14
 
15
15
  # @return [Riker::Command::FunctionDetails]
16
16
  def details
17
+ if command.around_block
18
+ with_around_block_function
19
+ else
20
+ without_around_block_function
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def without_around_block_function
17
27
  FunctionDetails.new(<<~RUBY, __FILE__, __LINE__ + 1)
18
28
  def self.run(**arguments) # def self.run!(**arguments)
19
29
  command = new(**arguments) # command = new(**arguments)
@@ -26,6 +36,24 @@ module Riker
26
36
  end # end
27
37
  RUBY
28
38
  end
39
+
40
+ def with_around_block_function
41
+ FunctionDetails.new(<<~RUBY, __FILE__, __LINE__ + 1)
42
+ def self.run(**arguments) # def self.run!(**arguments)
43
+ outcome = nil # outcome = nil
44
+ self.command.around_block.call(self, arguments) do # self.command.around_block.call(self, arguments) do
45
+ command = new(**arguments) # command = new(**arguments)
46
+ result = command.execute # result = command.execute
47
+ outcome = if command.errored? # outcome = if command.errored?
48
+ Riker::Outcome.invalid(command.errors) # Riker::Outcome.invalid(command.errors)
49
+ else # else
50
+ Riker::Outcome.valid(result) # Riker::Outcome.valid(result)
51
+ end # end
52
+ end # end
53
+ outcome # outcome
54
+ end # end
55
+ RUBY
56
+ end
29
57
  end
30
58
  end
31
59
  end
data/lib/riker/command.rb CHANGED
@@ -22,6 +22,9 @@ module Riker
22
22
  # @return [Proc, nil]
23
23
  attr_accessor :execute_block
24
24
 
25
+ # @return [Proc, nil]
26
+ attr_accessor :around_block
27
+
25
28
  def initialize
26
29
  @parameters = Parameters.new
27
30
  @function_writer = FunctionWriter.new(self)
data/lib/riker/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Riker
4
- VERSION = '0.1.0.pre5'
4
+ VERSION = '0.1.0.pre6'
5
5
  end
data/lib/riker.rb CHANGED
@@ -31,4 +31,11 @@ module Riker
31
31
  command.execute_block = block
32
32
  command.function_writer.write!(self)
33
33
  end
34
+
35
+ # @block the logic to run around a command
36
+ def around(&block)
37
+ raise Error, "around block already called for #{self}!" if command.around_block
38
+
39
+ command.around_block = block
40
+ end
34
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: riker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.pre5
4
+ version: 0.1.0.pre6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Falk
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-21 00:00:00.000000000 Z
11
+ date: 2022-11-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: High-Performance, Dependency-Free Command Pattern For Ruby
14
14
  email: