Class: Acl9::Dsl::Generators::FilterLambda

Inherits:
BaseGenerator show all
Defined in:
lib/acl9/controller_extensions/generators.rb

Constant Summary

Constants included from Prepositions

Prepositions::VALID_PREPOSITIONS

Instance Attribute Summary

Attributes inherited from Base

#allows, #denys

Instance Method Summary collapse

Methods inherited from Base

#acl_block!, #allowance_expression, #default_action

Methods included from Prepositions

#_by_preposition

Constructor Details

#initialize(subject_method) ⇒ FilterLambda

Returns a new instance of FilterLambda.



56
57
58
59
60
# File 'lib/acl9/controller_extensions/generators.rb', line 56

def initialize(subject_method)
  super

  @controller = 'controller'
end

Instance Method Details

#install_on(controller_class, options) ⇒ Object



62
63
64
65
66
# File 'lib/acl9/controller_extensions/generators.rb', line 62

def install_on(controller_class, options)
  super

  controller_class.send(:before_action, options, &self.to_proc)
end

#to_procObject



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/acl9/controller_extensions/generators.rb', line 68

def to_proc
  code = <<-RUBY
    lambda do |controller|
      unless #{allowance_expression}
        #{_access_denied}
      end
    end
  RUBY

  self.instance_eval(code, __FILE__, __LINE__)
rescue SyntaxError
  raise FilterSyntaxError, code
end