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.



59
60
61
62
63
# File 'lib/acl9/controller_extensions/generators.rb', line 59

def initialize(subject_method)
  super

  @controller = 'controller'
end

Instance Method Details

#install_on(controller_class, options) ⇒ Object



65
66
67
68
69
# File 'lib/acl9/controller_extensions/generators.rb', line 65

def install_on(controller_class, options)
  super

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

#to_procObject



71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/acl9/controller_extensions/generators.rb', line 71

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