red_light 0.0.8 → 0.0.9

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.
@@ -2,9 +2,8 @@
2
2
 
3
3
  module RedLight
4
4
  class FancyLogin
5
- def initialize(app, rules)
5
+ def initialize(app)
6
6
  @app = app
7
- @rules = rules
8
7
  end
9
8
 
10
9
  def call(env)
@@ -14,6 +13,8 @@ module RedLight
14
13
  def _call(env)
15
14
  @status, @headers, @response = @app.call(env)
16
15
 
16
+ return [@status, @headers, @response] if rules.empty?
17
+
17
18
  empty_response = (@response.is_a?(Array) && @response.size <= 1) ||
18
19
  !@response.respond_to?(:body) ||
19
20
  !@response.body.respond_to?(:empty?) ||
@@ -31,7 +32,7 @@ module RedLight
31
32
  controller = path[:controller]
32
33
  action = path[:action]
33
34
 
34
- if @rules[controller] && @rules[controller].include?(action)
35
+ if rules[controller] && rules[controller].include?(action)
35
36
  part.gsub!(/action="#{form_action}"/, "action='javascript:void(0);' rel='fancy_login'")
36
37
  end
37
38
  rescue ActionController::RoutingError => e
@@ -46,7 +47,7 @@ module RedLight
46
47
  controller = path[:controller]
47
48
  action = path[:action]
48
49
 
49
- if @rules[controller] && @rules[controller].include?(action)
50
+ if rules[controller] && rules[controller].include?(action)
50
51
  href_regex = Regexp.compile(Regexp.escape('href="/'+href+'"'))
51
52
  part.gsub!(href_regex, "href='/#{href}' rel='fancy_login'")
52
53
  end
@@ -59,5 +60,36 @@ module RedLight
59
60
 
60
61
  [@status, @headers, response_body]
61
62
  end
63
+
64
+ private
65
+ def rules
66
+ return @rules if @rules
67
+
68
+ @rules = Hash.new([])
69
+
70
+ Dir.glob("app/controllers/**/*_controller.rb").map do |entry|
71
+ controller = File.basename(entry, ".rb").classify.constantize
72
+
73
+ filter = controller._process_action_callbacks.select{ |callback|
74
+ callback.filter == :authenticate_user!
75
+ }.first
76
+
77
+ next if filter.nil?
78
+
79
+ controller_name = controller.to_s.underscore.split("_controller").first
80
+ @rules[controller_name] = Array(controller.action_methods)
81
+
82
+ options = filter.options
83
+ if options[:only].present? && Array(options[:only]).any?
84
+ @rules[controller_name] = Array(options[:only]).map(&:to_s)
85
+ end
86
+
87
+ if options[:except].present? && Array(options[:except]).any?
88
+ @rules[controller_name] -= Array(options[:except]).map(&:to_s)
89
+ end
90
+ end
91
+
92
+ @rules
93
+ end
62
94
  end
63
95
  end
@@ -3,31 +3,7 @@ require 'red_light/fancy_login'
3
3
  module RedLight
4
4
  class Railtie < Rails::Railtie
5
5
  initializer "red_light.configure_rails_initialization" do |app|
6
- rules = Hash.new([])
7
-
8
- Dir.glob("app/controllers/**/*_controller.rb").map do |entry|
9
- controller = File.basename(entry, ".rb").classify.constantize
10
-
11
- filter = controller._process_action_callbacks.select{ |callback|
12
- callback.filter == :authenticate_user!
13
- }.first
14
-
15
- next if filter.nil?
16
-
17
- controller_name = controller.to_s.underscore.split("_controller").first
18
- rules[controller_name] = Array(controller.action_methods)
19
-
20
- options = filter.options
21
- if options[:only].present? && Array(options[:only]).any?
22
- rules[controller_name] = Array(options[:only]).map(&:to_s)
23
- end
24
-
25
- if options[:except].present? && Array(options[:except]).any?
26
- rules[controller_name] -= Array(options[:except]).map(&:to_s)
27
- end
28
- end
29
-
30
- app.middleware.use RedLight::FancyLogin, rules
6
+ app.middleware.use RedLight::FancyLogin
31
7
  end
32
8
  end
33
9
  end
@@ -1,3 +1,3 @@
1
1
  module RedLight
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: red_light
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-05-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
- requirement: &70290583428500 !ruby/object:Gem::Requirement
16
+ requirement: &70212116389180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.3'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70290583428500
24
+ version_requirements: *70212116389180
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70290583425000 !ruby/object:Gem::Requirement
27
+ requirement: &70212116385820 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70290583425000
35
+ version_requirements: *70212116385820
36
36
  description: a gem used to add fancy login to your rails application
37
37
  email:
38
38
  - leomayleomay@gmail.com