simple_operation 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 +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +53 -0
- data/Rakefile +2 -0
- data/lib/simple_operation/version.rb +3 -0
- data/lib/simple_operation.rb +23 -0
- data/simple_operation.gemspec +23 -0
- data/test/simple_operation_test.rb +55 -0
- metadata +84 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: dce82ef0ca5c1231813003eb71b5b7ab9ca1e27d
|
|
4
|
+
data.tar.gz: 6d3a6ad782941b7837e050b3122009e68f3fc11b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 92c4e5c8f19c64d70a40ccf2c064f5b05a656853cb2b5a709d36e17277b65fabad0570a2c2c270284fceb68df162204c12f7c2c64e70085e565c6f77181e1e0c
|
|
7
|
+
data.tar.gz: e58f24eac78712ae4d45f43b473d375fc623c25db76a54eba88a015266f24feccb870166a62f90a45a2327ae8a80770915263801d2546abe3e4d6eac31b39575
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2015 Grzegorz Witek
|
|
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,53 @@
|
|
|
1
|
+
# SimpleOperation
|
|
2
|
+
|
|
3
|
+
The idea behind SimpleOperation is to provide a very basic class creator that facilitates using service objects.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'simple_operation'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install simple_operation
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
Example usage for SimpleOperation is creating user:
|
|
24
|
+
|
|
25
|
+
```ruby
|
|
26
|
+
class CreateUser < SimpleOperation.new(:login, :password)
|
|
27
|
+
|
|
28
|
+
def call
|
|
29
|
+
user = User.new(login, password)
|
|
30
|
+
validate_user(user)
|
|
31
|
+
UserRepository.persist(user)
|
|
32
|
+
user
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
def validate_user(user)
|
|
37
|
+
!UserRepository.fetch_all_logins.include?(user.login)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
CreateUser.('Grzegorz', 'arnvald.to@gmail.com')
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## Contributing
|
|
48
|
+
|
|
49
|
+
1. Fork it ( https://github.com/[my-github-username]/simple_operation/fork )
|
|
50
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
51
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
52
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
53
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#require "simple_operation/version"
|
|
2
|
+
|
|
3
|
+
class SimpleOperation
|
|
4
|
+
|
|
5
|
+
def self.new(*args)
|
|
6
|
+
args_list_with_nils = args.join('=nil, ') + '=nil'
|
|
7
|
+
Class.new do
|
|
8
|
+
class_eval <<-code
|
|
9
|
+
def self.call #{args_list_with_nils}
|
|
10
|
+
new(#{args.join(',')}).call
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def initialize #{args_list_with_nils}
|
|
14
|
+
#{args.map { |arg| "@#{arg}= #{arg}" }.join(';') }
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
#{args.map { |arg| "attr_reader :#{arg}" }.join(';') }
|
|
19
|
+
code
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'simple_operation/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "simple_operation"
|
|
8
|
+
spec.version = SimpleOperation::VERSION
|
|
9
|
+
spec.authors = ["Grzegorz Witek"]
|
|
10
|
+
spec.email = ["arnvald.to@gmail.com"]
|
|
11
|
+
spec.summary = %q{Create simple service object}
|
|
12
|
+
spec.description = %q{SimpleOperation is a very simple library that facilitates creating service objects}
|
|
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
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
2
|
+
require 'simple_operation'
|
|
3
|
+
require 'minitest/autorun'
|
|
4
|
+
|
|
5
|
+
class SimpleOperationTest < Minitest::Test
|
|
6
|
+
|
|
7
|
+
def test_runs_correctly
|
|
8
|
+
assert SimpleOperation.new(:login)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def test_has_no_public_readers
|
|
12
|
+
assert_raises(NoMethodError) { object.login }
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def test_has_private_readers
|
|
16
|
+
assert object.send(:login)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def test_reader_is_assigned
|
|
20
|
+
assert_equal 'Arnvald', object.send(:login)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_reader_is_assigned_default_value
|
|
24
|
+
assert_equal klass.new.send(:login), nil
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def test_instance_has_call_method
|
|
28
|
+
assert object.respond_to?(:call)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def test_class_has_call_method
|
|
32
|
+
assert klass.respond_to?(:call)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def test_class_call_runs_instances_call
|
|
36
|
+
assert klass.('Arnvald')
|
|
37
|
+
refute klass.('Grzegorz')
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def object
|
|
42
|
+
klass.new('Arnvald')
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def klass
|
|
46
|
+
FindUser
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
class FindUser < SimpleOperation.new(:login)
|
|
50
|
+
def call
|
|
51
|
+
login == 'Arnvald'
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: simple_operation
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Grzegorz Witek
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2015-04-15 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
|
+
description: SimpleOperation is a very simple library that facilitates creating service
|
|
42
|
+
objects
|
|
43
|
+
email:
|
|
44
|
+
- arnvald.to@gmail.com
|
|
45
|
+
executables: []
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- ".gitignore"
|
|
50
|
+
- Gemfile
|
|
51
|
+
- LICENSE.txt
|
|
52
|
+
- README.md
|
|
53
|
+
- Rakefile
|
|
54
|
+
- lib/simple_operation.rb
|
|
55
|
+
- lib/simple_operation/version.rb
|
|
56
|
+
- simple_operation.gemspec
|
|
57
|
+
- test/simple_operation_test.rb
|
|
58
|
+
homepage: ''
|
|
59
|
+
licenses:
|
|
60
|
+
- MIT
|
|
61
|
+
metadata: {}
|
|
62
|
+
post_install_message:
|
|
63
|
+
rdoc_options: []
|
|
64
|
+
require_paths:
|
|
65
|
+
- lib
|
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
67
|
+
requirements:
|
|
68
|
+
- - ">="
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '0'
|
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
requirements: []
|
|
77
|
+
rubyforge_project:
|
|
78
|
+
rubygems_version: 2.2.2
|
|
79
|
+
signing_key:
|
|
80
|
+
specification_version: 4
|
|
81
|
+
summary: Create simple service object
|
|
82
|
+
test_files:
|
|
83
|
+
- test/simple_operation_test.rb
|
|
84
|
+
has_rdoc:
|