performify 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 +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +41 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/rake +17 -0
- data/bin/rspec +17 -0
- data/bin/setup +8 -0
- data/lib/performify/base.rb +67 -0
- data/lib/performify/callbacks.rb +37 -0
- data/lib/performify/version.rb +3 -0
- data/lib/performify.rb +5 -0
- data/performify.gemspec +37 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e5d73a6fd3521ef86fbaeae9cb733e410e6101a5
|
4
|
+
data.tar.gz: fd8f33d33a3d9ac5309b53c097c1417db447c5cb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: da1783feeb0b3a51ed5314cb045e00912d67622f4d29231b532b4a49f0bfc25b8f4c7fdfcbc588bb85c0bcd484dd093746feb96943ce534c52ec791661245a6b
|
7
|
+
data.tar.gz: 7e2ac421eff8be0222d97263266e784ad281e02e780c5c54aaf66151e0252b7c66274794ff121b0e8f82130c2e4169aeb3e8c0e43006ebb69997e754dfd15fe5
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Sergey Tsvetkov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Performify
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/performify`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'performify'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install performify
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/performify.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "performify"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/rake
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'rake' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("rake", "rake")
|
data/bin/rspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
#
|
4
|
+
# This file was generated by Bundler.
|
5
|
+
#
|
6
|
+
# The application 'rspec' is installed as part of a gem, and
|
7
|
+
# this file is here to facilitate running it.
|
8
|
+
#
|
9
|
+
|
10
|
+
require "pathname"
|
11
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
12
|
+
Pathname.new(__FILE__).realpath)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("rspec-core", "rspec")
|
data/bin/setup
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'performify/callbacks'
|
2
|
+
|
3
|
+
module Performify
|
4
|
+
class Base
|
5
|
+
extend Performify::Callbacks
|
6
|
+
|
7
|
+
attr_reader :current_user
|
8
|
+
|
9
|
+
def initialize(current_user = nil, **args)
|
10
|
+
@current_user = current_user
|
11
|
+
|
12
|
+
args.each do |arg_name, arg_value|
|
13
|
+
define_singleton_method(arg_name) { arg_value }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute!
|
18
|
+
block_result = nil
|
19
|
+
|
20
|
+
ActiveRecord::Base.transaction do
|
21
|
+
begin
|
22
|
+
block_result = yield
|
23
|
+
if block_result
|
24
|
+
success!(with_callbacks: false)
|
25
|
+
else
|
26
|
+
fail!(with_callbacks: false)
|
27
|
+
end
|
28
|
+
rescue RuntimeError, ActiveRecord::RecordInvalid
|
29
|
+
fail!
|
30
|
+
end
|
31
|
+
|
32
|
+
raise ActiveRecord::Rollback if fail?
|
33
|
+
end
|
34
|
+
|
35
|
+
execute_callbacks
|
36
|
+
block_result
|
37
|
+
end
|
38
|
+
|
39
|
+
def execute_callbacks
|
40
|
+
if success?
|
41
|
+
self.class.execute_callbacks(:success, self)
|
42
|
+
elsif fail?
|
43
|
+
self.class.execute_callbacks(:fail, self)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def success!(with_callbacks: true)
|
48
|
+
@result = true
|
49
|
+
execute_callbacks if with_callbacks
|
50
|
+
@result
|
51
|
+
end
|
52
|
+
|
53
|
+
def fail!(with_callbacks: true)
|
54
|
+
@result = false
|
55
|
+
execute_callbacks if with_callbacks
|
56
|
+
@result
|
57
|
+
end
|
58
|
+
|
59
|
+
def success?
|
60
|
+
@result.present?
|
61
|
+
end
|
62
|
+
|
63
|
+
def fail?
|
64
|
+
@result.blank?
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Performify
|
2
|
+
module Callbacks
|
3
|
+
class UnknownTypeOfCallbackError < StandardError; end
|
4
|
+
|
5
|
+
TYPES_OF_CALLBACK = [ :success, :fail ].freeze
|
6
|
+
|
7
|
+
def clean_callbacks
|
8
|
+
@service_callbacks = {}
|
9
|
+
end
|
10
|
+
|
11
|
+
def register_callback(type_of_callback, method_name = nil, &block)
|
12
|
+
unless TYPES_OF_CALLBACK.include?(type_of_callback)
|
13
|
+
raise UnknownTypeOfCallbackError, "Type #{type_of_callback} is not allowed"
|
14
|
+
end
|
15
|
+
@service_callbacks ||= {}
|
16
|
+
@service_callbacks[type_of_callback] ||= []
|
17
|
+
@service_callbacks[type_of_callback] << method_name if method_name
|
18
|
+
@service_callbacks[type_of_callback] << block if block_given?
|
19
|
+
nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def execute_callbacks(type_of_callback, instance)
|
23
|
+
unless TYPES_OF_CALLBACK.include?(type_of_callback)
|
24
|
+
raise UnknownTypeOfCallbackError, "Type #{type_of_callback} is not allowed"
|
25
|
+
end
|
26
|
+
cbs = (@service_callbacks || {}).fetch(type_of_callback, [])
|
27
|
+
cbs.each { |cb| instance.instance_eval(&cb) }
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
|
31
|
+
TYPES_OF_CALLBACK.each do |type_of_callback|
|
32
|
+
define_method "on_#{type_of_callback}" do |method_name = nil, &block|
|
33
|
+
register_callback(type_of_callback, method_name, &block)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/performify.rb
ADDED
data/performify.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'performify/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "performify"
|
8
|
+
spec.version = Performify::VERSION
|
9
|
+
spec.authors = ["Sergey Tsvetkov"]
|
10
|
+
spec.email = ["sergey.a.tsvetkov@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{
|
13
|
+
Service classes that makes your life easier
|
14
|
+
}
|
15
|
+
|
16
|
+
spec.description = %q{
|
17
|
+
Performify helps you to define your app logic in separated and isolated service classes
|
18
|
+
that is easy to use, test and maitain.
|
19
|
+
}
|
20
|
+
|
21
|
+
spec.homepage = "https://github.com/kimrgrey/performify"
|
22
|
+
spec.license = "MIT"
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
f.match(%r{^(test|spec|features)/})
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_dependency "activerecord", ">= 4.0.0"
|
32
|
+
|
33
|
+
spec.add_development_dependency "sqlite3"
|
34
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
35
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
36
|
+
spec.add_development_dependency "rspec", "~> 3.5"
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: performify
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sergey Tsvetkov
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-04-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sqlite3
|
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: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.14'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.5'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.5'
|
83
|
+
description: "\n Performify helps you to define your app logic in separated and
|
84
|
+
isolated service classes\n that is easy to use, test and maitain.\n "
|
85
|
+
email:
|
86
|
+
- sergey.a.tsvetkov@gmail.com
|
87
|
+
executables: []
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- ".rspec"
|
93
|
+
- ".travis.yml"
|
94
|
+
- Gemfile
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/rake
|
100
|
+
- bin/rspec
|
101
|
+
- bin/setup
|
102
|
+
- lib/performify.rb
|
103
|
+
- lib/performify/base.rb
|
104
|
+
- lib/performify/callbacks.rb
|
105
|
+
- lib/performify/version.rb
|
106
|
+
- performify.gemspec
|
107
|
+
homepage: https://github.com/kimrgrey/performify
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.5.1
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Service classes that makes your life easier
|
131
|
+
test_files: []
|