resultable 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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +2 -0
- data/lib/resultable/result.rb +33 -0
- data/lib/resultable/version.rb +3 -0
- data/lib/resultable.rb +10 -0
- data/resultable.gemspec +24 -0
- data/spec/resultable/result_spec.rb +64 -0
- data/spec/resultable_spec.rb +17 -0
- data/spec/spec_helper.rb +1 -0
- data/tasks/rspec.rake +3 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 11270d59cfd27594b90ac4ab578801eb507cc274
|
4
|
+
data.tar.gz: e8f4d86b2d1cb7de01f474ecb27d055a081fd260
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 85cc5e18cffd51c31cf68e395c4774370465bfb66999b5860be252dfd7c02af66cce6be4ee6bb2339a12e94b267d274619e47e236de1780c93e5fa6b1ff19300
|
7
|
+
data.tar.gz: 8df54a0fef6644de9b583a5c144c548d90712a68bfc747c61649eef7ce036a8f4e7512cf419de88a8824693d43f53ef19af3030957734fc9dcf1b7e168100309
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Ruslan Milevskiy
|
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,52 @@
|
|
1
|
+
# Resultable
|
2
|
+
|
3
|
+
Simple ruby gem that provides reusable result object
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'resultable'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install resultable
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Include Resultable in any class that you want
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
class Service
|
27
|
+
include Resultable
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
Use result object
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
service = Service.new
|
35
|
+
puts service.result.successful?
|
36
|
+
=> false
|
37
|
+
puts service.result.error?
|
38
|
+
=> true
|
39
|
+
service.result.successful!
|
40
|
+
puts service.result.successful?
|
41
|
+
=> true
|
42
|
+
puts service.result.error?
|
43
|
+
=> false
|
44
|
+
```
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
1. Fork it ( https://github.com/[my-github-username]/resultable/fork )
|
49
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
50
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
51
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
52
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
module Resultable
|
2
|
+
class Result
|
3
|
+
|
4
|
+
module Status
|
5
|
+
SUCCESSFUL = 'successful'
|
6
|
+
ERROR = 'error'
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_accessor :status, :response
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
self.error!
|
13
|
+
end
|
14
|
+
|
15
|
+
def successful!
|
16
|
+
self.status = Status::SUCCESSFUL
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def successful?
|
21
|
+
self.status == Status::SUCCESSFUL
|
22
|
+
end
|
23
|
+
|
24
|
+
def error!
|
25
|
+
self.status = Status::ERROR
|
26
|
+
self
|
27
|
+
end
|
28
|
+
|
29
|
+
def error?
|
30
|
+
self.status == Status::ERROR
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/resultable.rb
ADDED
data/resultable.gemspec
ADDED
@@ -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 'resultable/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "resultable"
|
8
|
+
spec.version = Resultable::VERSION
|
9
|
+
spec.authors = ["Ruslan Milevskiy"]
|
10
|
+
spec.email = ["rpmilevskiy@gmail.com"]
|
11
|
+
spec.summary = %q{Simple ruby gem that provides reusable result object.}
|
12
|
+
spec.description = ""
|
13
|
+
spec.homepage = ""
|
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"
|
24
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Resultable::Result do
|
4
|
+
subject { Resultable::Result.new }
|
5
|
+
|
6
|
+
it 'sets default error status' do
|
7
|
+
expect(subject.status).to eq(Resultable::Result::Status::ERROR)
|
8
|
+
end
|
9
|
+
|
10
|
+
describe '#successful!' do
|
11
|
+
before { subject.successful! }
|
12
|
+
|
13
|
+
it 'sets successful status' do
|
14
|
+
expect(subject.status).to eq(Resultable::Result::Status::SUCCESSFUL)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#successful?' do
|
19
|
+
context 'if status is successful' do
|
20
|
+
it 'returns true' do
|
21
|
+
subject.status = Resultable::Result::Status::SUCCESSFUL
|
22
|
+
expect(subject.successful?).to eq(true)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context 'if status is error' do
|
27
|
+
it 'returns false' do
|
28
|
+
subject.status = Resultable::Result::Status::ERROR
|
29
|
+
expect(subject.successful?).to eq(false)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#error!' do
|
35
|
+
before { subject.error! }
|
36
|
+
|
37
|
+
it 'sets error status' do
|
38
|
+
expect(subject.status).to eq(Resultable::Result::Status::ERROR)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#error?' do
|
43
|
+
context 'if status is error' do
|
44
|
+
it 'returns true' do
|
45
|
+
subject.status = Resultable::Result::Status::ERROR
|
46
|
+
expect(subject.error?).to eq(true)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'if status is successful' do
|
51
|
+
it 'returns false' do
|
52
|
+
subject.status = Resultable::Result::Status::SUCCESSFUL
|
53
|
+
expect(subject.error?).to eq(false)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#response' do
|
59
|
+
it 'allows to set response attribute' do
|
60
|
+
subject.response = 'success'
|
61
|
+
expect(subject.response).to eq('success')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Resultable do
|
4
|
+
class Service
|
5
|
+
include Resultable
|
6
|
+
end
|
7
|
+
|
8
|
+
subject { Service.new }
|
9
|
+
|
10
|
+
it 'adds result attribute' do
|
11
|
+
expect(subject.result).to_not be_nil
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'initializes result attribute' do
|
15
|
+
expect(subject.result.class).to eq(Resultable::Result)
|
16
|
+
end
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'resultable'
|
data/tasks/rspec.rake
ADDED
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: resultable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ruslan Milevskiy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-03-11 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.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.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
|
+
description: ''
|
56
|
+
email:
|
57
|
+
- rpmilevskiy@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/resultable.rb
|
68
|
+
- lib/resultable/result.rb
|
69
|
+
- lib/resultable/version.rb
|
70
|
+
- resultable.gemspec
|
71
|
+
- spec/resultable/result_spec.rb
|
72
|
+
- spec/resultable_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
- tasks/rspec.rake
|
75
|
+
homepage: ''
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.4.5
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Simple ruby gem that provides reusable result object.
|
99
|
+
test_files:
|
100
|
+
- spec/resultable/result_spec.rb
|
101
|
+
- spec/resultable_spec.rb
|
102
|
+
- spec/spec_helper.rb
|