lucie-lib 0.0.15 → 0.0.16

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: 22fd96396292ce33f05a97f2f226a6c89ca3425a
4
- data.tar.gz: 92bdeb9d7ec61ed9b381f2b67602427cac7945dc
3
+ metadata.gz: 6f509d04638ba165b1e444061f66d60870e6936c
4
+ data.tar.gz: 261d15e0851a26c5449972fd075ee754b7fd28e8
5
5
  SHA512:
6
- metadata.gz: e126cfc3b93fcd8ac4ac875b5ad936475aaec2900d69dd93f14206988f705ac8de7f139cf3b9db9e87aaa30ad523d5511300480aa24fda552ad98a234852a11a
7
- data.tar.gz: 4788f1a3742bae56bf44450606a3d0274aa285f81c856480d9b90cc34a021b994b4e4aa48fb894000dfffcc1e87b57b05e3aafb1d3377923f203d35b097c36a6
6
+ metadata.gz: fc15a34df4977c1f297f8f1b823253593286c65d1ea267f4a314236d4641b59afebd5ececc829f0fe7f57f1cd27ebcb858506241329a338c1632b6725ec01728
7
+ data.tar.gz: 0c5087237ad1a707e766c435d98985082fff2019de84dabc2bf21509cf5dfbf44e59e3cdb787a193ff7b4213eb2f3fb8fbe36ce9c1974fd2a64f588bdca5ced8
data/lib/lucie/app.rb CHANGED
@@ -58,6 +58,7 @@ module Lucie
58
58
  private
59
59
 
60
60
  def call_method_invoking_process
61
+ autoload_controllers
61
62
  apply_validators
62
63
  pair_parameters
63
64
  call_action_on_controller
@@ -87,25 +88,38 @@ private
87
88
  end
88
89
 
89
90
  def controller_class
90
- if task
91
- @controller_class ||= [task.split("_").map{|i| i.capitalize}.join, "Controller"].join
92
- Object.const_get(@controller_class.to_sym)
93
- else
94
- include_controller_for "application"
95
- @controller_class = "ApplicationController"
96
- @action = :help
97
- Object.const_get(@controller_class.to_sym)
91
+ controller_class = begin
92
+ if task
93
+ [task.split("_").map{|i| i.capitalize}.join, "Controller"].join
94
+ else
95
+ @action = :help
96
+ "ApplicationController"
97
+ end
98
+ end
99
+
100
+ begin
101
+ Object.const_get(controller_class.to_sym)
102
+ rescue NameError
103
+ self.exit_value = 255
104
+ raise ControllerNotFound.new task
98
105
  end
99
- rescue NameError
100
- include_controller_for(task)
101
- Object.const_get(@controller_class.to_sym)
102
106
  end
103
107
 
104
- def include_controller_for(task)
105
- require File.join([root, "app/controllers", "#{task}_controller"])
106
- rescue LoadError
107
- self.exit_value = 255
108
- raise ControllerNotFound, task
108
+ def autoload_controllers
109
+ base_path = File.join([root, "app/controllers"])
110
+ $LOAD_PATH << base_path
111
+ Dir.glob(File.join([base_path, "*_controller.rb"])).each do |path|
112
+ filename = File.basename(path)
113
+ controller_name = filename.split(".rb").first
114
+ if controller_name.to_s.length > 0
115
+ const_name = controller_name.split("_").map!{|x| x.capitalize!}.join
116
+
117
+ # place the constant to the root namespace
118
+ Object.class_eval do
119
+ autoload const_name.to_sym, controller_name
120
+ end
121
+ end
122
+ end
109
123
  end
110
124
 
111
125
  def call_action_on_controller
@@ -72,14 +72,8 @@ module Lucie
72
72
 
73
73
  def apply_action(action)
74
74
  if has_action? action
75
-
76
75
  self.apply_before_filters
77
-
78
- begin
79
- return self.send(action)
80
- rescue NameError
81
- raise ActionNotFound.new(action, nil)
82
- end
76
+ return self.send(action)
83
77
  else
84
78
  raise ActionNotFound.new(action, nil)
85
79
  end
data/lib/lucie/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lucie
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require "test_helper"
2
2
  require "stringio"
3
- require "helpers/test_app"
3
+ require "fixtures/test_app"
4
4
  require "fixtures/command_parser_fixtures"
5
5
 
6
6
  describe App do
@@ -111,4 +111,14 @@ describe App do
111
111
  should "store the ENV" do
112
112
  assert_equal ENV["PWD"], TestApp.init([], "").env["PWD"]
113
113
  end
114
+
115
+ should "find other controllers as well in controllers directory without require statement" do
116
+ if defined?(FakeController)
117
+ Object.send(:remove_const, :FakeController)
118
+ end
119
+
120
+ assert_output "ok", "" do
121
+ TestApp.run "inheritance index", File.expand_path("../../test_app/", __FILE__)
122
+ end
123
+ end
114
124
  end
@@ -0,0 +1,2 @@
1
+ class FakeController < Controller::Base
2
+ end
@@ -0,0 +1,5 @@
1
+ class InheritanceController < FakeController
2
+ def index
3
+ print "ok"
4
+ end
5
+ end
data/test/test_helper.rb CHANGED
@@ -12,6 +12,7 @@ require "pathname"
12
12
 
13
13
  require File.expand_path('../../lib/lucie.rb', __FILE__)
14
14
  $LOAD_PATH << File.expand_path('../helpers', __FILE__)
15
+ $LOAD_PATH << File.expand_path('../fixtures', __FILE__)
15
16
 
16
17
  LUCIE_ROOT = File.expand_path File.dirname(__FILE__)
17
18
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lucie-lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.15
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nucc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-30 00:00:00.000000000 Z
11
+ date: 2013-12-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -88,13 +88,15 @@ files:
88
88
  - lib/lucie/validators/optional.rb
89
89
  - lib/lucie/version.rb
90
90
  - lucie-lib.gemspec
91
+ - test/fixtures/before_filter_controller.rb
91
92
  - test/fixtures/command_parser_fixtures.rb
92
93
  - test/fixtures/template_snippet_fixtures.rb
94
+ - test/fixtures/test_app.rb
93
95
  - test/functional/app_test.rb
94
96
  - test/functional/template_snippet_test.rb
95
- - test/helpers/before_filter_controller.rb
96
- - test/helpers/test_app.rb
97
97
  - test/test_app/app/controllers/application_controller.rb
98
+ - test/test_app/app/controllers/fake_controller.rb
99
+ - test/test_app/app/controllers/inheritance_controller.rb
98
100
  - test/test_helper.rb
99
101
  - test/unit/command_line_parser_test.rb
100
102
  - test/unit/command_line_slicer_test.rb
@@ -124,13 +126,15 @@ specification_version: 4
124
126
  summary: Library part of Lucie framework. Use only this gem, if you don't need project
125
127
  generator.
126
128
  test_files:
129
+ - test/fixtures/before_filter_controller.rb
127
130
  - test/fixtures/command_parser_fixtures.rb
128
131
  - test/fixtures/template_snippet_fixtures.rb
132
+ - test/fixtures/test_app.rb
129
133
  - test/functional/app_test.rb
130
134
  - test/functional/template_snippet_test.rb
131
- - test/helpers/before_filter_controller.rb
132
- - test/helpers/test_app.rb
133
135
  - test/test_app/app/controllers/application_controller.rb
136
+ - test/test_app/app/controllers/fake_controller.rb
137
+ - test/test_app/app/controllers/inheritance_controller.rb
134
138
  - test/test_helper.rb
135
139
  - test/unit/command_line_parser_test.rb
136
140
  - test/unit/command_line_slicer_test.rb
File without changes