corvette 0.0.2
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 +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/corvette.gemspec +27 -0
- data/lib/corvette/act.rb +122 -0
- data/lib/corvette/action.rb +18 -0
- data/lib/corvette/assertion.rb +7 -0
- data/lib/corvette/operation.rb +54 -0
- data/lib/corvette/procedure.rb +49 -0
- data/lib/corvette/railtie.rb +13 -0
- data/lib/corvette/service.rb +6 -0
- data/lib/corvette/version.rb +3 -0
- data/lib/corvette.rb +16 -0
- metadata +143 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: cee5ee9bcae209772e61cdb2c97c0bc15ff6b363
|
4
|
+
data.tar.gz: 0c78a900f9a0de81c60e34ad6f36abcac687fbe3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 36c59701ffc4689b5097338bf5aace9a7ed2f7bf46a93ad3904fdd740a9c43c5f84ce6c856870c091329c5540f714e68267f7209e250e40ad27fb328c5b162d9
|
7
|
+
data.tar.gz: 0ba8a5a7259ae2da55493faa12089e4ede7761b56bd31cfc19fbf39a2cea97630062e4590497a103e8a3a3f419c924fd4a5f77215d3d61702809b0b13c1679f3
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
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
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 BroderickBrockman
|
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
|
+
# Corvette
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'corvette'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install corvette
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/corvette/fork )
|
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 a new Pull Request
|
data/Rakefile
ADDED
data/corvette.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'corvette/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'corvette'
|
8
|
+
spec.version = Corvette::VERSION
|
9
|
+
spec.authors = ['BroderickBrockman']
|
10
|
+
spec.email = ['broderickbrockman@gmail.com']
|
11
|
+
spec.summary = %q{Kind of new rails architecture solution}
|
12
|
+
spec.description = %q{Some kind of new rails architecture solution}
|
13
|
+
spec.homepage = 'http://corvette-gem.com'
|
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.6'
|
22
|
+
spec.add_development_dependency 'rake', '~> 0'
|
23
|
+
spec.add_runtime_dependency 'reform', '1.1.1'
|
24
|
+
spec.add_runtime_dependency 'hashie', '3.3.1'
|
25
|
+
spec.add_runtime_dependency 'activesupport', '4.1.5'
|
26
|
+
spec.add_runtime_dependency 'virtus', '1.0.3'
|
27
|
+
end
|
data/lib/corvette/act.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'corvette/assertion'
|
2
|
+
module Corvette
|
3
|
+
class Act
|
4
|
+
class ActError < StandardError
|
5
|
+
attr_accessor :act
|
6
|
+
end
|
7
|
+
|
8
|
+
include Assertion
|
9
|
+
# include ActiveSupport::Rescuable
|
10
|
+
# rescue_from ERRORS, with: :log_error
|
11
|
+
|
12
|
+
def initialize(options={})
|
13
|
+
@options = options
|
14
|
+
process_callbacks
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
raise NotImplementedError, 'must be overridden'
|
19
|
+
end
|
20
|
+
|
21
|
+
def process_params(params)
|
22
|
+
assert { params.is_a?(Hash) }
|
23
|
+
|
24
|
+
if params.is_a?(Hashie::Mash)
|
25
|
+
@params = params
|
26
|
+
else
|
27
|
+
@params = Hashie::Mash.new(params)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def process_callbacks
|
32
|
+
@error_callback = @options[:on_error]
|
33
|
+
@success_callback = @options[:on_success]
|
34
|
+
end
|
35
|
+
|
36
|
+
def act_success
|
37
|
+
@success_callback.call(self) if @success_callback.is_a?(Proc)
|
38
|
+
end
|
39
|
+
|
40
|
+
def act_error(exception)
|
41
|
+
@error_callback.call(self, exception) if @error_callback.is_a?(Proc)
|
42
|
+
end
|
43
|
+
|
44
|
+
def log_error(exception, params = nil)
|
45
|
+
message = "message: #{ exception.message }; place: #{act_name}; (#{ exception.class })"
|
46
|
+
|
47
|
+
case exception
|
48
|
+
when Validation::ValidationError, Required::RequiredError
|
49
|
+
message << " error: #{exception.errors.inspect};"
|
50
|
+
else
|
51
|
+
#nothing
|
52
|
+
end
|
53
|
+
|
54
|
+
unless params.nil?
|
55
|
+
message << " params: #{params.inspect}"
|
56
|
+
end
|
57
|
+
|
58
|
+
Rails.logger.error message
|
59
|
+
end
|
60
|
+
|
61
|
+
def logger
|
62
|
+
Rails.logger
|
63
|
+
end
|
64
|
+
|
65
|
+
def act_name
|
66
|
+
@act_name ||= self.class.name.to_s
|
67
|
+
end
|
68
|
+
|
69
|
+
module Auxiliary
|
70
|
+
def process_auxiliary
|
71
|
+
if @options[:auxiliary]
|
72
|
+
@auxiliary = Hashie::Mash.new(@options[:auxiliary])
|
73
|
+
else
|
74
|
+
@auxiliary = Hashie::Mash.new
|
75
|
+
end
|
76
|
+
singleton_class.class_eval do
|
77
|
+
attr_reader :auxiliary
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
module Required
|
83
|
+
class RequiredError < StandardError
|
84
|
+
attr_accessor :errors
|
85
|
+
end
|
86
|
+
|
87
|
+
def process_required
|
88
|
+
if self.class.const_defined?(:RequiredContract)
|
89
|
+
@required = Hashie::Mash.new(@options[:required]||{})
|
90
|
+
required_contract = required_contract_class.new(@required)
|
91
|
+
unless required_contract.validate
|
92
|
+
exception = RequiredError.new
|
93
|
+
exception.errors = required_contract.errors.messages
|
94
|
+
raise exception
|
95
|
+
end
|
96
|
+
singleton_class.class_eval do
|
97
|
+
attr_reader :required
|
98
|
+
end
|
99
|
+
end
|
100
|
+
rescue StandardError => exception
|
101
|
+
# rescue_with_handler(exception) || raise
|
102
|
+
log_error(exception)
|
103
|
+
act_error(exception)
|
104
|
+
end
|
105
|
+
|
106
|
+
def required_contract_class
|
107
|
+
self.class.const_get :RequiredContract
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
module Validation
|
112
|
+
class ValidationError < StandardError
|
113
|
+
attr_accessor :errors
|
114
|
+
end
|
115
|
+
|
116
|
+
def contract_klass
|
117
|
+
self.class.const_get :Contract
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
# rescue_with_handler(exception) || raise
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'corvette/assertion'
|
2
|
+
require 'corvette/act'
|
3
|
+
|
4
|
+
module Corvette
|
5
|
+
class Action < Act
|
6
|
+
include Auxiliary
|
7
|
+
include Required
|
8
|
+
|
9
|
+
def action(params)
|
10
|
+
process_params(params)
|
11
|
+
yield
|
12
|
+
act_success
|
13
|
+
rescue StandardError => exception
|
14
|
+
log_error(exception, params)
|
15
|
+
act_error(exception)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
# require 'corvette/operation/model'
|
2
|
+
# require 'corvette/operation/multiple_models'
|
3
|
+
# require 'corvette/operation/anonymous_model'
|
4
|
+
# require 'corvette/operation/background_job'
|
5
|
+
# require 'corvette/operation/active_record_model'
|
6
|
+
|
7
|
+
require 'corvette/assertion'
|
8
|
+
require 'corvette/act'
|
9
|
+
|
10
|
+
module Corvette
|
11
|
+
class Operation < Act
|
12
|
+
include Validation
|
13
|
+
extend Forwardable
|
14
|
+
|
15
|
+
delegate [:model, :errors] => :contract
|
16
|
+
|
17
|
+
attr_reader :contract
|
18
|
+
|
19
|
+
def operation(model, params)
|
20
|
+
operation_log(:start)
|
21
|
+
process_params(params)
|
22
|
+
operation_validate(model, params)
|
23
|
+
yield
|
24
|
+
act_success
|
25
|
+
operation_log(:end)
|
26
|
+
rescue StandardError => exception
|
27
|
+
log_error(exception, params)
|
28
|
+
act_error(exception)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def operation_validate(model, params)
|
34
|
+
@contract = contract_klass.new(model)
|
35
|
+
unless contract.validate(params)
|
36
|
+
exception = ValidationError.new("validation failed")
|
37
|
+
exception.errors = contract.errors.messages
|
38
|
+
raise exception
|
39
|
+
end
|
40
|
+
operation_log(:validation_success)
|
41
|
+
end
|
42
|
+
|
43
|
+
def operation_log(kind)
|
44
|
+
case kind
|
45
|
+
when :start
|
46
|
+
logger.info "operation started (#{act_name})"
|
47
|
+
when :end
|
48
|
+
logger.info "operation ended (#{act_name})"
|
49
|
+
when :validation_success
|
50
|
+
logger.info "params validation succeeded (#{act_name})"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'corvette/assertion'
|
2
|
+
require 'corvette/act'
|
3
|
+
module Corvette
|
4
|
+
class Procedure < Act
|
5
|
+
|
6
|
+
include Validation
|
7
|
+
include Auxiliary
|
8
|
+
include Required
|
9
|
+
|
10
|
+
def procedure(params)
|
11
|
+
procedure_log(:start)
|
12
|
+
process_params(params)
|
13
|
+
process_auxiliary
|
14
|
+
process_required
|
15
|
+
procedure_validate(params)
|
16
|
+
yield
|
17
|
+
act_success
|
18
|
+
procedure_log(:end)
|
19
|
+
rescue StandardError => exception
|
20
|
+
log_error(exception, params)
|
21
|
+
act_error(exception)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def procedure_validate(params)
|
27
|
+
model = OpenStruct.new
|
28
|
+
contract = contract_klass.new(model)
|
29
|
+
|
30
|
+
unless contract.validate(params)
|
31
|
+
exception = ValidationError.new("validation failed")
|
32
|
+
exception.errors = contract.errors.messages
|
33
|
+
raise exception
|
34
|
+
end
|
35
|
+
procedure_log(:validation_success)
|
36
|
+
end
|
37
|
+
|
38
|
+
def procedure_log(kind)
|
39
|
+
case kind
|
40
|
+
when :start
|
41
|
+
logger.info "procedure started (#{act_name})"
|
42
|
+
when :end
|
43
|
+
logger.info "procedure ended (#{act_name})"
|
44
|
+
when :validation_success
|
45
|
+
logger.info "params validation succeeded (#{act_name})"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Corvette
|
2
|
+
class Railtie < ::Rails::Railtie
|
3
|
+
initializer 'corvette.basic', :after => :add_routing_paths do |app|
|
4
|
+
module StringGenerator
|
5
|
+
def generate_string(length)
|
6
|
+
o = [('a'..'z'), ('A'..'Z'), (0..9)].map { |i| i.to_a }.flatten
|
7
|
+
(0..length).map { o[rand(o.length)] }.join
|
8
|
+
end
|
9
|
+
end
|
10
|
+
Object.include(StringGenerator)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/corvette.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module Corvette
|
2
|
+
module Helper
|
3
|
+
def corvette_concept(name)
|
4
|
+
"#{name}_concept".camelcase.constantize
|
5
|
+
end
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
require "corvette/version"
|
10
|
+
require "corvette/railtie"
|
11
|
+
require "corvette/operation"
|
12
|
+
require "corvette/procedure"
|
13
|
+
require "corvette/action"
|
14
|
+
require "corvette/service"
|
15
|
+
require "corvette/assertion"
|
16
|
+
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: corvette
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- BroderickBrockman
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-05 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.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
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: reform
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.1.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.1.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hashie
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.3.1
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.3.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: activesupport
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 4.1.5
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 4.1.5
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: virtus
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.0.3
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.0.3
|
97
|
+
description: Some kind of new rails architecture solution
|
98
|
+
email:
|
99
|
+
- broderickbrockman@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".gitignore"
|
105
|
+
- Gemfile
|
106
|
+
- LICENSE.txt
|
107
|
+
- README.md
|
108
|
+
- Rakefile
|
109
|
+
- corvette.gemspec
|
110
|
+
- lib/corvette.rb
|
111
|
+
- lib/corvette/act.rb
|
112
|
+
- lib/corvette/action.rb
|
113
|
+
- lib/corvette/assertion.rb
|
114
|
+
- lib/corvette/operation.rb
|
115
|
+
- lib/corvette/procedure.rb
|
116
|
+
- lib/corvette/railtie.rb
|
117
|
+
- lib/corvette/service.rb
|
118
|
+
- lib/corvette/version.rb
|
119
|
+
homepage: http://corvette-gem.com
|
120
|
+
licenses:
|
121
|
+
- MIT
|
122
|
+
metadata: {}
|
123
|
+
post_install_message:
|
124
|
+
rdoc_options: []
|
125
|
+
require_paths:
|
126
|
+
- lib
|
127
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - ">="
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '0'
|
137
|
+
requirements: []
|
138
|
+
rubyforge_project:
|
139
|
+
rubygems_version: 2.2.2
|
140
|
+
signing_key:
|
141
|
+
specification_version: 4
|
142
|
+
summary: Kind of new rails architecture solution
|
143
|
+
test_files: []
|