rack-app 3.0.0.beta → 3.0.0.delta

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 115055ba41521d7fee618f4d2fe57b624471a39e
4
- data.tar.gz: 40fab600f70f7b89622a40106e94323e19b40d67
3
+ metadata.gz: 9fa3133ed7bd4031d0703e2c039f4ee62c8fb59d
4
+ data.tar.gz: 5708b587c27a12a03536afc88e4dc6db0a75bdef
5
5
  SHA512:
6
- metadata.gz: b8bb4760e69bc2815fc09664845dd7b172ade97d3723667c48166553bb8c994a534adbf430498e46f9f75f2e39320c6544cdb3238e6042fb1da43aef716181a5
7
- data.tar.gz: 333055adc24a03df566b36065931f921000901fc3f217204397964f96c1169d7140dbf28fc1b047079ef76486fa3186cac07d972fe8b64cfd2247c659d80de67
6
+ metadata.gz: 09e480478c10196def5fb0307c248c54da46aaf852a81f5f15dfc370c16e37e47f469f748d9018f3e4741239a384fab8f3dcf9e2df9d8681da4d8610213b747e
7
+ data.tar.gz: dbe8e342c8997a9f76f8b7c3e58a196000f267dbec814b6b91260bb9dc24bb60be463e8d97334ae0b22f4b505ad90a2eac29abef2b6967e6bf962a7c589f7ba9
@@ -0,0 +1,46 @@
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/VERSION CHANGED
@@ -1 +1 @@
1
- 3.0.0.beta
1
+ 3.0.0.delta
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rack/app/cli'
3
+ Rack::App::CLI.start(ARGV)
@@ -7,6 +7,7 @@ class Rack::App
7
7
  require 'rack/app/version'
8
8
  require 'rack/app/constants'
9
9
 
10
+ require 'rack/app/cli'
10
11
  require 'rack/app/test'
11
12
  require 'rack/app/utils'
12
13
  require 'rack/app/params'
@@ -0,0 +1,45 @@
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
@@ -0,0 +1,48 @@
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
@@ -30,7 +30,7 @@ class Rack::App::ErrorHandler
30
30
  end
31
31
 
32
32
  def parent(ex)
33
- handler = @handlers.find { |exception_class, handler| ex.class <= exception_class }
33
+ handler = @handlers.find { |exception_class, _| ex.class <= exception_class }
34
34
  return handler.nil? ? nil : handler.last
35
35
  end
36
36
 
@@ -1,29 +1,31 @@
1
- class Rack::App::Extension
2
- class << self
1
+ module Rack::App::Extension
3
2
 
4
- def includes
5
- @includes ||= []
6
- end
3
+ extend self
7
4
 
8
- def extends
9
- @extends ||= []
10
- end
5
+ def apply_extensions(app_class, *extension_names)
6
+ extension_names.each do |extension_name|
11
7
 
12
- def inheritances
13
- @on_inheritances ||= []
14
- end
8
+ ext = find_extension_for(extension_name) || raise("Not registered extension name requested: #{extension_name}")
9
+ app_class.class_eval(&ext)
15
10
 
16
- def include(endpoint_methods_module)
17
- includes << endpoint_methods_module
18
11
  end
12
+ nil
13
+ end
19
14
 
20
- def extend(app_class_methods_module)
21
- extends << app_class_methods_module
22
- end
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
23
20
 
24
- def on_inheritance(&block)
25
- inheritances << block
26
- end
21
+ protected
27
22
 
23
+ def extensions
24
+ @extensions ||= {}
28
25
  end
26
+
27
+ def find_extension_for(sym_name)
28
+ return extensions[sym_name.to_s.to_sym]
29
+ end
30
+
29
31
  end
@@ -6,15 +6,11 @@ class Rack::App::Router
6
6
  require 'rack/app/router/not_found'
7
7
 
8
8
  def call(env)
9
- response = nil
10
- registered_endpoint_routers.find do |router|
11
- response = router.call(env)
12
- end
13
- return response
9
+ @static.call(env) or @dynamic.call(env) or @not_found.call(env)
14
10
  end
15
11
 
16
12
  def endpoints
17
- registered_endpoint_routers.map(&:endpoints).reduce([],:+)
13
+ [@static, @dynamic, @not_found].map(&:endpoints).reduce([], :+)
18
14
  end
19
15
 
20
16
  def show_endpoints
@@ -63,10 +59,6 @@ class Rack::App::Router
63
59
  @not_found = Rack::App::Router::NotFound.new
64
60
  end
65
61
 
66
- def registered_endpoint_routers
67
- [@static, @dynamic, @not_found]
68
- end
69
-
70
62
  def router_for(request_path)
71
63
  defined_path_is_dynamic?(request_path) ? @dynamic : @static
72
64
  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.__send__(:middlewares).push(*middlewares)
15
+ child.middlewares.push(*middlewares)
16
16
 
17
17
  on_inheritance.each do |block|
18
18
  block.call(self, child)
@@ -10,13 +10,15 @@ 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.instance_exec(mount_prop, &on_mount)
13
+ duplication.class_exec(mount_prop, &on_mount)
14
14
  end
15
15
 
16
+ cli.merge!(duplication.cli)
17
+
16
18
  merge_prop = {:namespaces => [@namespaces, mount_to_path].flatten}
17
19
  router.merge_router!(duplication.router, merge_prop)
18
20
 
19
- return nil
21
+ nil
20
22
  end
21
23
 
22
24
  def mount_directory(directory_path, options={})
@@ -1,5 +1,11 @@
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
+
3
9
  protected
4
10
 
5
11
  def serializer(&definition_how_to_serialize)
@@ -18,16 +24,8 @@ module Rack::App::SingletonMethods::Settings
18
24
  @headers
19
25
  end
20
26
 
21
- def extensions(*extensions)
22
- extensions.each do |ext|
23
- if ext.is_a?(::Class) && ext < (::Rack::App::Extension)
24
-
25
- ext.includes.each { |m| include(m) }
26
- ext.extends.each { |m| extend(m) }
27
- ext.inheritances.each { |block| on_inheritance(&block) }
28
-
29
- end
30
- end
27
+ def extensions(*extension_names)
28
+ Rack::App::Extension.apply_extensions(self,*extension_names)
31
29
  end
32
30
 
33
31
  def error(*exception_classes, &block)
@@ -39,8 +37,6 @@ module Rack::App::SingletonMethods::Settings
39
37
  return @error_handler
40
38
  end
41
39
 
42
- private
43
-
44
40
  def middlewares(&block)
45
41
  @middlewares ||= []
46
42
  @middlewares << block unless block.nil?
@@ -28,8 +28,7 @@ module Rack::App::Test
28
28
  app_class = defined?(__rack_app_class__) ? __rack_app_class__ : nil
29
29
  constructors = []
30
30
  constructors << __rack_app_constructor__ if defined?(__rack_app_constructor__) and __rack_app_constructor__.is_a?(Proc)
31
- constructors << block unless block.nil?
32
- Rack::App::Test::Utils.rack_app_by(app_class, constructors)
31
+ Rack::App::Test::Utils.rack_app_by(app_class, constructors, &block)
33
32
  end
34
33
 
35
34
  end
@@ -10,17 +10,13 @@ module Rack::App::Test::Utils
10
10
  properties
11
11
  end
12
12
 
13
- def rack_app_by(rack_app_class, constructors)
14
- subject_app = nil
15
-
16
- if constructors.empty?
17
- subject_app = rack_app_class
18
- else
19
- subject_app = Class.new(rack_app_class || ::Rack::App)
20
- constructors.each { |constructor| subject_app.class_eval(&constructor) }
21
- end
13
+ def rack_app_by(subject_class, constructors, &block)
14
+
15
+ app_class = subject_class.respond_to?(:call) ? subject_class : Rack::App
16
+ app = Rack::App::Utils.deep_dup(app_class)
17
+ constructors.each { |constructor| app.class_eval(&constructor) }
22
18
 
23
- subject_app
19
+ block.is_a?(Proc) ? app.instance_exec(&block) : app
24
20
  end
25
21
 
26
22
  def env_by(properties)
@@ -20,9 +20,7 @@ module Rack::App::Utils
20
20
  path
21
21
  end
22
22
 
23
- # Based on ActiveSupport, removed inflections.
24
- # https://github.com/rails/rails/blob/v4.1.0.rc1/activesupport/lib/active_support/inflector/methods.rb
25
- def underscore(camel_cased_word)
23
+ def snake_case(camel_cased_word)
26
24
  word = camel_cased_word.to_s.gsub('::', '/')
27
25
  word.gsub!(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2')
28
26
  word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
@@ -31,6 +29,10 @@ module Rack::App::Utils
31
29
  word
32
30
  end
33
31
 
32
+ def camel_case(snake_case)
33
+ snake_case.to_s.split('_').collect(&:capitalize).join
34
+ end
35
+
34
36
  def pwd(*path_parts)
35
37
 
36
38
  root_folder = if ENV['BUNDLE_GEMFILE']
@@ -79,7 +81,7 @@ module Rack::App::Utils
79
81
 
80
82
 
81
83
  def deep_dup(object)
82
- ::Rack::App::Utils::DeepDup.new(object).to_dup
84
+ ::Rack::App::Utils::DeepDup.duplicate(object)
83
85
  end
84
86
 
85
87
  def deep_merge(hash,oth_hash)
@@ -1,90 +1,123 @@
1
- class Rack::App::Utils::DeepDup
1
+ module Rack::App::Utils::DeepDup
2
2
 
3
- def initialize(object)
4
- @object = object
5
- end
3
+ extend self
6
4
 
7
- def to_dup
8
- @register = {}
5
+ def duplicate(object)
6
+ register = {}
9
7
 
10
- dup(@object)
8
+ dup(register, object)
11
9
  end
12
10
 
13
11
  protected
14
12
 
15
- def registration(object, duplicate)
16
- @register[object.object_id]= duplicate
17
- duplicate
13
+ def registered(object, register)
14
+ register[object.object_id]
18
15
  end
19
16
 
20
- def registered(object)
21
- @register[object.object_id]
17
+ def register_duplication(register, object, duplicate)
18
+ register[object.object_id]= duplicate
19
+ duplicate
22
20
  end
23
21
 
24
- def dup(object)
22
+ def dup(register, object)
25
23
 
26
- return registered(object) if registered(object)
24
+ return object unless registrable?(object)
25
+ return registered(object, register) if registered(object, register)
27
26
 
28
27
  case object
29
28
 
30
29
  when Array
31
- dup_array(object)
30
+ dup_array(register, object)
32
31
 
33
32
  when Hash
34
- dup_hash(object)
33
+ dup_hash(register, object)
35
34
 
36
35
  when Range
37
- dup_range(object)
36
+ dup_range(register, object)
38
37
 
39
38
  when Struct
40
- dup_struct(object)
39
+ dup_struct(register, object)
41
40
 
42
- when NilClass, Symbol, Numeric, TrueClass, FalseClass
43
- registration(object, object)
41
+ when NilClass, Symbol, Numeric, TrueClass, FalseClass, Method
42
+ register_duplication(register, object, object)
44
43
 
45
44
  else
46
- dup_object(object)
45
+ dup_object(register, object)
47
46
 
48
47
  end
49
48
  end
50
49
 
51
- def dup_array(object)
52
- duplication = dup_object(object)
53
- duplication.map!{ |e| dup(e) }
50
+ def registrable?(object)
51
+ object.object_id
52
+ true
53
+ rescue NoMethodError
54
+ false
55
+ end
56
+
57
+ def dup_array(register, object)
58
+ duplication = dup_object(register, object)
59
+ duplication.map! { |e| dup(register, e) }
54
60
  end
55
61
 
56
- def dup_hash(object)
57
- duplication = dup_object(object)
58
- object.reduce(duplication) { |hash, (k, v)| hash.merge!(dup(k) => dup(v)) }
62
+ def dup_hash(register, object)
63
+ duplication = dup_object(register, object)
64
+ object.reduce(duplication) { |hash, (k, v)| hash.merge!(dup(register, k) => dup(register, v)) }
59
65
  end
60
66
 
61
- def dup_range(range)
62
- registration(range, range.class.new(dup(range.first), dup(range.last)))
67
+ def dup_range(register, range)
68
+ register_duplication(register, range, range.class.new(dup(register, range.first), dup(register, range.last)))
63
69
  rescue
64
- registration(range, range.dup)
70
+ register_duplication(register, range, range.dup)
65
71
  end
66
72
 
67
- def dup_struct(struct)
68
- duplication = registration(struct, struct.dup)
73
+ def dup_struct(register, struct)
74
+ duplication = register_duplication(register, struct, struct.dup)
69
75
 
70
76
  struct.each_pair do |attr, value|
71
- duplication.__send__("#{attr}=", dup(value))
77
+ duplication.__send__("#{attr}=", dup(register, value))
72
78
  end
73
79
 
74
80
  duplication
75
81
  end
76
82
 
77
- def dup_object(object)
78
- dup_instance_variables(object, registration(object, object.dup))
83
+ def dup_object(register, object)
84
+ dup_instance_variables(register, object, register_duplication(register, object, try_dup(object)))
79
85
  end
80
86
 
81
- def dup_instance_variables(object, duplicate)
87
+ def dup_instance_variables(register, object, duplication)
88
+ return duplication unless respond_to_instance_variables?(object)
89
+
82
90
  object.instance_variables.each do |instance_variable|
83
- value = object.instance_variable_get(instance_variable)
84
- duplicate.instance_variable_set(instance_variable, dup(value))
91
+ value = get_instance_variable(object, instance_variable)
92
+
93
+ set_instance_variable(duplication, instance_variable, dup(register, value))
85
94
  end
86
95
 
87
- return duplicate
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
88
121
  end
89
122
 
90
123
  end
@@ -1,8 +1,4 @@
1
1
  # coding: utf-8
2
- # lib = File.expand_path('../lib', __FILE__)
3
- # $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- # require 'rack/app/version'
5
-
6
2
  Gem::Specification.new do |spec|
7
3
 
8
4
  spec.name = "rack-app"
@@ -16,10 +12,11 @@ Gem::Specification.new do |spec|
16
12
  spec.homepage = 'http://www.rack-app.com/'
17
13
 
18
14
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
- spec.bindir = "exe"
20
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
15
  spec.require_paths = ["lib"]
22
16
 
17
+ spec.bindir = "bin"
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+
23
20
  spec.license = 'Apache License 2.0'
24
21
 
25
22
  spec.add_development_dependency "bundler"
@@ -28,4 +25,4 @@ Gem::Specification.new do |spec|
28
25
 
29
26
  spec.add_dependency "rack"
30
27
 
31
- end
28
+ 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.beta
4
+ version: 3.0.0.delta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-27 00:00:00.000000000 Z
11
+ date: 2016-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,12 +70,14 @@ 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: []
73
+ executables:
74
+ - rack-app
74
75
  extensions: []
75
76
  extra_rdoc_files: []
76
77
  files:
77
78
  - ".gitignore"
78
79
  - ".rspec"
80
+ - ".rubocop.yml"
79
81
  - ".travis.yml"
80
82
  - CODE_OF_CONDUCT.md
81
83
  - CONTRIBUTING.md
@@ -86,7 +88,10 @@ files:
86
88
  - Rakefile
87
89
  - VERSION
88
90
  - Vagrantfile
91
+ - bin/rack-app
89
92
  - lib/rack/app.rb
93
+ - lib/rack/app/cli.rb
94
+ - lib/rack/app/cli/command.rb
90
95
  - lib/rack/app/constants.rb
91
96
  - lib/rack/app/endpoint.rb
92
97
  - lib/rack/app/endpoint/not_found.rb