lucie-lib 0.0.14 → 0.0.15

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: a736c31b498e6c4051e20b80f7c66a9081f5c327
4
- data.tar.gz: 49e0ee62ac880ca1373821663285f7de6890106c
3
+ metadata.gz: 22fd96396292ce33f05a97f2f226a6c89ca3425a
4
+ data.tar.gz: 92bdeb9d7ec61ed9b381f2b67602427cac7945dc
5
5
  SHA512:
6
- metadata.gz: c4d686941affd4a5e8af762a5880f72197c9f948a5c7ba63ffb329c3aaa94a81fa14666325dba17bbf467ae6556dca60a9ea51854404e636d230c1d987184530
7
- data.tar.gz: 5b55550a159a5a5db88b8b58893ea09ef0cfd9075210fd2ec27f43703d812f164609201ee1b0a5aa0544c5b11a6e9bfe256e7e27c618f5972fb91afc0a28d24b
6
+ metadata.gz: e126cfc3b93fcd8ac4ac875b5ad936475aaec2900d69dd93f14206988f705ac8de7f139cf3b9db9e87aaa30ad523d5511300480aa24fda552ad98a234852a11a
7
+ data.tar.gz: 4788f1a3742bae56bf44450606a3d0274aa285f81c856480d9b90cc34a021b994b4e4aa48fb894000dfffcc1e87b57b05e3aafb1d3377923f203d35b097c36a6
data/lib/lucie/app.rb CHANGED
@@ -109,26 +109,16 @@ private
109
109
  end
110
110
 
111
111
  def call_action_on_controller
112
- method = action
113
- if controller_has_action? action
114
- # pop the args[0] element because this is the method
115
- @command.shift
116
- elsif controller_has_action? :no_method
117
- method = :no_method
118
- else
119
- self.exit_value = 255
120
- raise ActionNotFound.new(action, task)
121
- end
122
- self.exit_value = controller.send(method)
123
- rescue Controller::ExitRequest => exit_request
124
- self.exit_value = exit_request.code
125
- end
112
+ begin
113
+ self.exit_value = controller.send(:apply_action, action)
126
114
 
127
- def controller_has_action?(action)
128
- @public_actions ||= begin
129
- controller_class.public_instance_methods - Controller::Base.public_instance_methods + [:help]
115
+ # pop the args[0] element because this is the method
116
+ command.shift
117
+ rescue ActionNotFound
118
+ self.exit_value = controller.send(:apply_action, :no_method)
130
119
  end
131
- @public_actions.include?(action.to_sym)
120
+ rescue ActionNotFound
121
+ raise ActionNotFound.new(action, task)
132
122
  end
133
123
 
134
124
  def apply_validators
@@ -10,6 +10,13 @@ module Lucie
10
10
  class << self
11
11
  @validators = []
12
12
  @params = CommandLineParser.new("")
13
+ protected
14
+ @before_filter_args = []
15
+ attr_accessor :before_filter_args
16
+ end
17
+
18
+ def help
19
+ "Help"
13
20
  end
14
21
 
15
22
  def initialize(command_line_parser, app)
@@ -17,14 +24,17 @@ module Lucie
17
24
  @app = app
18
25
  end
19
26
 
20
- def self.params=(params)
21
- @params = params
22
- end
27
+ protected
23
28
 
24
29
  def params
25
30
  self.class.params
26
31
  end
27
32
 
33
+ def self.params=(params)
34
+ @params = params
35
+ end
36
+
37
+
28
38
  def self.params
29
39
  @params
30
40
  end
@@ -49,14 +59,51 @@ module Lucie
49
59
  validators.each {|validator| validator.apply(params) } if validators
50
60
  end
51
61
 
62
+ def self.before_filter(*args)
63
+ self.before_filter_args ||= []
64
+ args.each do |value|
65
+ self.before_filter_args << value
66
+ end
67
+ end
68
+
52
69
  def exit(value)
53
70
  raise ExitRequest, value
54
71
  end
55
72
 
56
- def help
57
- "Help"
73
+ def apply_action(action)
74
+ if has_action? action
75
+
76
+ self.apply_before_filters
77
+
78
+ begin
79
+ return self.send(action)
80
+ rescue NameError
81
+ raise ActionNotFound.new(action, nil)
82
+ end
83
+ else
84
+ raise ActionNotFound.new(action, nil)
85
+ end
86
+ rescue Controller::ExitRequest => exit_request
87
+ return exit_request.code
58
88
  end
59
89
 
90
+ def apply_before_filters
91
+ klass = self.class
92
+ while klass.respond_to?(:before_filter)
93
+ args = Array(klass.send(:before_filter_args))
94
+ args.each do |method|
95
+ self.send(method.to_sym)
96
+ end
97
+ klass = klass.superclass
98
+ end
99
+ end
100
+
101
+ def has_action?(action)
102
+ @public_actions ||= begin
103
+ self.class.public_instance_methods - Object.public_instance_methods
104
+ end
105
+ @public_actions.include?(action.to_sym)
106
+ end
60
107
  end
61
108
  end
62
109
  end
data/lib/lucie/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lucie
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  end
@@ -0,0 +1,35 @@
1
+ class BeforeFilterController < Controller::Base
2
+ before_filter :set_touched
3
+ attr_reader :touched
4
+
5
+ def set_touched
6
+ @touched = true
7
+ end
8
+
9
+ def method1
10
+ end
11
+ end
12
+
13
+ class BeforeFilterRecursionController < BeforeFilterController
14
+ def method2
15
+ end
16
+ end
17
+
18
+ class MultipleBeforeFilters < Controller::Base
19
+ before_filter :set_one, :set_two
20
+
21
+ def method3
22
+ end
23
+
24
+ attr_reader :one, :two
25
+
26
+ protected
27
+
28
+ def set_one
29
+ @one = true
30
+ end
31
+
32
+ def set_two
33
+ @two = true
34
+ end
35
+ end
data/test/test_helper.rb CHANGED
@@ -11,7 +11,7 @@ require "pathname"
11
11
  #require 'debugger'
12
12
 
13
13
  require File.expand_path('../../lib/lucie.rb', __FILE__)
14
-
14
+ $LOAD_PATH << File.expand_path('../helpers', __FILE__)
15
15
 
16
16
  LUCIE_ROOT = File.expand_path File.dirname(__FILE__)
17
17
 
@@ -10,4 +10,29 @@ class ControllerBaseTest < MiniTest::Unit::TestCase
10
10
  assert_equal app, controller.app
11
11
  end
12
12
 
13
+ def test_before_filter
14
+ require "before_filter_controller"
15
+
16
+ controller = BeforeFilterController.new(nil, Object.new)
17
+ controller.send(:apply_action, :method1)
18
+ assert_equal true, controller.touched
19
+ end
20
+
21
+ def test_before_filter_recursion
22
+ require "before_filter_controller"
23
+
24
+ controller = BeforeFilterRecursionController.new(nil, Object.new)
25
+ controller.send(:apply_action, :method2)
26
+ assert_equal true, controller.touched
27
+ end
28
+
29
+ def test_multiple_before_filters
30
+ require "before_filter_controller"
31
+
32
+ controller = MultipleBeforeFilters.new(nil, Object.new)
33
+ controller.send(:apply_action, :method3)
34
+ assert_equal true, controller.one
35
+ assert_equal true, controller.two
36
+ end
37
+
13
38
  end
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.14
4
+ version: 0.0.15
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-17 00:00:00.000000000 Z
11
+ date: 2013-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -92,6 +92,7 @@ files:
92
92
  - test/fixtures/template_snippet_fixtures.rb
93
93
  - test/functional/app_test.rb
94
94
  - test/functional/template_snippet_test.rb
95
+ - test/helpers/before_filter_controller.rb
95
96
  - test/helpers/test_app.rb
96
97
  - test/test_app/app/controllers/application_controller.rb
97
98
  - test/test_helper.rb
@@ -127,6 +128,7 @@ test_files:
127
128
  - test/fixtures/template_snippet_fixtures.rb
128
129
  - test/functional/app_test.rb
129
130
  - test/functional/template_snippet_test.rb
131
+ - test/helpers/before_filter_controller.rb
130
132
  - test/helpers/test_app.rb
131
133
  - test/test_app/app/controllers/application_controller.rb
132
134
  - test/test_helper.rb