skn_utils 2.0.3 → 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +4 -0
- data/lib/skn_utils/{action_service.rb → exploring/action_service.rb} +27 -25
- data/lib/skn_utils/exploring/commander.rb +68 -0
- data/lib/skn_utils/version.rb +13 -2
- data/lib/skn_utils.rb +2 -2
- data/spec/lib/skn_utils/action_service_spec.rb +3 -3
- data/spec/lib/skn_utils/commander_spec.rb +3 -3
- data/spec/spec_helper.rb +3 -0
- metadata +4 -4
- data/lib/skn_utils/commander.rb +0 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb76906e8c9a9acc4a24c4f3d901a82a4a75551e
|
4
|
+
data.tar.gz: 5c837b3b0237136a0d26f9819360c5223b49f0e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17ae5f8c61d19c3aed3e5b4915c68b341a2ac4f45da80b8a2841bafc620a88af72c245b45271782d3d748abce12406e712a53d7004b800c87bb75f82ed88c5b7
|
7
|
+
data.tar.gz: 3baa78fcdb3f07c458a5b9b5b378d971ec68a7b9828489e1971386a14dafce68929eef868c16ed790a80919d26e574a1fd4551b0ee2fb46a125b722d2a784b4e
|
data/README.rdoc
CHANGED
@@ -23,6 +23,10 @@ into the input params key ':enable_serialization' set to true. It defaults to f
|
|
23
23
|
=== New Features
|
24
24
|
--------------------------------
|
25
25
|
|
26
|
+
08/2016 V2.0.3
|
27
|
+
Added an exploritory ActionService class and RSpec test, triggered by reading [Kamil Lelonek](https://blog.lelonek.me/what-service-objects-are-not-7abef8aa2f99#.p64vudxq4)
|
28
|
+
I don't support his approach, but the CreateTask class caught my attention as a Rubyist.
|
29
|
+
|
26
30
|
12/2015 V2.0
|
27
31
|
All references to ActiveRecord or Rails has been removed to allow use in non-Rails environments
|
28
32
|
as a result serialization is done with standard Ruby Hash serialization methods; by first transforming
|
@@ -2,42 +2,44 @@
|
|
2
2
|
#
|
3
3
|
# Exploritory Action/Service Class
|
4
4
|
# Ref: https://blog.lelonek.me/what-service-objects-are-not-7abef8aa2f99#.p64vudxq4
|
5
|
+
# http://sporto.github.io/blog/2012/11/15/a-pattern-for-service-objects-in-rails/
|
5
6
|
#
|
6
7
|
# Not a template or abstract class, Just an Example of an Action class
|
7
8
|
#
|
8
9
|
|
9
10
|
module SknUtils
|
10
|
-
|
11
|
+
module Exploring
|
12
|
+
class ActionService
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
def call(*command_and_params)
|
17
|
-
puts "Called with: #{command_and_params}"
|
18
|
-
value = command_and_params
|
19
|
-
if value.first.is_a?(Symbol)
|
20
|
-
(value.size == 1 ? self.send(value.first) : self.send(value.first, value[1..-1]))
|
21
|
-
else
|
22
|
-
puts('No Action Taken')
|
14
|
+
def initialize(dependency_injection_arguments)
|
15
|
+
@thingy = dependency_injection_arguments
|
23
16
|
end
|
24
17
|
|
25
|
-
|
26
|
-
|
18
|
+
def call(*command_and_params)
|
19
|
+
puts "Called with: #{command_and_params}"
|
20
|
+
if command_and_params.first.is_a?(Symbol)
|
21
|
+
(command_and_params.size == 1 ? self.send(command_and_params.first) : self.send(command_and_params.first, command_and_params[1..-1]))
|
22
|
+
else
|
23
|
+
puts('No Action Taken')
|
24
|
+
end
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
def action_one
|
31
|
-
puts "#{__method__}() #{@thingy}"
|
32
|
-
true
|
33
|
-
end
|
26
|
+
self
|
27
|
+
end
|
34
28
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
29
|
+
private
|
30
|
+
# a bunch of private methods
|
31
|
+
def action_one
|
32
|
+
puts "#{__method__}() #{@thingy}"
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
def action_two(parm)
|
37
|
+
puts "#{__method__} => #{parm} #{@thingy}"
|
38
|
+
true
|
39
|
+
end
|
39
40
|
|
40
|
-
|
41
|
+
end # end class
|
42
|
+
end # end module
|
41
43
|
end # end module
|
42
44
|
|
43
45
|
|
@@ -0,0 +1,68 @@
|
|
1
|
+
##
|
2
|
+
# <project.root>/lib/skn_utils/exploring/commander.rb
|
3
|
+
##
|
4
|
+
# ref: https://github.com/saturnflyer/direction
|
5
|
+
##
|
6
|
+
# Provide a feature like the Forwardable library,
|
7
|
+
# but set the return value to self.
|
8
|
+
# It provides a class level "command" method to do
|
9
|
+
# message forwarding.
|
10
|
+
#
|
11
|
+
# class SomeClass
|
12
|
+
# extend SknUtils::Commander
|
13
|
+
#
|
14
|
+
# command [:print_details, :setup_things] => :collaborator
|
15
|
+
# query [:name, :id] => :collaborator, :type => :@partner
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
# This will define methods on instances that forward to the
|
19
|
+
# provided receiver while enforcing encapsulation of the
|
20
|
+
# relationship between objects.
|
21
|
+
#
|
22
|
+
# the collaborator and you must agree on how results can be exchanged
|
23
|
+
# you might provide a callback method for it to set its return value on you
|
24
|
+
# :callback, develop a protocol to exchange messages with collaborator
|
25
|
+
##
|
26
|
+
|
27
|
+
|
28
|
+
module SknUtils
|
29
|
+
module Exploring
|
30
|
+
module Commander
|
31
|
+
|
32
|
+
# Forward messages and return self, protecting the encapsulation of the object
|
33
|
+
def command(options)
|
34
|
+
Commander.define_methods(self, options) do |command, accessor|
|
35
|
+
%{
|
36
|
+
def #{command}(*args, &block)
|
37
|
+
#{accessor}.__send__(:#{command}, *args, &block)
|
38
|
+
self
|
39
|
+
end
|
40
|
+
}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Forward messages and return the result of the forwarded message
|
45
|
+
def query(options)
|
46
|
+
Commander.define_methods(self, options) do |query, accessor|
|
47
|
+
%{
|
48
|
+
def #{query}(*args, &block)
|
49
|
+
#{accessor}.__send__(:#{query}, *args, &block)
|
50
|
+
end
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# Commander's class method
|
56
|
+
def self.define_methods(mod, options)
|
57
|
+
method_defs = []
|
58
|
+
options.each_pair do |method_names, accessor|
|
59
|
+
Array(method_names).map do |message|
|
60
|
+
method_defs.push yield(message, accessor)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
mod.class_eval method_defs.join("\n"), __FILE__, __LINE__
|
64
|
+
end
|
65
|
+
|
66
|
+
end # Commander
|
67
|
+
end # Exploring
|
68
|
+
end # SknUtils
|
data/lib/skn_utils/version.rb
CHANGED
data/lib/skn_utils.rb
CHANGED
@@ -5,8 +5,8 @@ require 'skn_utils/generic_bean'
|
|
5
5
|
require 'skn_utils/page_controls'
|
6
6
|
require 'skn_utils/result_bean'
|
7
7
|
require 'skn_utils/value_bean'
|
8
|
-
require 'skn_utils/commander'
|
9
|
-
require 'skn_utils/action_service'
|
8
|
+
require 'skn_utils/exploring/commander'
|
9
|
+
require 'skn_utils/exploring/action_service'
|
10
10
|
|
11
11
|
module SknUtils
|
12
12
|
|
@@ -1,10 +1,10 @@
|
|
1
1
|
##
|
2
|
-
# spec/lib/skn_utils/action_service_spec.rb
|
2
|
+
# spec/lib/skn_utils/exploring/action_service_spec.rb
|
3
3
|
#
|
4
4
|
|
5
|
-
RSpec.describe SknUtils::ActionService, "Example Service Object class with command interface." do
|
5
|
+
RSpec.describe SknUtils::Exploring::ActionService, "Example Service Object class with command interface." do
|
6
6
|
let(:action) {
|
7
|
-
SknUtils::ActionService.new('Thingys')
|
7
|
+
SknUtils::Exploring::ActionService.new('Thingys')
|
8
8
|
}
|
9
9
|
|
10
10
|
context "Handles Bad Input. " do
|
@@ -4,7 +4,7 @@
|
|
4
4
|
#
|
5
5
|
|
6
6
|
class Person
|
7
|
-
extend SknUtils::Commander
|
7
|
+
extend SknUtils::Exploring::Commander
|
8
8
|
command [:make_me_a_sandwich, :cook, :blocky] => :@friend
|
9
9
|
query [:activities, :go, :say_what] => :friend
|
10
10
|
attr_accessor :friend
|
@@ -60,7 +60,7 @@ module Activities
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
RSpec.describe SknUtils::Commander, 'command' do
|
63
|
+
RSpec.describe SknUtils::Exploring::Commander, 'command' do
|
64
64
|
let(:friend){ Friend.new }
|
65
65
|
let(:person){ person = Person.new
|
66
66
|
person.friend = friend
|
@@ -95,7 +95,7 @@ RSpec.describe SknUtils::Commander, 'command' do
|
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
|
-
RSpec.describe SknUtils::Commander, 'query' do
|
98
|
+
RSpec.describe SknUtils::Exploring::Commander, 'query' do
|
99
99
|
let(:friend){ Friend.new }
|
100
100
|
let(:person){ person = Person.new
|
101
101
|
person.friend = friend
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: skn_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Scott Jr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-09-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -91,9 +91,9 @@ files:
|
|
91
91
|
- README.rdoc
|
92
92
|
- Rakefile
|
93
93
|
- lib/skn_utils.rb
|
94
|
-
- lib/skn_utils/action_service.rb
|
95
94
|
- lib/skn_utils/attribute_helpers.rb
|
96
|
-
- lib/skn_utils/
|
95
|
+
- lib/skn_utils/exploring/action_service.rb
|
96
|
+
- lib/skn_utils/exploring/commander.rb
|
97
97
|
- lib/skn_utils/generic_bean.rb
|
98
98
|
- lib/skn_utils/nested_result_base.rb
|
99
99
|
- lib/skn_utils/page_controls.rb
|
data/lib/skn_utils/commander.rb
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
##
|
2
|
-
# <project.root>/lib/skn_utils/commander.rb
|
3
|
-
##
|
4
|
-
# ref: https://github.com/saturnflyer/direction
|
5
|
-
##
|
6
|
-
# Provide a feature like the Forwardable library,
|
7
|
-
# but set the return value to self.
|
8
|
-
# It provides a class level "command" method to do
|
9
|
-
# message forwarding.
|
10
|
-
#
|
11
|
-
# class SomeClass
|
12
|
-
# extend SknUtils::Commander
|
13
|
-
#
|
14
|
-
# command [:print_details, :setup_things] => :collaborator
|
15
|
-
# query [:name, :id] => :collaborator, :type => :@partner
|
16
|
-
# end
|
17
|
-
#
|
18
|
-
# This will define methods on instances that forward to the
|
19
|
-
# provided receiver while enforcing encapsulation of the
|
20
|
-
# relationship between objects.
|
21
|
-
#
|
22
|
-
# the collaborator and you must agree on how results can be exchanged
|
23
|
-
# you might provide a callback method for it to set its return value on you
|
24
|
-
# :callback, develop a protocol to exchange messages with collaborator
|
25
|
-
##
|
26
|
-
|
27
|
-
|
28
|
-
module SknUtils
|
29
|
-
module Commander
|
30
|
-
|
31
|
-
# Forward messages and return self, protecting the encapsulation of the object
|
32
|
-
def command(options)
|
33
|
-
Commander.define_methods(self, options) do |command, accessor|
|
34
|
-
%{
|
35
|
-
def #{command}(*args, &block)
|
36
|
-
#{accessor}.__send__(:#{command}, *args, &block)
|
37
|
-
self
|
38
|
-
end
|
39
|
-
}
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# Forward messages and return the result of the forwarded message
|
44
|
-
def query(options)
|
45
|
-
Commander.define_methods(self, options) do |query, accessor|
|
46
|
-
%{
|
47
|
-
def #{query}(*args, &block)
|
48
|
-
#{accessor}.__send__(:#{query}, *args, &block)
|
49
|
-
end
|
50
|
-
}
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
# Commander's class method
|
55
|
-
def self.define_methods(mod, options)
|
56
|
-
method_defs = []
|
57
|
-
options.each_pair do |method_names, accessor|
|
58
|
-
Array(method_names).map do |message|
|
59
|
-
method_defs.push yield(message, accessor)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
mod.class_eval method_defs.join("\n"), __FILE__, __LINE__
|
63
|
-
end
|
64
|
-
|
65
|
-
end # Commander
|
66
|
-
end # SknUtils
|