Module: EffectivePages
- Defined in:
- lib/effective_pages.rb,
lib/effective_pages/engine.rb,
lib/effective_pages/version.rb,
lib/generators/effective_pages/install_generator.rb
Defined Under Namespace
Modules: Generators
Classes: Engine
Constant Summary
collapse
- VERSION =
'2.0.5'.freeze
Class Method Summary
collapse
Class Method Details
.authorize!(controller, action, resource) ⇒ Object
50
51
52
|
# File 'lib/effective_pages.rb', line 50
def self.authorize!(controller, action, resource)
raise Effective::AccessDenied.new('Access Denied', action, resource) unless authorized?(controller, action, resource)
end
|
.authorized?(controller, action, resource) ⇒ Boolean
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/effective_pages.rb', line 37
def self.authorized?(controller, action, resource)
@_exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact
return !!authorization_method unless authorization_method.respond_to?(:call)
controller = controller.controller if controller.respond_to?(:controller)
begin
!!(controller || self).instance_exec((controller || self), action, resource, &authorization_method)
rescue *@_exceptions
false
end
end
|
.layouts ⇒ Object
71
72
73
74
75
76
77
78
79
|
# File 'lib/effective_pages.rb', line 71
def self.layouts
ApplicationController.view_paths.map { |path| Dir["#{path}/layouts/**"] }.flatten.reverse.map do |file|
name = File.basename(file).split('.').first
next if name.starts_with?('_')
next if name.include?('mailer')
next if Array(EffectivePages.excluded_layouts).map { |str| str.to_s }.include?(name)
name
end.compact
end
|
.pages_path=(filepath) ⇒ Object
Remove leading and trailing ‘/’ characters
Will return: "effective/pages"
56
57
58
59
60
|
# File 'lib/effective_pages.rb', line 56
def self.pages_path=(filepath)
filepath = filepath.to_s
filepath = filepath[1..-1] if filepath.starts_with?('/')
@@pages_path = filepath.chomp('/')
end
|
.permitted_params ⇒ Object
81
82
83
|
# File 'lib/effective_pages.rb', line 81
def self.permitted_params
@@permitted_params ||= [:title, :meta_description, :draft, :layout, :template, :slug, roles: []]
end
|
.setup {|_self| ... } ⇒ Object
33
34
35
|
# File 'lib/effective_pages.rb', line 33
def self.setup
yield self
end
|
.templates ⇒ Object
62
63
64
65
66
67
68
69
|
# File 'lib/effective_pages.rb', line 62
def self.templates
ApplicationController.view_paths.map { |path| Dir["#{path}/#{pages_path}/**"] }.flatten.reverse.map do |file|
name = File.basename(file).split('.').first
next if name.starts_with?('_')
next if Array(EffectivePages.excluded_pages).map { |str| str.to_s }.include?(name)
name
end.compact
end
|