rack-app 3.0.0.delta → 3.0.0.gamma
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 +4 -4
- data/VERSION +1 -1
- data/lib/rack/app.rb +0 -1
- data/lib/rack/app/error_handler.rb +1 -1
- data/lib/rack/app/extension.rb +33 -20
- data/lib/rack/app/extension/factory.rb +13 -0
- data/lib/rack/app/singleton_methods/inheritance.rb +1 -1
- data/lib/rack/app/singleton_methods/mounting.rb +2 -4
- data/lib/rack/app/singleton_methods/settings.rb +20 -8
- data/lib/rack/app/utils/deep_dup.rb +6 -41
- metadata +4 -8
- data/.rubocop.yml +0 -46
- data/bin/rack-app +0 -3
- data/lib/rack/app/cli.rb +0 -45
- data/lib/rack/app/cli/command.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15eb9ec10fdc0e02a3cb11addc8b894951d69440
|
4
|
+
data.tar.gz: d5279dda2a8261405333f46e4eab83633fdaf8be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72b4effba0e6198d4996c994402f920d34abedeb336addb65bacdd6a5ad1e2d8074a446800df5efbc58e4b638c6719605ee547d9a501993c32d142c2170349e5
|
7
|
+
data.tar.gz: 3b64ceccee914c068ffc5dc661ba8c12805853ab7c69e1165f8ba62dc7c340ad50335d76bbc1c19b2e35413d4799cec8816f0f0a8a76462a22e9a074944ef64d
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0.0.
|
1
|
+
3.0.0.gamma
|
data/lib/rack/app.rb
CHANGED
@@ -30,7 +30,7 @@ class Rack::App::ErrorHandler
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def parent(ex)
|
33
|
-
handler = @handlers.find { |exception_class,
|
33
|
+
handler = @handlers.find { |exception_class, handler| ex.class <= exception_class }
|
34
34
|
return handler.nil? ? nil : handler.last
|
35
35
|
end
|
36
36
|
|
data/lib/rack/app/extension.rb
CHANGED
@@ -1,31 +1,44 @@
|
|
1
|
-
|
1
|
+
class Rack::App::Extension
|
2
2
|
|
3
|
-
|
3
|
+
require 'rack/app/extension/factory'
|
4
4
|
|
5
|
-
|
6
|
-
extension_names.each do |extension_name|
|
5
|
+
class << self
|
7
6
|
|
8
|
-
|
9
|
-
|
7
|
+
def names
|
8
|
+
@names ||= []
|
9
|
+
end
|
10
10
|
|
11
|
+
def name(extension_name_alias)
|
12
|
+
names << extension_name_alias.to_s.to_sym
|
11
13
|
end
|
12
|
-
nil
|
13
|
-
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
extension_registration_name
|
19
|
-
end
|
15
|
+
def inherited(klass)
|
16
|
+
klass.name(Rack::App::Utils.snake_case(klass.to_s.split('::').last).to_sym)
|
17
|
+
end
|
20
18
|
|
21
|
-
|
19
|
+
def includes
|
20
|
+
@includes ||= []
|
21
|
+
end
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
def extends
|
24
|
+
@extends ||= []
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
def inheritances
|
28
|
+
@on_inheritances ||= []
|
29
|
+
end
|
30
|
+
|
31
|
+
def include(endpoint_methods_module)
|
32
|
+
includes << endpoint_methods_module
|
33
|
+
end
|
34
|
+
|
35
|
+
def extend(app_class_methods_module)
|
36
|
+
extends << app_class_methods_module
|
37
|
+
end
|
38
|
+
|
39
|
+
def on_inheritance(&block)
|
40
|
+
inheritances << block
|
41
|
+
end
|
30
42
|
|
43
|
+
end
|
31
44
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Rack::App::Extension::Factory
|
2
|
+
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def all
|
6
|
+
ObjectSpace.each_object(Class).select { |klass| klass < ::Rack::App::Extension }
|
7
|
+
end
|
8
|
+
|
9
|
+
def find_for(sym_name)
|
10
|
+
return all.find{|extension_class| extension_class.names.include?(sym_name) }
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
@@ -12,7 +12,7 @@ module Rack::App::SingletonMethods::Inheritance
|
|
12
12
|
|
13
13
|
child.serializer(&serializer.logic)
|
14
14
|
child.headers.merge!(headers)
|
15
|
-
child.middlewares.push(*middlewares)
|
15
|
+
child.__send__(:middlewares).push(*middlewares)
|
16
16
|
|
17
17
|
on_inheritance.each do |block|
|
18
18
|
block.call(self, child)
|
@@ -10,15 +10,13 @@ module Rack::App::SingletonMethods::Mounting
|
|
10
10
|
duplication = ::Rack::App::Utils.deep_dup(api_class)
|
11
11
|
|
12
12
|
duplication.on_mounted.each do |on_mount|
|
13
|
-
duplication.class_exec(mount_prop
|
13
|
+
duplication.class_exec(mount_prop,&on_mount)
|
14
14
|
end
|
15
15
|
|
16
|
-
cli.merge!(duplication.cli)
|
17
|
-
|
18
16
|
merge_prop = {:namespaces => [@namespaces, mount_to_path].flatten}
|
19
17
|
router.merge_router!(duplication.router, merge_prop)
|
20
18
|
|
21
|
-
nil
|
19
|
+
return nil
|
22
20
|
end
|
23
21
|
|
24
22
|
def mount_directory(directory_path, options={})
|
@@ -1,11 +1,5 @@
|
|
1
1
|
module Rack::App::SingletonMethods::Settings
|
2
2
|
|
3
|
-
def cli(&block)
|
4
|
-
@cli ||= Rack::App::CLI.new
|
5
|
-
@cli.instance_exec(&block) unless block.nil?
|
6
|
-
@cli
|
7
|
-
end
|
8
|
-
|
9
3
|
protected
|
10
4
|
|
11
5
|
def serializer(&definition_how_to_serialize)
|
@@ -24,8 +18,24 @@ module Rack::App::SingletonMethods::Settings
|
|
24
18
|
@headers
|
25
19
|
end
|
26
20
|
|
27
|
-
def extensions(*
|
28
|
-
|
21
|
+
def extensions(*extensions)
|
22
|
+
extensions.each do |ext|
|
23
|
+
|
24
|
+
if ext.is_a?(Symbol)
|
25
|
+
ext = Rack::App::Extension::Factory::find_for(ext)
|
26
|
+
end
|
27
|
+
|
28
|
+
if ext.is_a?(::Class) && ext < ::Rack::App::Extension
|
29
|
+
|
30
|
+
ext.includes.each { |m| include(m) }
|
31
|
+
ext.extends.each { |m| extend(m) }
|
32
|
+
ext.inheritances.each { |block| on_inheritance(&block) }
|
33
|
+
|
34
|
+
else
|
35
|
+
raise("unsupported extension reference: #{ext.inspect}")
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
29
39
|
end
|
30
40
|
|
31
41
|
def error(*exception_classes, &block)
|
@@ -37,6 +47,8 @@ module Rack::App::SingletonMethods::Settings
|
|
37
47
|
return @error_handler
|
38
48
|
end
|
39
49
|
|
50
|
+
private
|
51
|
+
|
40
52
|
def middlewares(&block)
|
41
53
|
@middlewares ||= []
|
42
54
|
@middlewares << block unless block.nil?
|
@@ -21,7 +21,6 @@ module Rack::App::Utils::DeepDup
|
|
21
21
|
|
22
22
|
def dup(register, object)
|
23
23
|
|
24
|
-
return object unless registrable?(object)
|
25
24
|
return registered(object, register) if registered(object, register)
|
26
25
|
|
27
26
|
case object
|
@@ -38,7 +37,7 @@ module Rack::App::Utils::DeepDup
|
|
38
37
|
when Struct
|
39
38
|
dup_struct(register, object)
|
40
39
|
|
41
|
-
when NilClass, Symbol, Numeric, TrueClass, FalseClass
|
40
|
+
when NilClass, Symbol, Numeric, TrueClass, FalseClass
|
42
41
|
register_duplication(register, object, object)
|
43
42
|
|
44
43
|
else
|
@@ -47,13 +46,6 @@ module Rack::App::Utils::DeepDup
|
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
50
|
-
def registrable?(object)
|
51
|
-
object.object_id
|
52
|
-
true
|
53
|
-
rescue NoMethodError
|
54
|
-
false
|
55
|
-
end
|
56
|
-
|
57
49
|
def dup_array(register, object)
|
58
50
|
duplication = dup_object(register, object)
|
59
51
|
duplication.map! { |e| dup(register, e) }
|
@@ -81,43 +73,16 @@ module Rack::App::Utils::DeepDup
|
|
81
73
|
end
|
82
74
|
|
83
75
|
def dup_object(register, object)
|
84
|
-
dup_instance_variables(register, object, register_duplication(register, object,
|
76
|
+
dup_instance_variables(register, object, register_duplication(register, object, object.dup))
|
85
77
|
end
|
86
78
|
|
87
|
-
def dup_instance_variables(register, object,
|
88
|
-
return duplication unless respond_to_instance_variables?(object)
|
89
|
-
|
79
|
+
def dup_instance_variables(register, object, duplicate)
|
90
80
|
object.instance_variables.each do |instance_variable|
|
91
|
-
value =
|
92
|
-
|
93
|
-
set_instance_variable(duplication, instance_variable, dup(register, value))
|
81
|
+
value = object.instance_variable_get(instance_variable)
|
82
|
+
duplicate.instance_variable_set(instance_variable, dup(register, value))
|
94
83
|
end
|
95
84
|
|
96
|
-
return
|
97
|
-
end
|
98
|
-
|
99
|
-
def get_instance_variable(object, instance_variable_name)
|
100
|
-
object.instance_variable_get(instance_variable_name)
|
101
|
-
rescue NoMethodError
|
102
|
-
object.instance_eval("#{instance_variable_name}")
|
103
|
-
end
|
104
|
-
|
105
|
-
def set_instance_variable(duplicate, instance_variable_name, value_to_set)
|
106
|
-
duplicate.instance_variable_set(instance_variable_name, value_to_set)
|
107
|
-
rescue NoMethodError
|
108
|
-
duplicate.instance_eval("#{instance_variable_name} = Marshal.load(#{Marshal.dump(value_to_set).inspect})")
|
109
|
-
end
|
110
|
-
|
111
|
-
def try_dup(object)
|
112
|
-
object.dup
|
113
|
-
rescue NoMethodError, TypeError
|
114
|
-
object
|
115
|
-
end
|
116
|
-
|
117
|
-
def respond_to_instance_variables?(object)
|
118
|
-
object.respond_to?(:instance_variables)
|
119
|
-
rescue NoMethodError
|
120
|
-
false
|
85
|
+
return duplicate
|
121
86
|
end
|
122
87
|
|
123
88
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.
|
4
|
+
version: 3.0.0.gamma
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -70,14 +70,12 @@ description: Your next favourite rack based micro framework that is totally addi
|
|
70
70
|
free! Have a cup of awesomeness with your to performance designed framework!
|
71
71
|
email:
|
72
72
|
- adamluzsi@gmail.com
|
73
|
-
executables:
|
74
|
-
- rack-app
|
73
|
+
executables: []
|
75
74
|
extensions: []
|
76
75
|
extra_rdoc_files: []
|
77
76
|
files:
|
78
77
|
- ".gitignore"
|
79
78
|
- ".rspec"
|
80
|
-
- ".rubocop.yml"
|
81
79
|
- ".travis.yml"
|
82
80
|
- CODE_OF_CONDUCT.md
|
83
81
|
- CONTRIBUTING.md
|
@@ -88,15 +86,13 @@ files:
|
|
88
86
|
- Rakefile
|
89
87
|
- VERSION
|
90
88
|
- Vagrantfile
|
91
|
-
- bin/rack-app
|
92
89
|
- lib/rack/app.rb
|
93
|
-
- lib/rack/app/cli.rb
|
94
|
-
- lib/rack/app/cli/command.rb
|
95
90
|
- lib/rack/app/constants.rb
|
96
91
|
- lib/rack/app/endpoint.rb
|
97
92
|
- lib/rack/app/endpoint/not_found.rb
|
98
93
|
- lib/rack/app/error_handler.rb
|
99
94
|
- lib/rack/app/extension.rb
|
95
|
+
- lib/rack/app/extension/factory.rb
|
100
96
|
- lib/rack/app/file_server.rb
|
101
97
|
- lib/rack/app/instance_methods.rb
|
102
98
|
- lib/rack/app/instance_methods/core.rb
|
data/.rubocop.yml
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
AllCops:
|
2
|
-
Exclude:
|
3
|
-
- 'vendor/**/*'
|
4
|
-
- 'spec/fixtures/**/*'
|
5
|
-
- 'tmp/**/*'
|
6
|
-
|
7
|
-
Style/AndOr:
|
8
|
-
Enabled: false
|
9
|
-
|
10
|
-
Style/HashSyntax:
|
11
|
-
Enabled: false
|
12
|
-
|
13
|
-
Style/Documentation:
|
14
|
-
Enabled: false
|
15
|
-
|
16
|
-
Style/TrailingBlankLines:
|
17
|
-
Enabled: false
|
18
|
-
|
19
|
-
Style/SpaceAroundOperators:
|
20
|
-
Enabled: false
|
21
|
-
|
22
|
-
Style/ClassAndModuleChildren:
|
23
|
-
Enabled: false
|
24
|
-
|
25
|
-
Style/EmptyLinesAroundClassBody:
|
26
|
-
Enabled: false
|
27
|
-
|
28
|
-
Style/EmptyLinesAroundModuleBody:
|
29
|
-
Enabled: false
|
30
|
-
|
31
|
-
Style/EmptyLinesAroundMethodBody:
|
32
|
-
Enabled: false
|
33
|
-
|
34
|
-
Style/SpaceInsideHashLiteralBraces:
|
35
|
-
Enabled: false
|
36
|
-
|
37
|
-
Style/SpaceAroundEqualsInParameterDefault:
|
38
|
-
Enabled: false
|
39
|
-
|
40
|
-
Metrics/AbcSize:
|
41
|
-
Enabled: false
|
42
|
-
|
43
|
-
# Enabled: false
|
44
|
-
# Enabled: false
|
45
|
-
# Enabled: false
|
46
|
-
# Enabled: false
|
data/bin/rack-app
DELETED
data/lib/rack/app/cli.rb
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
require 'rack/app'
|
2
|
-
require 'optparse'
|
3
|
-
class Rack::App::CLI
|
4
|
-
|
5
|
-
require 'rack/app/cli/command'
|
6
|
-
|
7
|
-
def self.start(argv)
|
8
|
-
@argv = Rack::App::Utils.deep_dup(argv)
|
9
|
-
|
10
|
-
context = {}
|
11
|
-
Kernel.__send__(:define_method, :run) { |app, *_| context[:app]= app }
|
12
|
-
config_ru_file_path = Rack::App::Utils.pwd('config.ru')
|
13
|
-
load(config_ru_file_path) if File.exist?(config_ru_file_path)
|
14
|
-
|
15
|
-
context[:app].cli.start(argv)
|
16
|
-
end
|
17
|
-
|
18
|
-
def start(argv)
|
19
|
-
command_name = argv.shift
|
20
|
-
command = find_command_for(command_name)
|
21
|
-
command && command.start(argv)
|
22
|
-
end
|
23
|
-
|
24
|
-
def merge!(cli)
|
25
|
-
commands.push(*cli.commands)
|
26
|
-
self
|
27
|
-
end
|
28
|
-
|
29
|
-
protected
|
30
|
-
|
31
|
-
def find_command_for(command_name)
|
32
|
-
commands.find { |command| command.name == command_name }
|
33
|
-
end
|
34
|
-
|
35
|
-
def commands
|
36
|
-
@commands ||= []
|
37
|
-
end
|
38
|
-
|
39
|
-
def command(name, &block)
|
40
|
-
command_prototype = Rack::App::Utils.deep_dup(Rack::App::CLI::Command)
|
41
|
-
command_prototype.instance_exec(&block)
|
42
|
-
commands << command_prototype.new(name)
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
data/lib/rack/app/cli/command.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
class Rack::App::CLI::Command
|
2
|
-
|
3
|
-
require 'optparse'
|
4
|
-
|
5
|
-
class << self
|
6
|
-
|
7
|
-
def options_parser_options
|
8
|
-
@options_parser_options ||= []
|
9
|
-
end
|
10
|
-
|
11
|
-
def description(message = nil)
|
12
|
-
@description = message unless message.nil?
|
13
|
-
@description || ''
|
14
|
-
end
|
15
|
-
|
16
|
-
alias desc description
|
17
|
-
|
18
|
-
def option(*args, &block)
|
19
|
-
options_parser_options << {:args => args, :block => block}
|
20
|
-
end
|
21
|
-
|
22
|
-
alias on option
|
23
|
-
|
24
|
-
def action(&block)
|
25
|
-
@action = block unless block.nil?
|
26
|
-
@action || Proc.new {}
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
attr_reader :name
|
32
|
-
|
33
|
-
def initialize(name)
|
34
|
-
@name = name.to_s
|
35
|
-
@option_parser = OptionParser.new
|
36
|
-
self.class.options_parser_options.each { |h| @option_parser.on(*h[:args], &h[:block]) }
|
37
|
-
end
|
38
|
-
|
39
|
-
def description
|
40
|
-
self.class.description
|
41
|
-
end
|
42
|
-
|
43
|
-
def start(argv)
|
44
|
-
@option_parser.parse!(argv)
|
45
|
-
instance_exec(*argv,&(self.class.action))
|
46
|
-
end
|
47
|
-
|
48
|
-
end
|