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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6db99e4aeb953f51c21ff313dee110b9af305691
4
- data.tar.gz: 32a906192681346ab40052157e833ddd73d40bac
3
+ metadata.gz: eb76906e8c9a9acc4a24c4f3d901a82a4a75551e
4
+ data.tar.gz: 5c837b3b0237136a0d26f9819360c5223b49f0e6
5
5
  SHA512:
6
- metadata.gz: 0e6e5be4b0308853f81798dc2f0c599bd909c4353de6842e60d4f43cf6b09f58bda1e651845adc98f9338f7194b0ceacbf51638fe20349b2a96fb94acc0b9c72
7
- data.tar.gz: bf41ea172ab26025e58e2242ab9e7498f0cdaa42ddb4cac661de862c0d83ae85cae3ad19e3d863278ad5cd17a214086f4e2c0cbc29ed0a79f64cd91a8eb658a5
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
- class ActionService
11
+ module Exploring
12
+ class ActionService
11
13
 
12
- def initialize(dependency_injection_arguments)
13
- @thingy = dependency_injection_arguments
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
- self
26
- end
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
- private
29
- # a bunch of private methods
30
- def action_one
31
- puts "#{__method__}() #{@thingy}"
32
- true
33
- end
26
+ self
27
+ end
34
28
 
35
- def action_two(parm)
36
- puts "#{__method__} => #{parm} #{@thingy}"
37
- true
38
- end
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
- end # end class
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
@@ -1,3 +1,14 @@
1
+ # A better way to say it
1
2
  module SknUtils
2
- VERSION = "2.0.3"
3
- end
3
+ class Version
4
+ MAJOR = 2
5
+ MINOR = 0
6
+ PATCH = 4
7
+
8
+ def self.to_s
9
+ [MAJOR, MINOR, PATCH].join('.')
10
+ end
11
+ end
12
+
13
+ VERSION = Version.to_s
14
+ end
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
@@ -1,6 +1,9 @@
1
1
  ENV['RAILS_ENV'] ||= 'test'
2
2
 
3
3
  require 'skn_utils'
4
+ require 'skn_utils/exploring/commander'
5
+ require 'skn_utils/exploring/action_service'
6
+
4
7
  require 'rspec'
5
8
  require 'yaml'
6
9
 
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.3
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-08-27 00:00:00.000000000 Z
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/commander.rb
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
@@ -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