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

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

Constant Summary

Constants inherited from Base

Base::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

Constructor Details

#initialize(subject_method) ⇒ FilterLambda

Returns a new instance of FilterLambda.



87
88
89
90
91
# File 'lib/acl9/controller_extensions/generators.rb', line 87

def initialize(subject_method)
  super

  @controller = 'controller'
end

Instance Method Details

#install_on(controller_class, options) ⇒ Object



93
94
95
96
97
# File 'lib/acl9/controller_extensions/generators.rb', line 93

def install_on(controller_class, options)
  super

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

#to_procObject



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/acl9/controller_extensions/generators.rb', line 99

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