skn_utils 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/README.md +40 -24
- data/README.rdoc +21 -14
- data/lib/skn_utils/commander.rb +66 -0
- data/lib/skn_utils/value_bean.rb +20 -0
- data/lib/skn_utils/version.rb +1 -1
- data/lib/skn_utils.rb +2 -0
- data/skn_utils.gemspec +4 -8
- data/spec/lib/skn_utils/commander_spec.rb +125 -0
- data/spec/spec_helper.rb +0 -1
- metadata +18 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16db7b3b33003706dd1edab8aaf65a4af517f383
|
4
|
+
data.tar.gz: d4c20f62a0723f50657e6025a62579f0c8c799a5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe7fcee2998180166c6ebc4491170afcde6fd8b7973aaa72c1bb2122ca518a9545bbc81a51716f5a4ec9f59b35fe74ff4e6bf087a538aee9426989d9fbe41ec9
|
7
|
+
data.tar.gz: 33f8b0fbe884fd40feb53876b4e316260f80a6d53f284bf31ab11c1ba7797fffec8c63162ea57afebcff81b028e33c82a1bde4f75e1c7568e56ca8b462e2f3ff
|
data/.gitignore
CHANGED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
SknUtils
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.2.3
|
data/README.md
CHANGED
@@ -1,62 +1,77 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/skn_utils.svg)](http://badge.fury.io/rb/skn_utils)
|
2
2
|
|
3
3
|
# SknUtils
|
4
|
-
|
4
|
+
Ruby Gem containing a Ruby PORO (Plain Old Ruby Object) that can be instantiated at runtime with an input hash. This library creates
|
5
5
|
an Object with instance variables and associated getters and setters for Dot or Hash notational access to each instance variable. Additional
|
6
6
|
instance variables can be added post-create by 'obj.my_new_var = "some value"', or simply assigning it.
|
7
7
|
|
8
8
|
|
9
|
-
The intent of this gem is to be a container of data results, with easy access to its contents with on-demand transformation back to a hash (#to_hash)
|
9
|
+
The intent of this gem is to be a container of data results or value bean, with easy access to its contents with on-demand transformation back to a hash (#to_hash)
|
10
10
|
for easy serialization using standard ruby Hash serialization methods.
|
11
11
|
|
12
|
+
|
13
|
+
* Transforms the initialization hash into object instance variables, with their Keys as the method names.
|
12
14
|
* If the key's value is also a hash, it too can optionally become an Object.
|
13
15
|
* if the key's value is a Array of Hashes, each element of the Array can optionally become an Object.
|
16
|
+
|
14
17
|
|
15
|
-
|
16
|
-
|
18
|
+
This nesting action is controlled by the value of the options key ':depth'.
|
19
|
+
The key :depth defaults to :multi, and has options of :single, :multi, or :multi_with_arrays
|
17
20
|
|
18
|
-
|
19
|
-
|
21
|
+
The ability of the resulting Object to be Marshalled(dump/load) can be preserved by merging configuration options
|
22
|
+
into the input params key ':enable_serialization' set to true. It defaults to false for speed purposes
|
20
23
|
|
21
24
|
|
22
25
|
### New Features
|
23
26
|
--------------------------------
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
|
28
|
+
02/2015 V2.0.2
|
29
|
+
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
|
+
which allows to use :command instead of :Forwardable to implement a portion of the 'Eastward' methodology.
|
31
|
+
|
32
|
+
12/2015 V2.0
|
33
|
+
All references to ActiveRecord or Rails has been removed to allow use in non-Rails environments
|
34
|
+
as a result serialization is done with standard Ruby Hash serialization methods; by first transforming
|
35
|
+
object back to a hash using its #to_hash method.
|
36
|
+
|
37
|
+
06/2015 V1.5.1 commit #67ef656
|
38
|
+
Last Version to depend on Rails (ActiveModel) for #to_json and #to_xml serialization
|
27
39
|
|
28
40
|
|
29
41
|
### Configuration Options
|
30
42
|
--------------------------------
|
31
43
|
|
32
|
-
|
33
|
-
|
44
|
+
Include in initialization hash
|
45
|
+
:enable_serialization = false -- [ true | false ], for speed, omits creation of attr_accessor
|
46
|
+
:depth = :multi -- [ :single | :multi | :multi_with_arrays ]
|
34
47
|
|
35
48
|
|
36
49
|
### Public Methods
|
37
50
|
--------------------------------
|
38
51
|
|
39
52
|
Each concrete Class supports the following utility methods:
|
40
|
-
#depth_level -- returns parsing depth level, see :depth
|
41
|
-
#serialization_required? -- returns true/false if serialization is enabled
|
42
53
|
#to_hash -- returns a hash of all user attributes
|
43
|
-
#to_hash(true) -- returns a hash of all user and internal attributes
|
54
|
+
#to_hash(true) -- returns a hash of all user and internal attributes -- use for serialization
|
44
55
|
#[] -- returns value of attr, when #[<attr_name_symbol>]
|
45
56
|
#[]=(attr, value) -- assigns value to existing attr, or creates a new key/value pair
|
46
|
-
#clear_<attr> -- assigns nil to existing attr, when #clear_attr
|
47
57
|
#<attr>? -- detects true/false presence? of attr, and non-blank existance of attr's value; when #address?
|
48
58
|
#<attr> -- returns value of named attribute
|
49
59
|
#<attr> = (value) -- assigns value to existing attr, or creates a new key/value pair
|
50
|
-
-- Where <attr> is a key value from the initial hash, or a key that was dynamically added
|
60
|
+
-- Where <attr> is a key value from the initial hash, or a key that was/will be dynamically added
|
61
|
+
|
62
|
+
#depth_level -- returns parsing depth level, see :depth
|
63
|
+
#serialization_required? -- returns true/false if serialization is enabled
|
64
|
+
#clear_<attr> -- assigns nil to existing attr, when #clear_attr
|
51
65
|
|
52
66
|
|
53
67
|
### Public Components
|
54
68
|
--------------------------------
|
55
69
|
|
56
70
|
Inherit from NestedResultBase or instantiate an pre-built Class:
|
57
|
-
SknUtils::
|
58
|
-
SknUtils::PageControls # => Serializable
|
59
|
-
SknUtils::
|
71
|
+
SknUtils::ResultBean # => Not Serializable and follows hash values only.
|
72
|
+
SknUtils::PageControls # => Serializable and follows hash values and arrays of hashes.
|
73
|
+
SknUtils::GenericBean # => Serializable and follows hash values only.
|
74
|
+
SknUtils::ValueBean # => Serializable and DOES NOT follows hash values.
|
60
75
|
or Include AttributeHelpers # => Add getter/setters, and hash notation access to instance vars of any object.
|
61
76
|
|
62
77
|
|
@@ -68,7 +83,7 @@ for easy serialization using standard ruby Hash serialization methods.
|
|
68
83
|
'x = obj["value1"]'
|
69
84
|
'x = obj[:value1]'
|
70
85
|
|
71
|
-
- enables serialization by avoiding the use of ''singleton_class'' methods which breaks Serializers:
|
86
|
+
- enables serialization by avoiding the use of ''singleton_class'' methods, #attr_accessor, which breaks Serializers:
|
72
87
|
Serializer supports #to_hash, and standard Marshall''ing. Notice use of #to_hash to convert object back to a Ruby Hash before
|
73
88
|
using #to_json and #to_xml; presumed to be methods enabled on the standard Ruby Hash class.
|
74
89
|
|
@@ -101,11 +116,11 @@ The combination of this NestedResultBase(dot notation class) and AttributeHelper
|
|
101
116
|
drb = SknUtils::ResultBean.new(params) Basic dot notation: effect of :depth
|
102
117
|
---------------------------------------------------- -----------------------------------------------------------------
|
103
118
|
|
104
|
-
(DOES NOT FOLLOW Values)
|
119
|
+
(DOES NOT FOLLOW Values) :depth => :single
|
105
120
|
```ruby
|
106
121
|
* params = {one: 1, drb.one = 1
|
107
122
|
two: { one: 1, drb.two = {one: 1, two: 'two}
|
108
|
-
|
123
|
+
two: "two" drb.two.two = NoMethodError
|
109
124
|
},
|
110
125
|
three: [ {one: 'one', two: 2}, drb.three = [{one: 'one', two: 2},{three: 'three', four: 4}]
|
111
126
|
{three: 'three', four: 4} drb.three[1] = {three: 'three', four: 4}
|
@@ -113,7 +128,7 @@ The combination of this NestedResultBase(dot notation class) and AttributeHelper
|
|
113
128
|
}
|
114
129
|
```
|
115
130
|
|
116
|
-
(Follow VALUES that are Hashes only.)
|
131
|
+
(Follow VALUES that are Hashes only.) :depth => :multi
|
117
132
|
```ruby
|
118
133
|
* params = {one: 1, drb.one = 1
|
119
134
|
two: { one: 1, drb.two = <SknUtils::ResultBean>
|
@@ -125,7 +140,7 @@ The combination of this NestedResultBase(dot notation class) and AttributeHelper
|
|
125
140
|
}
|
126
141
|
```
|
127
142
|
|
128
|
-
(Follow VALUES that are Hashes and/or Arrays of Hashes)
|
143
|
+
(Follow VALUES that are Hashes and/or Arrays of Hashes) :depth => :multi_with_arrays
|
129
144
|
```ruby
|
130
145
|
* params = {one: 1, drb.one = 1
|
131
146
|
two: { one: 1, drb.two = <SknUtils::ResultBean>
|
@@ -195,6 +210,7 @@ Use GenericBean or PageControls if serialization is needed, they initialize with
|
|
195
210
|
|
196
211
|
## Installation
|
197
212
|
----------------
|
213
|
+
|
198
214
|
runtime prereqs:
|
199
215
|
V2+ None
|
200
216
|
V1+ gem 'active_model', '~> 3.0'
|
data/README.rdoc
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
[![Gem Version](https://badge.fury.io/rb/skn_utils.svg)](http://badge.fury.io/rb/skn_utils)
|
2
2
|
|
3
3
|
= SknUtils
|
4
|
-
|
4
|
+
Ruby Gem containing a Ruby PORO (Plain Old Ruby Object) that can be instantiated at runtime with an input hash. This library creates
|
5
5
|
an Object with instance variables and associated getters and setters for Dot or Hash notational access to each instance variable. Additional
|
6
6
|
instance variables can be added post-create by 'obj.my_new_var = "some value"', or simply assigning it.
|
7
7
|
|
@@ -9,21 +9,27 @@ instance variables can be added post-create by 'obj.my_new_var = "some value"',
|
|
9
9
|
The intent of this gem is to be a container of data results, with easy access to its contents with on-demand transformation back to a hash (#to_hash)
|
10
10
|
for easy serialization using standard ruby Hash serialization methods.
|
11
11
|
|
12
|
+
* Transforms the initialization hash into object instance variables, with their Keys as the variable names
|
12
13
|
* If the key's value is also a hash, it too can optionally become an Object.
|
13
14
|
* if the key's value is a Array of Hashes, each element of the Array can optionally become an Object.
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
This nesting action is controlled by the value of the options key ':depth'.
|
17
|
+
The key :depth defaults to :multi, and has options of :single, :multi, or :multi_with_arrays
|
17
18
|
|
18
|
-
|
19
|
-
|
19
|
+
The ability of the resulting Object to be Marshalled(dump/load) can be preserved by merging configuration options
|
20
|
+
into the input params key ':enable_serialization' set to true. It defaults to false for speed purposes
|
20
21
|
|
21
22
|
|
22
23
|
=== New Features
|
23
24
|
--------------------------------
|
24
|
-
|
25
|
-
|
26
|
-
|
25
|
+
|
26
|
+
12/2015 V2.0
|
27
|
+
All references to ActiveRecord or Rails has been removed to allow use in non-Rails environments
|
28
|
+
as a result serialization is done with standard Ruby Hash serialization methods; by first transforming
|
29
|
+
object back to a hash using its #to_hash method.
|
30
|
+
|
31
|
+
06/2015 V1.5.1 commit #67ef656
|
32
|
+
Last Version to depend on Rails (ActiveModel) for #to_json and #to_xml serialization
|
27
33
|
|
28
34
|
|
29
35
|
=== Configuration Options
|
@@ -53,10 +59,10 @@ for easy serialization using standard ruby Hash serialization methods.
|
|
53
59
|
=== Public Components
|
54
60
|
--------------------------------
|
55
61
|
|
56
|
-
Inherit from NestedResultBase or instantiate
|
57
|
-
SknUtils::
|
58
|
-
SknUtils::PageControls # => Serializable
|
59
|
-
SknUtils::
|
62
|
+
Inherit from NestedResultBase or instantiate a pre-built Class:
|
63
|
+
SknUtils::ResultBean # => Not Serializable and follows hash values only.
|
64
|
+
SknUtils::PageControls # => Serializable and follows hash values and arrays of hashes.
|
65
|
+
SknUtils::GenericBean # => Serializable and follows hash values only.
|
60
66
|
or Include AttributeHelpers # => Add getter/setters, and hash notation access to instance vars of any object.
|
61
67
|
|
62
68
|
|
@@ -68,7 +74,7 @@ for easy serialization using standard ruby Hash serialization methods.
|
|
68
74
|
'x = obj["value1"]'
|
69
75
|
'x = obj[:value1]'
|
70
76
|
|
71
|
-
- enables serialization by avoiding the use of ''singleton_class'' methods which breaks Serializers:
|
77
|
+
- enables serialization by avoiding the use of ''singleton_class'' methods, #attr_accessor, which breaks Serializers:
|
72
78
|
Serializer supports #to_hash, and standard Marshall''ing. Notice use of #to_hash to convert object back to a Ruby Hash before
|
73
79
|
using #to_json and #to_xml; presumed to be methods enabled on the standard Ruby Hash class.
|
74
80
|
|
@@ -105,7 +111,7 @@ The combination of this NestedResultBase(dot notation class) and AttributeHelper
|
|
105
111
|
```ruby
|
106
112
|
* params = {one: 1, drb.one = 1
|
107
113
|
two: { one: 1, drb.two = {one: 1, two: 'two}
|
108
|
-
|
114
|
+
two: "two" drb.two.two = NoMethodError
|
109
115
|
},
|
110
116
|
three: [ {one: 'one', two: 2}, drb.three = [{one: 'one', two: 2},{three: 'three', four: 4}]
|
111
117
|
{three: 'three', four: 4} drb.three[1] = {three: 'three', four: 4}
|
@@ -196,6 +202,7 @@ Use GenericBean or PageControls if serialization is needed, they initialize with
|
|
196
202
|
== Installation
|
197
203
|
----------------
|
198
204
|
runtime prereqs:
|
205
|
+
|
199
206
|
V2+ None
|
200
207
|
V1+ gem 'active_model', '~> 3.0'
|
201
208
|
|
@@ -0,0 +1,66 @@
|
|
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
|
@@ -0,0 +1,20 @@
|
|
1
|
+
##
|
2
|
+
# <project.root>/lib/skn_utils/generic_bean.rb
|
3
|
+
#
|
4
|
+
# *** See SknUtils::NestedResultBase for details ***
|
5
|
+
#
|
6
|
+
##
|
7
|
+
# (Defaults)
|
8
|
+
# :enable_serialization = true
|
9
|
+
# :depth = :single
|
10
|
+
|
11
|
+
module SknUtils
|
12
|
+
|
13
|
+
class ValueBean < NestedResultBase
|
14
|
+
#:nodoc:
|
15
|
+
def initialize(params={})
|
16
|
+
super( params.merge({enable_serialization: true, depth: :single}) )
|
17
|
+
end
|
18
|
+
end # end class
|
19
|
+
|
20
|
+
end # end module
|
data/lib/skn_utils/version.rb
CHANGED
data/lib/skn_utils.rb
CHANGED
data/skn_utils.gemspec
CHANGED
@@ -19,12 +19,8 @@ EOF
|
|
19
19
|
|
20
20
|
spec.description = <<EOF
|
21
21
|
Creates an PORO Object with instance variables and associated getters and setters for each input key, during runtime.
|
22
|
-
|
23
|
-
|
24
|
-
If a key's value is also a hash, it too can optionally become an Object.
|
25
|
-
|
26
|
-
|
27
|
-
If a key's value is a Array of Hashes, each element of the Array can optionally become an Object.
|
22
|
+
If a key's value is also a hash, it too can optionally become an Object.
|
23
|
+
If a key's value is a Array of Hashes, each element of the Array can optionally become an Object.
|
28
24
|
|
29
25
|
|
30
26
|
This nesting action is controlled by the value of the options key ':depth'. Options key :depth defaults
|
@@ -32,7 +28,7 @@ to :multi, and has options of :single, :multi, or :multi_with_arrays
|
|
32
28
|
|
33
29
|
|
34
30
|
The ability of the resulting Object to be Marshalled(dump/load) can be preserved by merging configuration options
|
35
|
-
into the input params
|
31
|
+
into the input params. Key ':enable_serialization' set to true. It defaults to false for speed purposes.
|
36
32
|
|
37
33
|
|
38
34
|
Review the RSpec tests, and or review the README for more details.
|
@@ -54,6 +50,6 @@ EOF
|
|
54
50
|
## Make sure you can build the gem on older versions of RubyGems too:
|
55
51
|
spec.rubygems_version = "1.6.2"
|
56
52
|
spec.required_rubygems_version = Gem::Requirement.new(">= 0") if spec.respond_to? :required_rubygems_version=
|
57
|
-
spec.required_ruby_version = '
|
53
|
+
spec.required_ruby_version = '~> 2.0'
|
58
54
|
spec.specification_version = 3 if spec.respond_to? :specification_version
|
59
55
|
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
##
|
2
|
+
# spec/lib/skn_utils/commander_spec.rb
|
3
|
+
#
|
4
|
+
#
|
5
|
+
|
6
|
+
class Person
|
7
|
+
extend SknUtils::Commander
|
8
|
+
command [:make_me_a_sandwich, :cook, :blocky] => :@friend
|
9
|
+
query [:activities, :go, :say_what] => :friend
|
10
|
+
attr_accessor :friend
|
11
|
+
end
|
12
|
+
|
13
|
+
class Friend
|
14
|
+
def make_me_a_sandwich
|
15
|
+
Table.place "a sandwich!"
|
16
|
+
end
|
17
|
+
|
18
|
+
def cook(what)
|
19
|
+
Table.place what
|
20
|
+
end
|
21
|
+
|
22
|
+
def activities
|
23
|
+
'running, biking, hiking'
|
24
|
+
end
|
25
|
+
|
26
|
+
def go(do_what)
|
27
|
+
Activities.record do_what
|
28
|
+
end
|
29
|
+
|
30
|
+
def blocky(text)
|
31
|
+
Activities.record([yield(self).to_s,text].join(' '))
|
32
|
+
end
|
33
|
+
|
34
|
+
def say_what(text)
|
35
|
+
[yield(self).to_s,text].join(' ')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module Table
|
40
|
+
def self.place(text)
|
41
|
+
contents << text
|
42
|
+
end
|
43
|
+
def self.contents
|
44
|
+
@contents ||= []
|
45
|
+
end
|
46
|
+
def self.clear
|
47
|
+
@contents = []
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
module Activities
|
52
|
+
def self.record(text)
|
53
|
+
list << text
|
54
|
+
end
|
55
|
+
def self.list
|
56
|
+
@list ||= []
|
57
|
+
end
|
58
|
+
def self.clear
|
59
|
+
@list = []
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
RSpec.describe SknUtils::Commander, 'command' do
|
64
|
+
let(:friend){ Friend.new }
|
65
|
+
let(:person){ person = Person.new
|
66
|
+
person.friend = friend
|
67
|
+
person
|
68
|
+
}
|
69
|
+
before do
|
70
|
+
Table.clear
|
71
|
+
Activities.clear
|
72
|
+
end
|
73
|
+
it 'forwards a message to another object' do
|
74
|
+
expect(Table.contents).to eq []
|
75
|
+
person.make_me_a_sandwich
|
76
|
+
expect(Table.contents).to include "a sandwich!"
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'returns the original receiver' do
|
80
|
+
expect( person).to eq person.make_me_a_sandwich
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'forwards additional arguments' do
|
84
|
+
expect(Table.contents).to eq []
|
85
|
+
person.cook('yum')
|
86
|
+
expect(Table.contents).to include "yum"
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'forwards block arguments' do
|
90
|
+
expect(Activities.list).to eq []
|
91
|
+
person.blocky('yay!') do |friend|
|
92
|
+
"Arguments forwarded to #{friend}"
|
93
|
+
end
|
94
|
+
expect(Activities.list).to include "Arguments forwarded to #{friend} yay!"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
RSpec.describe SknUtils::Commander, 'query' do
|
99
|
+
let(:friend){ Friend.new }
|
100
|
+
let(:person){ person = Person.new
|
101
|
+
person.friend = friend
|
102
|
+
person
|
103
|
+
}
|
104
|
+
before do
|
105
|
+
Activities.clear
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'forwards a message to another object' do
|
109
|
+
expect(person.activities).to eq "running, biking, hiking"
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'forwards additional arguments' do
|
113
|
+
expect(Activities.list).to eq []
|
114
|
+
person.go('have fun')
|
115
|
+
expect(Activities.list).to include "have fun"
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'forwards block arguments' do
|
119
|
+
expect(Activities.list).to eq []
|
120
|
+
what_said = person.say_what('yay!') do |friend|
|
121
|
+
"Arguments forwarded to #{friend}"
|
122
|
+
end
|
123
|
+
expect(what_said).to eq "Arguments forwarded to #{friend} yay!"
|
124
|
+
end
|
125
|
+
end
|
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.2
|
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:
|
11
|
+
date: 2016-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -67,13 +67,13 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: "Creates an PORO Object with instance variables and associated getters
|
70
|
-
and setters for each input key, during runtime.\n
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
70
|
+
and setters for each input key, during runtime.\n If a key's value is also a hash,
|
71
|
+
it too can optionally become an Object.\n If a key's value is a Array of Hashes,
|
72
|
+
each element of the Array can optionally become an Object.\n\n \nThis nesting action
|
73
|
+
is controlled by the value of the options key ':depth'. Options key :depth defaults
|
74
|
+
\nto :multi, and has options of :single, :multi, or :multi_with_arrays\n\n \nThe
|
75
|
+
ability of the resulting Object to be Marshalled(dump/load) can be preserved by
|
76
|
+
merging configuration options\ninto the input params. Key ':enable_serialization'
|
77
77
|
set to true. It defaults to false for speed purposes.\n\n\nReview the RSpec tests,
|
78
78
|
and or review the README for more details.\n"
|
79
79
|
email: skoona@gmail.com
|
@@ -83,6 +83,8 @@ extra_rdoc_files: []
|
|
83
83
|
files:
|
84
84
|
- ".gitignore"
|
85
85
|
- ".rspec"
|
86
|
+
- ".ruby-gemset"
|
87
|
+
- ".ruby-version"
|
86
88
|
- Gemfile
|
87
89
|
- LICENSE
|
88
90
|
- README.md
|
@@ -90,12 +92,15 @@ files:
|
|
90
92
|
- Rakefile
|
91
93
|
- lib/skn_utils.rb
|
92
94
|
- lib/skn_utils/attribute_helpers.rb
|
95
|
+
- lib/skn_utils/commander.rb
|
93
96
|
- lib/skn_utils/generic_bean.rb
|
94
97
|
- lib/skn_utils/nested_result_base.rb
|
95
98
|
- lib/skn_utils/page_controls.rb
|
96
99
|
- lib/skn_utils/result_bean.rb
|
100
|
+
- lib/skn_utils/value_bean.rb
|
97
101
|
- lib/skn_utils/version.rb
|
98
102
|
- skn_utils.gemspec
|
103
|
+
- spec/lib/skn_utils/commander_spec.rb
|
99
104
|
- spec/lib/skn_utils/generic_bean_spec.rb
|
100
105
|
- spec/lib/skn_utils/page_controls_spec.rb
|
101
106
|
- spec/lib/skn_utils/result_bean_spec.rb
|
@@ -112,9 +117,9 @@ require_paths:
|
|
112
117
|
- lib
|
113
118
|
required_ruby_version: !ruby/object:Gem::Requirement
|
114
119
|
requirements:
|
115
|
-
- - "
|
120
|
+
- - "~>"
|
116
121
|
- !ruby/object:Gem::Version
|
117
|
-
version: 2.0
|
122
|
+
version: '2.0'
|
118
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
124
|
requirements:
|
120
125
|
- - ">="
|
@@ -122,7 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
127
|
version: '0'
|
123
128
|
requirements: []
|
124
129
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.4.
|
130
|
+
rubygems_version: 2.4.5.1
|
126
131
|
signing_key:
|
127
132
|
specification_version: 3
|
128
133
|
summary: Ruby convenience utilities, the first being a ResultBean. ResultBean is
|
@@ -131,10 +136,10 @@ summary: Ruby convenience utilities, the first being a ResultBean. ResultBean
|
|
131
136
|
via dot or hash notation, and is serializable (<obj>.to_hash) using standard Hash
|
132
137
|
serialization methods.
|
133
138
|
test_files:
|
139
|
+
- spec/lib/skn_utils/commander_spec.rb
|
134
140
|
- spec/lib/skn_utils/generic_bean_spec.rb
|
135
141
|
- spec/lib/skn_utils/page_controls_spec.rb
|
136
142
|
- spec/lib/skn_utils/result_bean_spec.rb
|
137
143
|
- spec/spec_helper.rb
|
138
144
|
- spec/support/shared_example_marshalable_ruby_pojo.rb
|
139
145
|
- spec/support/shared_example_ruby_pojo.rb
|
140
|
-
has_rdoc:
|