responsive_service 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e260d3381714a7a7260e52ace95f3468db7670f3
4
+ data.tar.gz: 150db5b50d0a77943a02678e037b0d28df22b560
5
+ SHA512:
6
+ metadata.gz: 01a7ce6348cf94b5496142e5ba0ed1c7d817a565a4a85c5497ca98f505c9d5f560557dfff919d7791467b22b87585ff0fa331c0f5df441d6c7df86c92b17122b
7
+ data.tar.gz: 7f9f2b025e83cf696a5eda50360bb70faec7e83b8d05434e3123b57d0baaffb27bde5930921b9d06476fd1c2bf1cdd335c19181d4731046ce260ea9ddffd16cd
data/.gitignore ADDED
@@ -0,0 +1,20 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .ruby-version
7
+ .ruby-gemset
8
+ .rvmrc
9
+ Gemfile.lock
10
+ InstalledFiles
11
+ _yardoc
12
+ coverage
13
+ doc/
14
+ lib/bundler/man
15
+ pkg
16
+ rdoc
17
+ spec/reports
18
+ test/tmp
19
+ test/version_tmp
20
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in responsive_service.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 alexpeachey
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,62 @@
1
+ # ResponsiveService
2
+
3
+ The ResponsiveService gem is at this point little more than a light wrapper on a suggested pattern
4
+ for implementing service classes.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'responsive_service'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install responsive_service
19
+
20
+ ## Usage
21
+
22
+ Create a service class, either your own or feel free to subclass from `ResponsiveService::ResponsiveService`.
23
+
24
+ ```ruby
25
+ class MyService < ResponsiveService::ResponsiveService
26
+ def call(&block)
27
+ # do some work
28
+ yield ResponsiveService::Responder.new(:success)
29
+ end
30
+ end
31
+ ```
32
+
33
+ You must implement a `call` method if you subclass `ResponsiveService::ResponsiveService`.
34
+ Your call method should yield with a `ResponsiveService::Responder`.
35
+
36
+ A `ResponsiveService::Responder` can take up to 3 arguments but must at least have the first argument which is the type of the response. In addition it can take a message and a context. The message by convention should
37
+ be a string but there are no restrictions. The context can be any object.
38
+
39
+ ```ruby
40
+ responder = Responder.new(:success, 'You win!', {an_important_value: 'some value'})
41
+ responder.type # :success
42
+ responder.message # 'You win!'
43
+ responder.context # {an_important_value: 'some value'}
44
+ ```
45
+
46
+ Your service can now be used as such:
47
+
48
+ ```ruby
49
+ service = MyService.new
50
+ service.call do |response|
51
+ response.success { puts 'I was successful.' }
52
+ response.failure { puts 'I failed.' }
53
+ end
54
+ ```
55
+
56
+ ## Contributing
57
+
58
+ 1. Fork it
59
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
60
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
61
+ 4. Push to the branch (`git push origin my-new-feature`)
62
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,16 @@
1
+ module ResponsiveService
2
+ class Responder
3
+
4
+ attr_reader :type, :message, :context
5
+
6
+ def initialize(type, message=nil, context=nil)
7
+ @type = type
8
+ @context = context
9
+ @message = message
10
+ end
11
+
12
+ def method_missing(method, *args, &block)
13
+ yield if method == type
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ module ResponsiveService
2
+ class ResponsiveService
3
+ def call(&block)
4
+ yield Responder.new(:unimplemented, "A ResponsiveService should implement the call method.\nThe call method should perform the relevant work of the service and yield a ResponsiveService::Responder object.\n")
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module ResponsiveService
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,6 @@
1
+ require "responsive_service/version"
2
+ require "responsive_service/responsive_service"
3
+ require "responsive_service/responder"
4
+
5
+ module ResponsiveService
6
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'responsive_service/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'responsive_service'
8
+ spec.version = ResponsiveService::VERSION
9
+ spec.authors = ['alexpeachey']
10
+ spec.email = ['alex.peachey@gmail.com']
11
+ spec.description = 'Easy to use responsive service pattern'
12
+ spec.summary = 'Easy to use responsive service pattern'
13
+ spec.homepage = 'http://github.com/alexpeachey/responsive_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.3'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec'
24
+ spec.add_development_dependency 'simplecov'
25
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ module ResponsiveService
4
+ describe Responder do
5
+ subject(:responder) { Responder.new(type) }
6
+ let(:type) { :success }
7
+
8
+ it 'yields when sent :success with a type of :success' do
9
+ expect { |b| responder.success(&b) }.to yield_control
10
+ end
11
+
12
+ it 'does not yield when sent :failure with a type of :success' do
13
+ expect { |b| responder.failure(&b) }.to_not yield_control
14
+ end
15
+
16
+ context 'when initialized with a message' do
17
+ subject(:responder) { Responder.new(type, message) }
18
+ let(:message) { double(:message) }
19
+
20
+ specify { expect(responder.message).to eq message }
21
+
22
+ context 'when additionally initialized with a context' do
23
+ subject(:responder) { Responder.new(type, message, context) }
24
+ let(:context) { double(:context) }
25
+
26
+ specify { expect(responder.context).to eq context }
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,16 @@
1
+ require 'spec_helper'
2
+
3
+ module ResponsiveService
4
+ describe ResponsiveService do
5
+ subject(:service) { ResponsiveService.new }
6
+
7
+ describe '#call' do
8
+ it 'yields with a responder indicating instructions' do
9
+ service.call do |response|
10
+ expect(response.type).to eq :unimplemented
11
+ expect(response.message).to eq "A ResponsiveService should implement the call method.\nThe call method should perform the relevant work of the service and yield a ResponsiveService::Responder object.\n"
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,27 @@
1
+ require 'simplecov'
2
+
3
+ SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
4
+
5
+ SimpleCov.start do
6
+ command_name 'spec'
7
+ add_filter 'config/'
8
+ add_filter 'spec'
9
+ add_filter '.bundle'
10
+ minimum_coverage 100
11
+ end
12
+
13
+ require 'rspec'
14
+ require 'responsive_service'
15
+
16
+ RSpec.configure do |config|
17
+ config.mock_with :rspec
18
+ config.treat_symbols_as_metadata_keys_with_true_values = true
19
+ config.run_all_when_everything_filtered = true
20
+ config.filter_run :focus
21
+
22
+ # Run specs in random order to surface order dependencies. If you find an
23
+ # order dependency and want to debug it, you can fix the order by providing
24
+ # the seed, which is printed after each run.
25
+ # --seed 1234
26
+ config.order = 'random'
27
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: responsive_service
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - alexpeachey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-26 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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Easy to use responsive service pattern
70
+ email:
71
+ - alex.peachey@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - lib/responsive_service.rb
83
+ - lib/responsive_service/responder.rb
84
+ - lib/responsive_service/responsive_service.rb
85
+ - lib/responsive_service/version.rb
86
+ - responsive_service.gemspec
87
+ - spec/lib/responsive_service/responder_spec.rb
88
+ - spec/lib/responsive_service/responsive_service_spec.rb
89
+ - spec/spec_helper.rb
90
+ homepage: http://github.com/alexpeachey/responsive_service
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.0.14
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Easy to use responsive service pattern
114
+ test_files:
115
+ - spec/lib/responsive_service/responder_spec.rb
116
+ - spec/lib/responsive_service/responsive_service_spec.rb
117
+ - spec/spec_helper.rb