bizness 0.9.0 → 0.9.1

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: 5763645a9f422b6ffffcd1c7d2479e5e90d954ee
4
- data.tar.gz: 544d347d96ca56f02295460f2a81b66450b03bfa
3
+ metadata.gz: b714a39badf727a99d3bdc0c66d973cefba362b6
4
+ data.tar.gz: 44a55bee700c1836c0ede38fa362e5a83f51d5e2
5
5
  SHA512:
6
- metadata.gz: 47de010ec86cd7ab359631bff52169b20de0a43418f066947b555b0bc1e726b3913f42390a486d54d9358fc200241e2c643b8d8311ecf80843b99c28dfa96590
7
- data.tar.gz: 385b68bd06eeaacba49548a8d51caad440b23eda8892f6d7b7aff251d95e58389c72804f3d339dfd326fa089605dd97135be2bf4c3a6ff801be16e6f89b963a8
6
+ metadata.gz: 142c588c8ce88f7116812c104b5259d3d3eb3916d3bfcd2edba351a0a7669650576a5ff1284c6a85d0cc0f3c09f999ffc8651493aacc8bf816d8459f97c0ec4c
7
+ data.tar.gz: 7cb79a4e410349489b9fbeb906536d13bee55b3825142271fa914eabc9d65d421d8d4d13c8367f11927580a14ebd2c378e25f3a3fe7c6a526c0642dd75eda1b6
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Bizness
2
2
 
3
- Get your bizness right and organize your business logic into operations.
3
+ Get your bizness right and organize your business logic into operations and policies.
4
4
 
5
5
  ## Installation
6
6
 
@@ -29,8 +29,8 @@ ShippingEasy adopted this strategy, but we opted to use the term Operation rathe
29
29
 
30
30
  As we wrote more and more operations, some insights emerged:
31
31
 
32
- 1. We always ran an operation in a transaction
33
- 2. An operation nearly always corresponded to an important system event ("Complete Registration")
32
+ 1. We almost always ran an operation in a transaction
33
+ 2. An operation often corresponded to an important system event ("Complete Registration")
34
34
  3. Logging these events into a dashboard like Kibana could provide us with valuable metrics and insight into how our system was performing at a business logic level
35
35
 
36
36
  Bizness, therefore, allows you to create PORO operation objects and easily augment their business logic execution via a series of filters. Out of the box there are filters to wrap every operation in a transaction as well as automatically broadcasting every operation as a series of events.
@@ -88,21 +88,23 @@ op.to_h
88
88
 
89
89
  Operations are expected to run to completion, otherwise a runtime error should be raised. Before executing an operation, you should generally ensure that the object or objects being operated against pass a certain set of criteria.
90
90
 
91
- We typically wrap this set of criteria in a Policy object, and if the object passes the policy we kick off the operation. You can call this policy during input validation and return the violations to the end user. However, we also like to use the policy object inside the operation as a final guard before running the operation. If the policy fails, we raise a runtime exception containing the list of violations.
91
+ We typically wrap this set of criteria in a Policy object, and if the object passes the policy we kick off the operation. You can also call this policy during input validation (for example, in a Form object) and return the violations to the end user. However, we also like to use the policy object inside the operation as a final guard before running the operation. If the policy fails, we raise a runtime exception containing the list of violations.
92
92
 
93
93
  Since this is such a common pattern, we created the `Bizness::Policy` module. Here's an example:
94
94
 
95
95
  ```ruby
96
96
  class Policies::StringFormatPolicy
97
97
  include Bizness::Policy
98
-
99
- attr_reader :string
98
+
99
+ policy_enforces :alphanumeric?, :all_caps?
100
100
 
101
101
  def initialize(string:)
102
102
  @string = string
103
103
  end
104
104
 
105
105
  private
106
+
107
+ attr_reader :string
106
108
 
107
109
  def alphanumeric?
108
110
  string.match(/^[[:alpha:]]+$/)
@@ -126,7 +128,7 @@ policy.violations
126
128
 
127
129
  By including the module, the object gets the `violated?` (and `obeyed?`) method which does the following when called:
128
130
 
129
- 1. Introspects all private predicate methods (methods that end with a question mark) and executes them
131
+ 1. Executes the methods listed via the `policy_enforces` macro
130
132
  2. If the method returns false, it looks for a translation in an I18n YAML file
131
133
  3. It composes an I18n key using the policy's class and method name (without the question mark). For example: `policies.mock_policy.violations.all_caps`
132
134
  4. It adds the result of the translation to the list of `violations`
@@ -10,7 +10,9 @@ module Bizness::Filters
10
10
 
11
11
  def evented_call
12
12
  result = filtered_operation.call
13
- Hey.publish!("#{event_name}#{delimiter}#{successful? ? "succeeded" : "failed"}", payload(result))
13
+ event_status = (respond_to?(:successful?) && !successful?) ? "failed" : "succeeded"
14
+ Hey.publish!("#{event_name}#{delimiter}#{event_status}", payload(result))
15
+ result
14
16
  rescue Exception => e
15
17
  Hey.publish!("#{event_name}#{delimiter}aborted", payload.merge(error: e.message, stacktrace: e.backtrace, exception: e.class.name))
16
18
  raise e
@@ -1,3 +1,3 @@
1
1
  module Bizness
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bizness
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ShippingEasy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-14 00:00:00.000000000 Z
11
+ date: 2016-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  version: '0'
155
155
  requirements: []
156
156
  rubyforge_project:
157
- rubygems_version: 2.4.6
157
+ rubygems_version: 2.4.8
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: Get your bizness right and organize your business logic into operations.