skn_utils 2.0.2 → 2.0.3
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 +4 -4
- data/README.md +4 -0
- data/lib/skn_utils/action_service.rb +88 -0
- data/lib/skn_utils/attribute_helpers.rb +1 -0
- data/lib/skn_utils/nested_result_base.rb +16 -15
- data/lib/skn_utils/version.rb +1 -1
- data/lib/skn_utils.rb +1 -0
- data/spec/lib/skn_utils/action_service_spec.rb +40 -0
- data/spec/lib/skn_utils/result_bean_spec.rb +3 -0
- data/spec/lib/skn_utils/value_bean_spec.rb +96 -0
- data/spec/support/shared_example_ruby_pojo.rb +1 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6db99e4aeb953f51c21ff313dee110b9af305691
|
4
|
+
data.tar.gz: 32a906192681346ab40052157e833ddd73d40bac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e6e5be4b0308853f81798dc2f0c599bd909c4353de6842e60d4f43cf6b09f58bda1e651845adc98f9338f7194b0ceacbf51638fe20349b2a96fb94acc0b9c72
|
7
|
+
data.tar.gz: bf41ea172ab26025e58e2242ab9e7498f0cdaa42ddb4cac661de862c0d83ae85cae3ad19e3d863278ad5cd17a214086f4e2c0cbc29ed0a79f64cd91a8eb658a5
|
data/README.md
CHANGED
@@ -25,6 +25,10 @@ into the input params key ':enable_serialization' set to true. It defaults to f
|
|
25
25
|
### New Features
|
26
26
|
--------------------------------
|
27
27
|
|
28
|
+
08/2016 V2.0.3
|
29
|
+
Added an exploritory ActionService class and RSpec test, triggered by reading [Kamil Lelonek](https://blog.lelonek.me/what-service-objects-are-not-7abef8aa2f99#.p64vudxq4)
|
30
|
+
I don't support his approach, but the CreateTask class caught my attention as a Rubyist.
|
31
|
+
|
28
32
|
02/2015 V2.0.2
|
29
33
|
Added Jim Gay's Direction module, from his [Eastward Video](http://confreaks.tv/videos/rubyconf2014-eastward-ho-a-clear-path-through-ruby-with-oo)
|
30
34
|
which allows to use :command instead of :Forwardable to implement a portion of the 'Eastward' methodology.
|
@@ -0,0 +1,88 @@
|
|
1
|
+
## lib/skn_utils/action_service.rb
|
2
|
+
#
|
3
|
+
# Exploritory Action/Service Class
|
4
|
+
# Ref: https://blog.lelonek.me/what-service-objects-are-not-7abef8aa2f99#.p64vudxq4
|
5
|
+
#
|
6
|
+
# Not a template or abstract class, Just an Example of an Action class
|
7
|
+
#
|
8
|
+
|
9
|
+
module SknUtils
|
10
|
+
class ActionService
|
11
|
+
|
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')
|
23
|
+
end
|
24
|
+
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
# a bunch of private methods
|
30
|
+
def action_one
|
31
|
+
puts "#{__method__}() #{@thingy}"
|
32
|
+
true
|
33
|
+
end
|
34
|
+
|
35
|
+
def action_two(parm)
|
36
|
+
puts "#{__method__} => #{parm} #{@thingy}"
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
end # end class
|
41
|
+
end # end module
|
42
|
+
|
43
|
+
|
44
|
+
# - regular execution
|
45
|
+
# action = DoSomeAction.new.(arg1, arg2)
|
46
|
+
#
|
47
|
+
# action.('Mine')
|
48
|
+
# => Called with: ["Mine"]
|
49
|
+
# => "No Action Taken"
|
50
|
+
# => #<SknUtils::ActionService:0x007ffa62079c20 @thingy="Things">
|
51
|
+
#
|
52
|
+
# action.()
|
53
|
+
# =>Called with: []
|
54
|
+
# => "No Action Taken"
|
55
|
+
# => #<SknUtils::ActionService:0x007ffa62079c20 @thingy="Things">
|
56
|
+
#
|
57
|
+
# action.(:action_two,'samples')
|
58
|
+
# => Called with: [:action_two, "samples"]
|
59
|
+
# => action_two(["samples"]) with Thingy: Things
|
60
|
+
# => #<SknUtils::ActionService:0x007ffa62079c20 @thingy="Things">
|
61
|
+
#
|
62
|
+
# action.(:action_one,'samples')
|
63
|
+
# => Called with: [:action_one, "samples"]
|
64
|
+
# => action_one() Thingy: Things
|
65
|
+
# => #<SknUtils::ActionService:0x007ffa62079c20 @thingy="Things">
|
66
|
+
#
|
67
|
+
# action.(:action_one).(:action_two,'Always')
|
68
|
+
# => Called with: [:action_one]
|
69
|
+
# => action_one() Thingy: Things
|
70
|
+
# => Called with: [:action_two, "Always"]
|
71
|
+
# => action_two(["Always"]) with Thingy: Things
|
72
|
+
# => #<SknUtils::ActionService:0x007ffa62079c20 @thingy="Things">
|
73
|
+
#
|
74
|
+
# - with dependency injection
|
75
|
+
#
|
76
|
+
# def do_some_action
|
77
|
+
# DoSomeAction.new(http_adapter)
|
78
|
+
# end
|
79
|
+
#
|
80
|
+
# do_some_action.(arg1, arg2)
|
81
|
+
#
|
82
|
+
#
|
83
|
+
#
|
84
|
+
# - in tests
|
85
|
+
#
|
86
|
+
# let(:do_some_action) { DoSomeAction.new(fake_http_adapter) }
|
87
|
+
# it { is_expected.to be_connected }
|
88
|
+
#
|
@@ -36,7 +36,7 @@ module SknUtils
|
|
36
36
|
def initialize(params={})
|
37
37
|
@skn_enabled_depth = params.delete(:depth) {|not_found| :multi }
|
38
38
|
@skn_enable_serialization = params.delete(:enable_serialization) {|not_found| false }
|
39
|
-
case
|
39
|
+
case @skn_enabled_depth
|
40
40
|
when :single
|
41
41
|
single_level_initializer(params)
|
42
42
|
when :multi_with_arrays
|
@@ -99,22 +99,23 @@ module SknUtils
|
|
99
99
|
true
|
100
100
|
end
|
101
101
|
|
102
|
-
# Some keys have chars not suitable for symbol keys
|
102
|
+
# Some keys have chars not suitable for symbol keys => @,#,:,-
|
103
103
|
#:nodoc:
|
104
104
|
def clean_key(original)
|
105
|
-
formatted_key = original.to_s
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
end
|
117
|
-
|
105
|
+
formatted_key = original.to_s.gsub(/[#|@]/,'').gsub(/[:|-]/,'_')
|
106
|
+
|
107
|
+
# if /^[#|@|:]/.match(formatted_key) # filter out (@xsi) from '@xsi:type' keys
|
108
|
+
# label = /@(.+):(.+)/.match(formatted_key) || /[#|@|:](.+)/.match(formatted_key) || []
|
109
|
+
# formatted_key = case label.size
|
110
|
+
# when 1
|
111
|
+
# label[1].to_s
|
112
|
+
# when 2
|
113
|
+
# "#{label[1]}_#{label[2]}"
|
114
|
+
# else
|
115
|
+
# original # who knows what it was, give it back
|
116
|
+
# end
|
117
|
+
# end
|
118
|
+
# formatted_key
|
118
119
|
end
|
119
120
|
|
120
121
|
|
data/lib/skn_utils/version.rb
CHANGED
data/lib/skn_utils.rb
CHANGED
@@ -0,0 +1,40 @@
|
|
1
|
+
##
|
2
|
+
# spec/lib/skn_utils/action_service_spec.rb
|
3
|
+
#
|
4
|
+
|
5
|
+
RSpec.describe SknUtils::ActionService, "Example Service Object class with command interface." do
|
6
|
+
let(:action) {
|
7
|
+
SknUtils::ActionService.new('Thingys')
|
8
|
+
}
|
9
|
+
|
10
|
+
context "Handles Bad Input. " do
|
11
|
+
it "Handles invalid string input params" do
|
12
|
+
expect { action.('Samples') }.to output(/Samples/).to_stdout
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "Single Method Invocations. " do
|
17
|
+
it "Handles a call with no param" do
|
18
|
+
expect { action.() }.to output(/No Action Taken/).to_stdout
|
19
|
+
end
|
20
|
+
it "Handles a call with one param" do
|
21
|
+
expect { action.(:action_one) }.to output(/Thingys/).to_stdout
|
22
|
+
end
|
23
|
+
it "Handles a call with more than one param" do
|
24
|
+
expect { action.(:action_two, 'Wonderful') }.to output(/Wonderful/).to_stdout
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context "Chaining Method Invocations. " do
|
29
|
+
it "Handles calls with no params" do
|
30
|
+
expect { action.().() }.to output(/No Action Taken/).to_stdout
|
31
|
+
end
|
32
|
+
it "Handles a calls with one param" do
|
33
|
+
expect { action.(:action_one).(:action_one) }.to output(/Thingys/).to_stdout
|
34
|
+
end
|
35
|
+
it "Handles a calls with more than one param" do
|
36
|
+
expect { action.(:action_two, 'Wonderful').(:action_two, 'Marvelous') }.to output(/Wonderful/).to_stdout
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -35,6 +35,9 @@ RSpec.describe SknUtils::ResultBean, "Result Bean class - Basic usage." do
|
|
35
35
|
it "Supports - respond_to - methods, because it has accessor methods" do
|
36
36
|
expect(object).to respond_to(:one)
|
37
37
|
end
|
38
|
+
it "Supports - respond_to - methods, because it has respond_to_missing? method" do
|
39
|
+
expect(object.method(:one)).to be
|
40
|
+
end
|
38
41
|
end
|
39
42
|
|
40
43
|
shared_examples_for "retains initialization options" do
|
@@ -0,0 +1,96 @@
|
|
1
|
+
##
|
2
|
+
# spec/lib/skn_utils/Value_bean_spec.rb
|
3
|
+
#
|
4
|
+
|
5
|
+
RSpec.describe SknUtils::ValueBean, "Basic Value Bean class " do
|
6
|
+
let(:object) {
|
7
|
+
SknUtils::ValueBean.new({one: "one",
|
8
|
+
two: "two",
|
9
|
+
three: {four: 4, five: 5, six: {seven: 7, eight: "eight" }},
|
10
|
+
four: {any_key: "any value"}, five: []}
|
11
|
+
)
|
12
|
+
}
|
13
|
+
|
14
|
+
context "Internal Operations, assuming :dept => :multi and enable_serialization => true" do
|
15
|
+
it "Creates an empty bean if no params are passed" do
|
16
|
+
is_expected.to be
|
17
|
+
end
|
18
|
+
it "Can be Marshalled after dynamically adding a key/value." do
|
19
|
+
expect { object.fifty = {any_key: "any value"} }.not_to raise_error
|
20
|
+
expect { object.sixty = 60 }.not_to raise_error
|
21
|
+
dmp = obj = ""
|
22
|
+
expect { dmp = Marshal.dump(object) }.not_to raise_error
|
23
|
+
expect { obj = Marshal.load(dmp) }.not_to raise_error
|
24
|
+
expect(obj).to be_a(SknUtils::ValueBean)
|
25
|
+
expect(obj.fifty[:any_key]).to eql "any value"
|
26
|
+
expect(obj.sixty).to eql 60
|
27
|
+
end
|
28
|
+
it "Initializes from a hash" do
|
29
|
+
expect(SknUtils::ValueBean.new({one: "one", two: "two"})).to be
|
30
|
+
end
|
31
|
+
it "Does not modify the base class, only singleton instance methods" do
|
32
|
+
obj1 = SknUtils::ValueBean.new({one: "one", two: "two"})
|
33
|
+
obj2 = SknUtils::ValueBean.new({three: "3", four: "4"})
|
34
|
+
expect(obj1.one).to eql "one"
|
35
|
+
expect(obj2.three).to eql "3"
|
36
|
+
expect(obj2.one?).to be false
|
37
|
+
expect(obj1.three?).to be false
|
38
|
+
expect { obj1.three }.to raise_error NoMethodError
|
39
|
+
expect { obj2.one }.to raise_error NoMethodError
|
40
|
+
end
|
41
|
+
it "Supports - respond_to? - method, because it has accessors or method_missing coverage" do
|
42
|
+
expect(object).to respond_to(:one)
|
43
|
+
expect(object.one).to eql "one"
|
44
|
+
expect{ object.fifty = {any_key: "any value"} }.not_to raise_error
|
45
|
+
expect( object.fifty).not_to respond_to(:any_key)
|
46
|
+
end
|
47
|
+
it "nest objects if multi-level hash is given" do
|
48
|
+
expect(object.one).to be_eql("one")
|
49
|
+
expect(object.two).to be_eql("two")
|
50
|
+
expect(object.three).to be_a(Hash)
|
51
|
+
expect(object.three[:five]).to eq(5)
|
52
|
+
end
|
53
|
+
it "#attributes method returns a hash of all attributes and their values." do
|
54
|
+
expect(object.to_hash).to be_a(Hash)
|
55
|
+
expect(object.to_hash[:one]).to be_eql("one")
|
56
|
+
expect(object.to_hash[:three]).to be_a(Hash)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
shared_examples_for "retains initialization options" do
|
61
|
+
it "retains depth_level option flag" do
|
62
|
+
expect(@obj.depth_level).to eql(:single)
|
63
|
+
end
|
64
|
+
it "retains serialization option flag" do
|
65
|
+
expect(@obj.serialization_required?).to be true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "Basic Operations without marshaling " do
|
70
|
+
before :each do
|
71
|
+
@obj = object
|
72
|
+
end
|
73
|
+
|
74
|
+
it_behaves_like "retains initialization options"
|
75
|
+
it_behaves_like "marshalable ruby pojo"
|
76
|
+
end
|
77
|
+
context "Basic Operations after Yaml marshaling " do
|
78
|
+
before :each do
|
79
|
+
dmp = YAML::dump(object)
|
80
|
+
@obj = YAML::load(dmp)
|
81
|
+
end
|
82
|
+
|
83
|
+
it_behaves_like "retains initialization options"
|
84
|
+
it_behaves_like "marshalable ruby pojo"
|
85
|
+
end
|
86
|
+
context "Basic Operations after Marshal marshaling " do
|
87
|
+
before :each do
|
88
|
+
dmp = Marshal.dump(object)
|
89
|
+
@obj = Marshal.load(dmp)
|
90
|
+
end
|
91
|
+
|
92
|
+
it_behaves_like "retains initialization options"
|
93
|
+
it_behaves_like "marshalable ruby pojo"
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
@@ -49,6 +49,7 @@ RSpec.shared_examples "ruby pojo" do
|
|
49
49
|
context "transformations are enabled with " do
|
50
50
|
it "#attributes method returns a hash of all attributes and their values." do
|
51
51
|
expect(@obj.to_hash).to be_a(Hash)
|
52
|
+
expect(@obj.to_h).to be_a(Hash)
|
52
53
|
expect(@obj.to_hash[:one]).to be_eql("one")
|
53
54
|
expect(@obj.to_hash[:three]).to be_a(Hash)
|
54
55
|
end
|
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.3
|
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-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -91,6 +91,7 @@ files:
|
|
91
91
|
- README.rdoc
|
92
92
|
- Rakefile
|
93
93
|
- lib/skn_utils.rb
|
94
|
+
- lib/skn_utils/action_service.rb
|
94
95
|
- lib/skn_utils/attribute_helpers.rb
|
95
96
|
- lib/skn_utils/commander.rb
|
96
97
|
- lib/skn_utils/generic_bean.rb
|
@@ -100,10 +101,12 @@ files:
|
|
100
101
|
- lib/skn_utils/value_bean.rb
|
101
102
|
- lib/skn_utils/version.rb
|
102
103
|
- skn_utils.gemspec
|
104
|
+
- spec/lib/skn_utils/action_service_spec.rb
|
103
105
|
- spec/lib/skn_utils/commander_spec.rb
|
104
106
|
- spec/lib/skn_utils/generic_bean_spec.rb
|
105
107
|
- spec/lib/skn_utils/page_controls_spec.rb
|
106
108
|
- spec/lib/skn_utils/result_bean_spec.rb
|
109
|
+
- spec/lib/skn_utils/value_bean_spec.rb
|
107
110
|
- spec/spec_helper.rb
|
108
111
|
- spec/support/shared_example_marshalable_ruby_pojo.rb
|
109
112
|
- spec/support/shared_example_ruby_pojo.rb
|
@@ -136,10 +139,12 @@ summary: Ruby convenience utilities, the first being a ResultBean. ResultBean
|
|
136
139
|
via dot or hash notation, and is serializable (<obj>.to_hash) using standard Hash
|
137
140
|
serialization methods.
|
138
141
|
test_files:
|
142
|
+
- spec/lib/skn_utils/action_service_spec.rb
|
139
143
|
- spec/lib/skn_utils/commander_spec.rb
|
140
144
|
- spec/lib/skn_utils/generic_bean_spec.rb
|
141
145
|
- spec/lib/skn_utils/page_controls_spec.rb
|
142
146
|
- spec/lib/skn_utils/result_bean_spec.rb
|
147
|
+
- spec/lib/skn_utils/value_bean_spec.rb
|
143
148
|
- spec/spec_helper.rb
|
144
149
|
- spec/support/shared_example_marshalable_ruby_pojo.rb
|
145
150
|
- spec/support/shared_example_ruby_pojo.rb
|