tarquinn 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +35 -0
- data/LICENSE +22 -0
- data/README.md +0 -0
- data/Rakefile +7 -0
- data/lib/tarquinn/builder.rb +23 -0
- data/lib/tarquinn/class_methods.rb +13 -0
- data/lib/tarquinn/concern.rb +17 -0
- data/lib/tarquinn/config.rb +33 -0
- data/lib/tarquinn/engine.rb +27 -0
- data/lib/tarquinn/handler.rb +58 -0
- data/lib/tarquinn/version.rb +3 -0
- data/lib/tarquinn.rb +9 -0
- data/spec/spec_helper.rb +19 -0
- data/tarquinn.gemspec +24 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ecb0edee29d3f22108388751e86d64641f06e927
|
4
|
+
data.tar.gz: 4502cfa609572a32c6137bd2ff2639ee90641065
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1c57b6df4121b783036ff66f4bb32591e98c16c3a7e57abc997158a55d0b5d67455894c557a2a135e840aef91c6722f4732876cdd18af4e4ac5e5a3bc1f4d9e5
|
7
|
+
data.tar.gz: 2ba5ac3b72a550cbd48dc45858331e69d2e944fe62cac24e703461af7dabb9be7502bc6d44a25ee7e8d14124048ca3a1fee412d6f28764e9f5fa855e91da3e75
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tarquinn (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.2.5)
|
10
|
+
docile (1.1.5)
|
11
|
+
json (1.8.3)
|
12
|
+
rake (10.4.2)
|
13
|
+
rspec (2.99.0)
|
14
|
+
rspec-core (~> 2.99.0)
|
15
|
+
rspec-expectations (~> 2.99.0)
|
16
|
+
rspec-mocks (~> 2.99.0)
|
17
|
+
rspec-core (2.99.2)
|
18
|
+
rspec-expectations (2.99.2)
|
19
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
20
|
+
rspec-mocks (2.99.4)
|
21
|
+
simplecov (0.10.0)
|
22
|
+
docile (~> 1.1.0)
|
23
|
+
json (~> 1.8)
|
24
|
+
simplecov-html (~> 0.10.0)
|
25
|
+
simplecov-html (0.10.0)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
bundler (~> 1.6)
|
32
|
+
rake
|
33
|
+
rspec (~> 2.14)
|
34
|
+
simplecov
|
35
|
+
tarquinn!
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Favini
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
File without changes
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
class Tarquinn::Builder
|
2
|
+
def add_redirection_config(redirection, *methods, block)
|
3
|
+
config_for(redirection).add_redirection_rules(*methods, &block)
|
4
|
+
end
|
5
|
+
|
6
|
+
def add_skip_config(redirection, *methods, block)
|
7
|
+
config_for(redirection).add_skip_rules(*methods, &block)
|
8
|
+
end
|
9
|
+
|
10
|
+
def build(controller)
|
11
|
+
Tarquinn::Engine.new(configs, controller)
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def config_for(redirection)
|
17
|
+
configs[redirection.to_sym] ||= Tarquinn::Config.new(redirection)
|
18
|
+
end
|
19
|
+
|
20
|
+
def configs
|
21
|
+
@configs ||= {}
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Tarquinn::ClassMethods
|
2
|
+
def redirection_rule(redirection, *methods, &block)
|
3
|
+
redirector_builder.add_redirection_config(redirection, *methods, block)
|
4
|
+
end
|
5
|
+
|
6
|
+
def skip_redirection_rule(redirection, *methods, &block)
|
7
|
+
redirector_builder.add_skip_config(redirection, *methods, block)
|
8
|
+
end
|
9
|
+
|
10
|
+
def redirector_builder
|
11
|
+
@redirector_builder ||= Tarquinn::Builder.new
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Tarquinn
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
before_action :perform_redirection
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def redirector_engine
|
11
|
+
self.class.redirector_builder.build(self)
|
12
|
+
end
|
13
|
+
|
14
|
+
def perform_redirection
|
15
|
+
redirector_engine.perform_redirect
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class Tarquinn::Config
|
2
|
+
attr_accessor :redirect
|
3
|
+
|
4
|
+
def initialize(redirect)
|
5
|
+
@redirect = redirect
|
6
|
+
end
|
7
|
+
|
8
|
+
def add_redirection_rules(*methods, &block)
|
9
|
+
self.methods.concat methods
|
10
|
+
blocks << block if block_given?
|
11
|
+
end
|
12
|
+
|
13
|
+
def add_skip_rules(*methods, &block)
|
14
|
+
skip_methods.concat methods
|
15
|
+
skip_blocks << block if block_given?
|
16
|
+
end
|
17
|
+
|
18
|
+
def methods
|
19
|
+
@methods ||= []
|
20
|
+
end
|
21
|
+
|
22
|
+
def skip_methods
|
23
|
+
@skip_methods ||= []
|
24
|
+
end
|
25
|
+
|
26
|
+
def blocks
|
27
|
+
@blocks ||= []
|
28
|
+
end
|
29
|
+
|
30
|
+
def skip_blocks
|
31
|
+
@skip_blocks ||= []
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Tarquinn::Engine
|
2
|
+
attr_reader :configs, :controller
|
3
|
+
|
4
|
+
def initialize(configs, controller)
|
5
|
+
@configs = configs
|
6
|
+
@controller = controller
|
7
|
+
end
|
8
|
+
|
9
|
+
def perform_redirect?
|
10
|
+
handlers.any? { |h| h.perform_redirect? }
|
11
|
+
end
|
12
|
+
|
13
|
+
def perform_redirect
|
14
|
+
return unless perform_redirect?
|
15
|
+
handlers.find { |h| h.perform_redirect? }.redirect
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def handlers
|
21
|
+
@handlers ||= build_handlers
|
22
|
+
end
|
23
|
+
|
24
|
+
def build_handlers
|
25
|
+
configs.map { |_,c| Tarquinn::Handler.new(c, controller) }
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
class Tarquinn::Handler
|
2
|
+
attr_accessor :config, :controller
|
3
|
+
|
4
|
+
delegate :methods, :skip_methods, :blocks, :skip_blocks, to: :config
|
5
|
+
|
6
|
+
def initialize(config, controller)
|
7
|
+
@config = config
|
8
|
+
@controller = controller
|
9
|
+
end
|
10
|
+
|
11
|
+
def perform_redirect?
|
12
|
+
@perform_redirect = is_redirect? if @perform_redirect.nil?
|
13
|
+
@perform_redirect
|
14
|
+
end
|
15
|
+
|
16
|
+
def redirect
|
17
|
+
controller.send(:redirect_to, redirect_path)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def redirect_method
|
23
|
+
config.redirect
|
24
|
+
end
|
25
|
+
|
26
|
+
def redirect_path
|
27
|
+
controller.send(config.redirect)
|
28
|
+
end
|
29
|
+
|
30
|
+
def is_redirect?
|
31
|
+
return false if methods_skip_redirect? || blocks_skip_redirect?
|
32
|
+
methods_require_redirect? || blocks_require_redirect?
|
33
|
+
end
|
34
|
+
|
35
|
+
def methods_skip_redirect?
|
36
|
+
skip_methods.any? do |method|
|
37
|
+
controller.send(method)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def blocks_skip_redirect?
|
42
|
+
skip_blocks.any? do |block|
|
43
|
+
block.yield
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def methods_require_redirect?
|
48
|
+
methods.any? do |method|
|
49
|
+
controller.send(method)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def blocks_require_redirect?
|
54
|
+
blocks.any? do |block|
|
55
|
+
block.yield
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/tarquinn.rb
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
require 'tarquinn'
|
5
|
+
|
6
|
+
support_files = File.expand_path("spec/support/**/*.rb")
|
7
|
+
Dir[support_files].each { |file| require file }
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
config.filter_run_excluding :integration unless ENV['ALL']
|
14
|
+
|
15
|
+
config.order = 'random'
|
16
|
+
|
17
|
+
config.before do
|
18
|
+
end
|
19
|
+
end
|
data/tarquinn.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 'tarquinn/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = 'tarquinn'
|
8
|
+
gem.version = Tarquinn::VERSION
|
9
|
+
gem.authors = %w(DarthJee)
|
10
|
+
gem.email = %w(darthjee@gmail.com)
|
11
|
+
gem.homepage = 'https://github.com/darthje/tarquinn'
|
12
|
+
gem.description = 'Gem for easy redirection controll'
|
13
|
+
gem.summary = gem.description
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "bundler", "~> 1.6"
|
21
|
+
gem.add_development_dependency "rake"
|
22
|
+
gem.add_development_dependency "rspec", "~> 2.14"
|
23
|
+
gem.add_development_dependency 'simplecov'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tarquinn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- DarthJee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-29 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: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.14'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.14'
|
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: Gem for easy redirection controll
|
70
|
+
email:
|
71
|
+
- darthjee@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- Gemfile
|
77
|
+
- Gemfile.lock
|
78
|
+
- LICENSE
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- lib/tarquinn.rb
|
82
|
+
- lib/tarquinn/builder.rb
|
83
|
+
- lib/tarquinn/class_methods.rb
|
84
|
+
- lib/tarquinn/concern.rb
|
85
|
+
- lib/tarquinn/config.rb
|
86
|
+
- lib/tarquinn/engine.rb
|
87
|
+
- lib/tarquinn/handler.rb
|
88
|
+
- lib/tarquinn/version.rb
|
89
|
+
- spec/spec_helper.rb
|
90
|
+
- tarquinn.gemspec
|
91
|
+
homepage: https://github.com/darthje/tarquinn
|
92
|
+
licenses: []
|
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.4.6
|
111
|
+
signing_key:
|
112
|
+
specification_version: 4
|
113
|
+
summary: Gem for easy redirection controll
|
114
|
+
test_files: []
|