bizness 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 46ccf06a38a9105276d39ba1cda08326a8297313
4
+ data.tar.gz: 1b04f4e1195cf2cd40acc7521deef036c06ddd67
5
+ SHA512:
6
+ metadata.gz: cd74a12a843d17aeca92f51f82928ffcbad4b143af83df5720801f7fa7a925a58f3ca049673758d05ecd49c34103fa301ef5d4c1c99256de27d021e2e30caca0
7
+ data.tar.gz: 6045251f26b029b4b1b19e311d4543b1a34c9bc9ad0d314181c2e5cc800b504052ae104da585a717806caf36769034a1b5d14c3195ac7046b3535785cc8da396
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .idea
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.2
4
+ before_install: gem install bundler -v 1.10.5
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "hey-pubsub", require: "hey"
4
+
5
+ # Specify your gem's dependencies in bizness.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Theo Mills
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Bizness
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/bizness`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'bizness'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install bizness
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/bizness.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bizness"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/bizness.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bizness/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bizness"
8
+ spec.version = Bizness::VERSION
9
+ spec.authors = ["ShippingEasy"]
10
+ spec.email = ["dev@shippingeasy.com"]
11
+
12
+ spec.summary = "Get your bizness right and organize your business logic into operations."
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "activerecord"
22
+ spec.add_dependency "hey-pubsub"
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec"
26
+ spec.add_development_dependency "sqlite3"
27
+ end
@@ -0,0 +1,11 @@
1
+ class Bizness::Configuration
2
+ attr_writer :filters
3
+
4
+ def initialize
5
+ @filters = []
6
+ end
7
+
8
+ def filters
9
+ Array(@filters).flatten.compact
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ require "ostruct"
2
+
3
+ class Bizness::Context < OpenStruct
4
+ attr_accessor :error
5
+
6
+ def successful?
7
+ error.nil?
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ class Bizness::Failure < StandardError
2
+ def initialize(context = nil)
3
+ @context = context
4
+ super
5
+ end
6
+ end
@@ -0,0 +1,10 @@
1
+ module Bizness::Filters
2
+ class ActiveRecordTransactionFilter < Bizness::Filters::BaseFilter
3
+ def call
4
+ ActiveRecord::Base.transaction(requires_new: true) do
5
+ filtered_operation.call
6
+ raise ActiveRecord::Rollback unless successful?
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ module Bizness::Filters
2
+ class BaseFilter < SimpleDelegator
3
+ def initialize(operation)
4
+ @__original_operation__ = operation if __original_operation__.nil?
5
+ super(operation)
6
+ end
7
+
8
+ def self.wrap(collection)
9
+ collection.map { |object| new(object) }
10
+ end
11
+
12
+ private
13
+
14
+ attr_reader :__original_operation__
15
+
16
+ def filtered_operation
17
+ __getobj__
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,24 @@
1
+ module Bizness::Filters
2
+ class EventFilter < Bizness::Filters::BaseFilter
3
+ def call
4
+ Hey.publish!("#{event_name}:executed", context.to_h) do
5
+ evented_call
6
+ end
7
+ end
8
+
9
+ private
10
+
11
+ def evented_call
12
+ filtered_operation.call
13
+ Hey.publish!("#{event_name}:#{successful? ? "succeeded" : "failed"}", context.to_h)
14
+ rescue => e
15
+ context.error = e.message
16
+ Hey.publish!("#{event_name}:failed", context.to_h)
17
+ raise e
18
+ end
19
+
20
+ def event_name
21
+ __original_operation__.class.name.underscore.gsub("/", ":")
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,46 @@
1
+ class Bizness::Operation
2
+ extend Forwardable
3
+
4
+ def_delegators :context, :error, :successful?
5
+
6
+ attr_reader :context
7
+
8
+ def initialize(context = {})
9
+ @context = context.is_a?(Bizness::Context) ? context : Bizness::Context.new(context)
10
+ end
11
+
12
+ def self.filters
13
+ Bizness.filters
14
+ end
15
+
16
+ def self.call!(context = {})
17
+ new(context).call!
18
+ end
19
+
20
+ def call!
21
+ execute_filtered_operation!
22
+ context
23
+ end
24
+
25
+ def call
26
+ raise NotImplementedError
27
+ end
28
+
29
+ def fail!(error:)
30
+ context.error = error
31
+ end
32
+
33
+ private
34
+
35
+ def execute_filtered_operation!
36
+ filtered_operation.call
37
+ raise Bizness::Failure, context.error unless successful?
38
+ rescue => e
39
+ context.error = e.message
40
+ end
41
+
42
+ def filtered_operation
43
+ return self if self.class.filters.empty?
44
+ self.class.filters.reduce(self) { |filtered_op, filter| filter.new(filtered_op) }
45
+ end
46
+ end
@@ -0,0 +1,9 @@
1
+ module Bizness::Subscriber
2
+ def subscribe(*event_names)
3
+ event_names.each do |event_name|
4
+ Hey.subscribe!(event_name) do |event|
5
+ call!(event[:metadata])
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Bizness
2
+ VERSION = "0.1.0"
3
+ end
data/lib/bizness.rb ADDED
@@ -0,0 +1,28 @@
1
+ require "bizness/version"
2
+ require "active_record"
3
+ require "forwardable"
4
+ require "hey"
5
+
6
+ module Bizness
7
+ def self.configure
8
+ Hey.configuration.namespace = "operations"
9
+ yield(configuration)
10
+ end
11
+
12
+ def self.configuration
13
+ @configuration ||= Bizness::Configuration.new
14
+ end
15
+
16
+ def self.filters
17
+ configuration.filters
18
+ end
19
+ end
20
+
21
+ require "bizness/configuration"
22
+ require "bizness/context"
23
+ require "bizness/operation"
24
+ require "bizness/failure"
25
+ require "bizness/subscriber"
26
+ require "bizness/filters/base_filter"
27
+ require "bizness/filters/active_record_transaction_filter"
28
+ require "bizness/filters/event_filter"
metadata ADDED
@@ -0,0 +1,148 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bizness
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ShippingEasy
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-08-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hey-pubsub
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - dev@shippingeasy.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".rspec"
106
+ - ".travis.yml"
107
+ - Gemfile
108
+ - LICENSE.txt
109
+ - README.md
110
+ - Rakefile
111
+ - bin/console
112
+ - bin/setup
113
+ - bizness.gemspec
114
+ - lib/bizness.rb
115
+ - lib/bizness/configuration.rb
116
+ - lib/bizness/context.rb
117
+ - lib/bizness/failure.rb
118
+ - lib/bizness/filters/active_record_transaction_filter.rb
119
+ - lib/bizness/filters/base_filter.rb
120
+ - lib/bizness/filters/event_filter.rb
121
+ - lib/bizness/operation.rb
122
+ - lib/bizness/subscriber.rb
123
+ - lib/bizness/version.rb
124
+ homepage: ''
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubyforge_project:
144
+ rubygems_version: 2.2.2
145
+ signing_key:
146
+ specification_version: 4
147
+ summary: Get your bizness right and organize your business logic into operations.
148
+ test_files: []