active-service 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 65ececfb51c36bf6866af414be83d9a0e10362fb
4
+ data.tar.gz: 2a6f9afccf04f5876757c99b37124b96bf81b52f
5
+ SHA512:
6
+ metadata.gz: b2869511e08b10e9af429fcac2979784ea75627d2b2ba63b417994647be6976be158664620d7d105868cc15113b5186107239ca033d61b016754eba6e56f4166
7
+ data.tar.gz: 19d6cd37cd5fa6e7812353f2c9a2a8a75142a2d1cbf71200702a0131c252800c4459c3a99366e5709bfa25a5234556c6ba5e92a9c3a661949b31ff121ab2dccb
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - 2.0
3
+ script: rspec spec
4
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_service.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Martin Fernandez
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # ActiveService
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'active_service'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install active_service
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/active_service/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_service/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active-service"
8
+ spec.version = ActiveService::VERSION
9
+ spec.authors = ["Martin Fernandez", "Andres Pache"]
10
+ spec.email = ["fmartin91@gmail.com", "apache90@gmail.com"]
11
+ spec.summary = %q{ Steroids for business modules. }
12
+ spec.description = %q{ Steroids for business modules. }
13
+ spec.homepage = "https://github.com/bilby91/active_service"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", "~> 3.2"
24
+ end
@@ -0,0 +1,14 @@
1
+ require_relative 'active_service/version'
2
+ require_relative 'active_service/runner'
3
+ require_relative 'active_service/hooks'
4
+
5
+ module ActiveService
6
+
7
+ def self.included(base)
8
+ base.class_eval do
9
+ include Runner
10
+ include Hooks
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,74 @@
1
+ module ActiveService
2
+
3
+ module Hooks
4
+
5
+ def self.included(base)
6
+ base.class_eval do
7
+ extend ClassMethods
8
+ end
9
+ end
10
+
11
+ module ClassMethods
12
+
13
+ %W(before after around).each do |type|
14
+ class_eval %{
15
+ def #{type}_hooks(action)
16
+ @#{type}_hooks ||= {}
17
+
18
+ @#{type}_hooks[action] ||= []
19
+ end
20
+ }
21
+ end
22
+
23
+ def add_hook(type, action, *args, &block)
24
+ options = extract_options! *args
25
+
26
+ if args.first.is_a? Symbol
27
+ block = lambda { |*ops|
28
+ send(args.first, *ops)
29
+ }
30
+ end
31
+
32
+ send("#{type}_hooks",action).push(block)
33
+ end
34
+
35
+ def before(action, *args, &block)
36
+ add_hook(:before, action, *args, &block)
37
+ end
38
+
39
+ def after(action, *args, &block)
40
+ add_hook(:after, action, *args, &block)
41
+ end
42
+
43
+ def around(action, *args, &block)
44
+ add_hook(:around, action, *args, &block)
45
+ end
46
+
47
+ def run_before_hooks(obj, action)
48
+ before_hooks(action).each { |h| run_hook(h, obj, action) }
49
+ end
50
+
51
+ def run_after_hooks(obj, action)
52
+ after_hooks(action).each { |h| run_hook(h, obj, action) }
53
+ end
54
+
55
+ def run_around_hooks(obj, action, &block)
56
+ around_hooks(action).inject(block) { |chain, hook|
57
+ proc { run_hook(hook, obj, chain) }
58
+ }.call
59
+ end
60
+
61
+ def run_hook(hook, obj, *args)
62
+ obj.instance_exec(*args, &hook)
63
+ end
64
+
65
+ def extract_options!(*args)
66
+ args.last.is_a?(::Hash) ? args.pop : {}
67
+ end
68
+
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
@@ -0,0 +1,41 @@
1
+ module ActiveService
2
+
3
+ module Runner
4
+
5
+ def self.included(base)
6
+ base.class_eval do
7
+ extend ClassMethods
8
+ include InstaceMethods
9
+ end
10
+ end
11
+
12
+ module ClassMethods
13
+
14
+ def method_missing(sym, *args, &block)
15
+ obj = self.new
16
+
17
+ super(sym, *args, &block) unless obj.respond_to?(sym)
18
+
19
+ obj.run_method(sym, *args, &block)
20
+ end
21
+
22
+ end
23
+
24
+ module InstaceMethods
25
+
26
+ def run_method(sym, *args, &block)
27
+ self.class.run_before_hooks(self, sym)
28
+
29
+ result = send(sym, *args, &block)
30
+
31
+ self.class.run_after_hooks(self, sym)
32
+
33
+ result
34
+ end
35
+
36
+ end
37
+
38
+ end
39
+
40
+
41
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveService
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,126 @@
1
+ require 'spec_helper'
2
+
3
+ module ActiveService
4
+
5
+ describe Hooks do
6
+
7
+ context 'when using around hook' do
8
+
9
+ context 'when using block api' do
10
+
11
+ let(:hooked) {
12
+ build_hooked do
13
+ around :process do |o|
14
+ steps << :pre
15
+ o.call
16
+ steps << :post
17
+ end
18
+ end
19
+ }
20
+
21
+ it 'calls the around block' do
22
+ expect(hooked.process).to eq([:pre, :process, :post])
23
+ end
24
+
25
+ end
26
+
27
+ context 'when using block api' do
28
+
29
+ let(:hooked) {
30
+ build_hooked do
31
+ around :process, :post
32
+
33
+ def post(operation)
34
+ steps << :pre
35
+ operation.call
36
+ steps << :post
37
+ end
38
+ end
39
+ }
40
+
41
+ it 'calls the around method' do
42
+ expect(hooked.process).to eq([:pre, :process, :post])
43
+ end
44
+
45
+ end
46
+
47
+ end
48
+ context 'when using before hook' do
49
+
50
+ context 'when using block api' do
51
+
52
+ let(:hooked) {
53
+ build_hooked do
54
+ before :process do
55
+ steps << :pre
56
+ end
57
+ end
58
+ }
59
+
60
+ it 'calls the before block' do
61
+ expect(hooked.process).to include(:pre)
62
+ end
63
+
64
+ end
65
+
66
+ context 'when using block api' do
67
+
68
+ let(:hooked) {
69
+ build_hooked do
70
+ before :process, :pre
71
+
72
+ def pre(operation)
73
+ steps << :pre
74
+ end
75
+ end
76
+ }
77
+
78
+ it 'calls the method' do
79
+ expect(hooked.process).to include(:pre)
80
+ end
81
+
82
+ end
83
+
84
+ end
85
+
86
+ end
87
+
88
+ context 'when using after hook' do
89
+
90
+ context 'when using block api' do
91
+
92
+ let(:hooked) {
93
+ build_hooked do
94
+ after :process do
95
+ steps << :post
96
+ end
97
+ end
98
+ }
99
+
100
+ it 'calls the after block' do
101
+ expect(hooked.process).to include(:post)
102
+ end
103
+
104
+ end
105
+
106
+ context 'when using block api' do
107
+
108
+ let(:hooked) {
109
+ build_hooked do
110
+ after :process, :post
111
+
112
+ def post(operation)
113
+ steps << :post
114
+ end
115
+ end
116
+ }
117
+
118
+ it 'calls the method' do
119
+ expect(hooked.process).to include(:post)
120
+ end
121
+
122
+ end
123
+
124
+ end
125
+
126
+ end
@@ -0,0 +1,77 @@
1
+ require_relative '../lib/active_service'
2
+
3
+ Dir[File.expand_path("../support/*.rb", __FILE__)].each { |f| require f }
4
+
5
+ RSpec.configure do |config|
6
+
7
+ config.include HookBuilder
8
+
9
+ config.expect_with :rspec do |expectations|
10
+ # This option will default to `true` in RSpec 4. It makes the `description`
11
+ # and `failure_message` of custom matchers include text for helper methods
12
+ # defined using `chain`, e.g.:
13
+ # be_bigger_than(2).and_smaller_than(4).description
14
+ # # => "be bigger than 2 and smaller than 4"
15
+ # ...rather than:
16
+ # # => "be bigger than 2"
17
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
18
+ end
19
+
20
+ # rspec-mocks config goes here. You can use an alternate test double
21
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
22
+ config.mock_with :rspec do |mocks|
23
+ # Prevents you from mocking or stubbing a method that does not exist on
24
+ # a real object. This is generally recommended, and will default to
25
+ # `true` in RSpec 4.
26
+ mocks.verify_partial_doubles = true
27
+ end
28
+
29
+ # The settings below are suggested to provide a good initial experience
30
+ # with RSpec, but feel free to customize to your heart's content.
31
+ =begin
32
+ # These two settings work together to allow you to limit a spec run
33
+ # to individual examples or groups you care about by tagging them with
34
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
35
+ # get run.
36
+ config.filter_run :focus
37
+ config.run_all_when_everything_filtered = true
38
+
39
+ # Limits the available syntax to the non-monkey patched syntax that is
40
+ # recommended. For more details, see:
41
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
42
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
43
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
44
+ config.disable_monkey_patching!
45
+
46
+ # This setting enables warnings. It's recommended, but in some cases may
47
+ # be too noisy due to issues in dependencies.
48
+ config.warnings = true
49
+
50
+ # Many RSpec users commonly either run the entire suite or an individual
51
+ # file, and it's useful to allow more verbose output when running an
52
+ # individual spec file.
53
+ if config.files_to_run.one?
54
+ # Use the documentation formatter for detailed output,
55
+ # unless a formatter has already been configured
56
+ # (e.g. via a command-line flag).
57
+ config.default_formatter = 'doc'
58
+ end
59
+
60
+ # Print the 10 slowest examples and example groups at the
61
+ # end of the spec run, to help surface which specs are running
62
+ # particularly slow.
63
+ config.profile_examples = 10
64
+
65
+ # Run specs in random order to surface order dependencies. If you find an
66
+ # order dependency and want to debug it, you can fix the order by providing
67
+ # the seed, which is printed after each run.
68
+ # --seed 1234
69
+ config.order = :random
70
+
71
+ # Seed global randomization in this process using the `--seed` CLI option.
72
+ # Setting this allows you to use `--seed` to deterministically reproduce
73
+ # test failures related to randomization by passing the same `--seed` value
74
+ # as the one that triggered the failure.
75
+ Kernel.srand config.seed
76
+ =end
77
+ end
@@ -0,0 +1,35 @@
1
+ module HookBuilder
2
+
3
+ def build_hooked(&block)
4
+ hooked = Class.new
5
+
6
+ hooked.class_eval do
7
+ include ActiveService::Hooks
8
+
9
+ attr_reader :steps
10
+
11
+ def initialize
12
+ @steps = []
13
+ end
14
+
15
+ def self.process
16
+ instance = new
17
+
18
+ run_before_hooks(instance, :process)
19
+ run_around_hooks(instance, :process) { instance.process }
20
+ run_after_hooks(instance, :process)
21
+
22
+ instance.steps
23
+ end
24
+
25
+ def process
26
+ steps << :process
27
+ end
28
+
29
+ end
30
+
31
+ hooked.class_eval(&block) if block
32
+ hooked
33
+ end
34
+
35
+ end
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active-service
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Martin Fernandez
8
+ - Andres Pache
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2015-05-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: '1.7'
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ~>
26
+ - !ruby/object:Gem::Version
27
+ version: '1.7'
28
+ - !ruby/object:Gem::Dependency
29
+ name: rake
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ~>
33
+ - !ruby/object:Gem::Version
34
+ version: '10.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ~>
40
+ - !ruby/object:Gem::Version
41
+ version: '10.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: rspec
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '3.2'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ~>
54
+ - !ruby/object:Gem::Version
55
+ version: '3.2'
56
+ description: ' Steroids for business modules. '
57
+ email:
58
+ - fmartin91@gmail.com
59
+ - apache90@gmail.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - .gitignore
65
+ - .rspec
66
+ - .travis.yml
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - active_service.gemspec
72
+ - lib/active_service.rb
73
+ - lib/active_service/hooks.rb
74
+ - lib/active_service/runner.rb
75
+ - lib/active_service/version.rb
76
+ - spec/hooks_spec.rb
77
+ - spec/spec_helper.rb
78
+ - spec/support/hook_builder.rb
79
+ homepage: https://github.com/bilby91/active_service
80
+ licenses:
81
+ - MIT
82
+ metadata: {}
83
+ post_install_message:
84
+ rdoc_options: []
85
+ require_paths:
86
+ - lib
87
+ required_ruby_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ requirements: []
98
+ rubyforge_project:
99
+ rubygems_version: 2.4.5
100
+ signing_key:
101
+ specification_version: 4
102
+ summary: Steroids for business modules.
103
+ test_files:
104
+ - spec/hooks_spec.rb
105
+ - spec/spec_helper.rb
106
+ - spec/support/hook_builder.rb
107
+ has_rdoc: