hexx 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/README.rdoc +32 -25
- data/lib/hexx/models.rb +1 -2
- data/lib/hexx/service/validations.rb +2 -0
- data/lib/hexx/service.rb +5 -2
- data/lib/hexx/version.rb +1 -1
- data/lib/hexx.rb +4 -6
- data/spec/spec_helper.rb +5 -1
- metadata +17 -19
- data/spec/initializers/coveralls.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44ade515af4a4044dce3725cf4a30ed2aef4da8e
|
4
|
+
data.tar.gz: 1c456b7fb78fe55d509019f03c0fbbce27a8f777
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 255b6f79bd8726ffae49218d4f66ea397766ae79d265a2cdd353306217b5beedb73286e3c620f8ee45f2e42e94bf8ebf353452d9e504bdb35340009d1ac9a629
|
7
|
+
data.tar.gz: acdc38e43842a7be485378975c1b3dacc7e99b4ee0c53c500f2f35c369f70da4a60242712067d7bea8bb9dd9e692641adbce06659dc6736db7555423852c5c84
|
data/README.rdoc
CHANGED
@@ -14,6 +14,10 @@ Provides:
|
|
14
14
|
* +Service+ base class for decoupling a domain business logics from a controller
|
15
15
|
* +Models+ module for extending domain models.
|
16
16
|
|
17
|
+
The module is expected to be used in PORO domain. For usage in active record
|
18
|
+
domains consider { hexx-active_record }[https://github.com/nepalez/hexx-active_record]
|
19
|
+
gem instead.
|
20
|
+
|
17
21
|
== Installation
|
18
22
|
|
19
23
|
Add this line to your application's Gemfile:
|
@@ -28,16 +32,16 @@ Or install it yourself as:
|
|
28
32
|
|
29
33
|
$ gem install hexx
|
30
34
|
|
31
|
-
==
|
35
|
+
== Pattern
|
36
|
+
|
37
|
+
Service objects decouple business logics from:
|
32
38
|
|
33
|
-
Service objects decouple business logics from both:
|
34
39
|
* Domain _models_ (entities).
|
35
40
|
* Delivery mechanism _controllers_ (such as Rails framework).
|
36
41
|
|
37
|
-
|
38
|
-
*Observer* (Listener) pattern
|
39
|
-
|
40
|
-
return their result to caller but notifies its subscribers instead.
|
42
|
+
To follow object oriented architecture Hexx services exploit the
|
43
|
+
*Observer* (Listener) pattern via { Wisper }[https://github.com/krisleech/wisper]
|
44
|
+
gem.
|
41
45
|
|
42
46
|
Some examples of this pattern implementation are available at the
|
43
47
|
{ wisper gem wiki }[https://github.com/krisleech/wisper/wiki].
|
@@ -48,7 +52,7 @@ A typical service object is shown below:
|
|
48
52
|
|
49
53
|
require 'hexx'
|
50
54
|
|
51
|
-
class
|
55
|
+
class AddItem < Hexx::Service
|
52
56
|
|
53
57
|
# whitelists parameters and defines corresponding attributes.
|
54
58
|
allow_params :name
|
@@ -58,8 +62,7 @@ A typical service object is shown below:
|
|
58
62
|
|
59
63
|
# runs a service
|
60
64
|
def run
|
61
|
-
|
62
|
-
# runs some
|
65
|
+
# a wrapper sends :error notification to listeners in case of any exception raised.
|
63
66
|
transaction
|
64
67
|
MyModel.save! name: name # name is defined by allow_params helper.
|
65
68
|
publish :success # notifies its listeners.
|
@@ -67,39 +70,43 @@ A typical service object is shown below:
|
|
67
70
|
end
|
68
71
|
end
|
69
72
|
|
70
|
-
Usage of the service (
|
73
|
+
Usage of the service (with a Rails controller):
|
71
74
|
|
72
75
|
class ItemsController < ActionController::Base
|
73
76
|
|
74
77
|
# Creates an item with given name
|
75
|
-
def
|
76
|
-
service =
|
78
|
+
def create
|
79
|
+
service = AddItem.new params.allow(:name)
|
77
80
|
service.subscribe self, prefix: :on
|
78
81
|
service.run
|
79
82
|
end
|
80
83
|
|
81
84
|
# Publishes a success message
|
82
|
-
def
|
83
|
-
|
85
|
+
def on_created(item, messages)
|
86
|
+
@item, @messages = item, messages
|
87
|
+
render "created", status: 201
|
84
88
|
end
|
85
89
|
|
86
90
|
# Publishes an error messages
|
87
|
-
def
|
91
|
+
def on_error(messages)
|
88
92
|
@messages = messages
|
89
93
|
render "error"
|
90
94
|
end
|
95
|
+
end
|
96
|
+
|
97
|
+
The controller knows nothing about the action itself. It only needs to
|
98
|
+
sort out a request and send it to a corresponding service.
|
91
99
|
|
92
|
-
|
93
|
-
for selection of proper service and responding to its results.
|
100
|
+
Any controller action does one thing only.
|
94
101
|
|
95
|
-
|
96
|
-
|
97
|
-
|
102
|
+
* +create+ action sorts out requests.
|
103
|
+
* both +on_success+ and +on_created+ listens to services and report their
|
104
|
+
results back to client.
|
98
105
|
|
99
106
|
=== Models and Entities
|
100
107
|
|
101
|
-
The module also defines
|
102
|
-
(entities). This allows coercion of
|
108
|
+
The module also defines <tt>Hexx::Models</tt> module to extend domain models
|
109
|
+
(entities). This allows coercion of attributes with +attr_coerced+ helper:
|
103
110
|
|
104
111
|
class User
|
105
112
|
extend Hexx::Models
|
@@ -114,8 +121,8 @@ The module also defines module <tt>Hexx::Models</tt> to extend domain models
|
|
114
121
|
user.name.class
|
115
122
|
# => ActiveSupport::Multibyte::Chars
|
116
123
|
|
117
|
-
The method
|
118
|
-
|
124
|
+
The method redefines both getter and setter and can be used for value
|
125
|
+
preparation:
|
119
126
|
|
120
127
|
class StrippedString < String
|
121
128
|
def initialize(value)
|
@@ -133,7 +140,7 @@ it to transform values by default:
|
|
133
140
|
|
134
141
|
== Relevant Links
|
135
142
|
|
136
|
-
|
143
|
+
* Matt Wynne's talk {Hexagonal Rails}[http://www.confreaks.com/videos/977-goruco2012-hexagonal-rails]
|
137
144
|
|
138
145
|
== License
|
139
146
|
|
data/lib/hexx/models.rb
CHANGED
data/lib/hexx/service.rb
CHANGED
data/lib/hexx/version.rb
CHANGED
data/lib/hexx.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
require "active_model"
|
2
2
|
require "wisper"
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
Dir[File.join(lib, "hexx/*.rb")].each { |file| require file }
|
7
|
-
|
8
|
-
# Namespace for the gem.
|
9
|
-
module Hexx
|
4
|
+
def files
|
5
|
+
@files ||= Dir[File.expand_path("../hexx/**/*.rb", __FILE__)]
|
10
6
|
end
|
7
|
+
|
8
|
+
files.each { |file| require file }
|
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
|
-
|
1
|
+
require "coveralls"
|
2
|
+
|
3
|
+
# Application root
|
4
|
+
root = File.expand_path "../..", __FILE__
|
2
5
|
|
3
6
|
# Support files and Rspec settings
|
4
7
|
Dir[File.join(root, "spec/initializers/*.rb")].each { |file| require file }
|
5
8
|
|
6
9
|
# Application files
|
10
|
+
Coveralls.wear!
|
7
11
|
require File.join(root, "lib/hexx.rb")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hexx
|
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
|
- Andrew Kozin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -53,75 +53,75 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0.7'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: inch
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '0.5'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '0.5'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: metric_fu
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '4.11'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '4.11'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: rake
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '10.3'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '10.3'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
98
|
+
name: rspec
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0
|
103
|
+
version: '3.0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0
|
110
|
+
version: '3.0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: rubocop
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
117
|
+
version: '0.23'
|
118
118
|
type: :development
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
124
|
+
version: '0.23'
|
125
125
|
description: Defines domain service object and model attributes coercion.
|
126
126
|
email: andrew.kozin@gmail.com
|
127
127
|
executables: []
|
@@ -149,7 +149,6 @@ files:
|
|
149
149
|
- spec/hexx/service/invalid_spec.rb
|
150
150
|
- spec/hexx/service/message_spec.rb
|
151
151
|
- spec/hexx/service_spec.rb
|
152
|
-
- spec/initializers/coveralls.rb
|
153
152
|
- spec/initializers/focus.rb
|
154
153
|
- spec/initializers/garbage_collection.rb
|
155
154
|
- spec/initializers/i18n.rb
|
@@ -189,7 +188,6 @@ test_files:
|
|
189
188
|
- spec/initializers/garbage_collection.rb
|
190
189
|
- spec/initializers/i18n.rb
|
191
190
|
- spec/initializers/focus.rb
|
192
|
-
- spec/initializers/coveralls.rb
|
193
191
|
- spec/initializers/random_order.rb
|
194
192
|
- spec/initializers/rspec.rb
|
195
193
|
- Rakefile
|