rack-app 3.0.0.delta → 3.0.0.gamma

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9fa3133ed7bd4031d0703e2c039f4ee62c8fb59d
4
- data.tar.gz: 5708b587c27a12a03536afc88e4dc6db0a75bdef
3
+ metadata.gz: 15eb9ec10fdc0e02a3cb11addc8b894951d69440
4
+ data.tar.gz: d5279dda2a8261405333f46e4eab83633fdaf8be
5
5
  SHA512:
6
- metadata.gz: 09e480478c10196def5fb0307c248c54da46aaf852a81f5f15dfc370c16e37e47f469f748d9018f3e4741239a384fab8f3dcf9e2df9d8681da4d8610213b747e
7
- data.tar.gz: dbe8e342c8997a9f76f8b7c3e58a196000f267dbec814b6b91260bb9dc24bb60be463e8d97334ae0b22f4b505ad90a2eac29abef2b6967e6bf962a7c589f7ba9
6
+ metadata.gz: 72b4effba0e6198d4996c994402f920d34abedeb336addb65bacdd6a5ad1e2d8074a446800df5efbc58e4b638c6719605ee547d9a501993c32d142c2170349e5
7
+ data.tar.gz: 3b64ceccee914c068ffc5dc661ba8c12805853ab7c69e1165f8ba62dc7c340ad50335d76bbc1c19b2e35413d4799cec8816f0f0a8a76462a22e9a074944ef64d
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.0.delta
1
+ 3.0.0.gamma
data/lib/rack/app.rb CHANGED
@@ -7,7 +7,6 @@ class Rack::App
7
7
  require 'rack/app/version'
8
8
  require 'rack/app/constants'
9
9
 
10
- require 'rack/app/cli'
11
10
  require 'rack/app/test'
12
11
  require 'rack/app/utils'
13
12
  require 'rack/app/params'
@@ -30,7 +30,7 @@ class Rack::App::ErrorHandler
30
30
  end
31
31
 
32
32
  def parent(ex)
33
- handler = @handlers.find { |exception_class, _| ex.class <= 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
 
@@ -1,31 +1,44 @@
1
- module Rack::App::Extension
1
+ class Rack::App::Extension
2
2
 
3
- extend self
3
+ require 'rack/app/extension/factory'
4
4
 
5
- def apply_extensions(app_class, *extension_names)
6
- extension_names.each do |extension_name|
5
+ class << self
7
6
 
8
- ext = find_extension_for(extension_name) || raise("Not registered extension name requested: #{extension_name}")
9
- app_class.class_eval(&ext)
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
- def register(extension_name, &builder_block)
16
- extension_registration_name = extension_name.to_s.to_sym
17
- extensions[extension_registration_name]= builder_block
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
- protected
19
+ def includes
20
+ @includes ||= []
21
+ end
22
22
 
23
- def extensions
24
- @extensions ||= {}
25
- end
23
+ def extends
24
+ @extends ||= []
25
+ end
26
26
 
27
- def find_extension_for(sym_name)
28
- return extensions[sym_name.to_s.to_sym]
29
- end
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, &on_mount)
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(*extension_names)
28
- Rack::App::Extension.apply_extensions(self,*extension_names)
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, Method
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, try_dup(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, duplication)
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 = get_instance_variable(object, instance_variable)
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 duplication
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.delta
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-04-01 00:00:00.000000000 Z
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
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'rack/app/cli'
3
- Rack::App::CLI.start(ARGV)
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
@@ -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