call 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4de687ca6fd57163c91e38697986639f2e8976b4
4
+ data.tar.gz: 35b6f1dbb6236fd91853e70412ec3fa6147aa47a
5
+ SHA512:
6
+ metadata.gz: 83e2f170d01e5b250d0a1e1fcb7938b2d7eda2421216d9867fc686bf17eb6e069a87ad24ff1dd5763cdd362a2918aa76768c9a2872a47edd073e0d7124961aad
7
+ data.tar.gz: 2acda1c8db91cc6c17dd0b7291e29f9818b112be1daccb6c0abeeed5d75b4bcf35a4beb81341606c32503b55135cfb6d29dfa2b0034ca6e8b0099c2f4623a661
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in call.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TODO: Write your name
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Call
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'call'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install call
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rake/testtask'
4
+
5
+ Rake::TestTask.new(:spec) do |t|
6
+ t.libs << "spec"
7
+ t.test_files = FileList['spec/**/*_spec.rb']
8
+ t.verbose = true
9
+ end
10
+
11
+ task :default => :spec
data/call.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'call/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "call"
8
+ spec.version = Call::VERSION
9
+ spec.authors = ["Jakob Holderbaum"]
10
+ spec.email = ["jh@neopoly.de"]
11
+ spec.summary = %q{Callback-Trigger-Pingpong for clean DCI implementation.}
12
+ spec.homepage = "https://github.com/neopoly/call"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.3"
21
+ spec.add_development_dependency "rake"
22
+ end
data/examples/dci.rb ADDED
@@ -0,0 +1,45 @@
1
+ require 'call'
2
+
3
+ User = Struct.new(:name)
4
+
5
+ class CreatingUser
6
+ Trigger = Call.new(:success, :failure)
7
+ Response = Struct.new(:name)
8
+
9
+ def initialize(username)
10
+ @username = username
11
+ end
12
+
13
+ def call(&block)
14
+ trigger = Trigger.new(&block)
15
+
16
+ raise "invalid username" if @username.start_with?'A'
17
+ user = User.new(@username)
18
+
19
+ trigger.success Response.new(user.name)
20
+
21
+ rescue RuntimeError => e
22
+ trigger.failure e.message
23
+ end
24
+ end
25
+
26
+
27
+ CreatingUser.new('My Account').call do |on|
28
+ on.success do |user|
29
+ p :user_account => user
30
+ end
31
+
32
+ on.failure do |error|
33
+ p :error => error
34
+ end
35
+ end
36
+
37
+ CreatingUser.new('An Account').call do |on|
38
+ on.success do |user|
39
+ p :user_account => user
40
+ end
41
+
42
+ on.failure do |error|
43
+ p :error => error
44
+ end
45
+ end
@@ -0,0 +1,15 @@
1
+ module Call
2
+ class Response
3
+ def initialize(type, *args)
4
+ @type = type
5
+ @args = args
6
+ end
7
+
8
+ private
9
+ def trigger_responded(type, &block)
10
+ if type == @type
11
+ block.call(*@args)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ module Call
2
+ class Trigger
3
+ class << self
4
+ attr_accessor :response_class
5
+ end
6
+
7
+ def initialize(&block)
8
+ raise ArgumentError, 'Block required' if block.nil?
9
+ @callback = block
10
+ end
11
+
12
+ private
13
+
14
+ def call(response_type, *args)
15
+ response = self.class.response_class.new(response_type, *args)
16
+ @callback.call response
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module Call
2
+ VERSION = "0.0.1"
3
+ end
data/lib/call.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'call/version'
2
+ require 'call/trigger'
3
+ require 'call/response'
4
+
5
+ module Call
6
+ def self.new(*responses)
7
+ Class.new(Trigger) do
8
+ responses.each do |response|
9
+ define_method response do |*args|
10
+ call response, *args
11
+ end
12
+ end
13
+
14
+ self.response_class = Class.new(Response) do
15
+ responses.each do |response|
16
+ define_method response do |&block|
17
+ trigger_responded(response, &block)
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ end
24
+ end
data/spec/call_spec.rb ADDED
@@ -0,0 +1,50 @@
1
+ require 'helper'
2
+
3
+ require 'ostruct'
4
+
5
+ describe Call do
6
+ it 'creates a Trigger-Class' do
7
+ trigger_class = Call.new(:success, :failure)
8
+
9
+ assert_equal Call::Trigger, trigger_class.superclass
10
+ end
11
+
12
+ it 'builds response methods' do
13
+ trigger_class = Call.new(:success, :failure)
14
+
15
+ trigger = trigger_class.new do
16
+ end
17
+
18
+ assert trigger.respond_to? :success
19
+ assert trigger.respond_to? :failure
20
+ end
21
+
22
+ it 'is needs a block' do
23
+ trigger_class = Call.new(:success, :failure)
24
+
25
+ assert_raises ArgumentError do
26
+ trigger_class.new
27
+ end
28
+ end
29
+
30
+ it 'calls the block with a response object' do
31
+ @calls = []
32
+
33
+ trigger_class = Call.new(:success, :failure)
34
+
35
+ trigger = trigger_class.new do |on|
36
+ on.success do |*args|
37
+ @calls << OpenStruct.new(:type => :success, :args => args)
38
+ end
39
+
40
+ on.failure do |*args|
41
+ @calls << OpenStruct.new(:type => :success, :args => args)
42
+ end
43
+ end
44
+
45
+ trigger.success '12', :b
46
+ trigger.failure 22
47
+
48
+ assert_equal 2, @calls.size
49
+ end
50
+ end
data/spec/helper.rb ADDED
@@ -0,0 +1,4 @@
1
+ require 'minitest/autorun'
2
+ require 'minitest/spec'
3
+
4
+ require 'call'
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: call
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jakob Holderbaum
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description:
42
+ email:
43
+ - jh@neopoly.de
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - call.gemspec
54
+ - examples/dci.rb
55
+ - lib/call.rb
56
+ - lib/call/response.rb
57
+ - lib/call/trigger.rb
58
+ - lib/call/version.rb
59
+ - spec/call_spec.rb
60
+ - spec/helper.rb
61
+ homepage: https://github.com/neopoly/call
62
+ licenses:
63
+ - MIT
64
+ metadata: {}
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 2.0.0
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Callback-Trigger-Pingpong for clean DCI implementation.
85
+ test_files:
86
+ - spec/call_spec.rb
87
+ - spec/helper.rb