Class: CheapCoder::Authorizer

Inherits:
Object
  • Object
show all
Includes:
AST::Processor::Mixin
Defined in:
lib/cheap_coder/authorizer.rb

Instance Method Summary collapse

Constructor Details

#initialize(allowed_methods) ⇒ Authorizer

Returns a new instance of Authorizer.



7
8
9
# File 'lib/cheap_coder/authorizer.rb', line 7

def initialize(allowed_methods)
  @allowed_methods = allowed_methods || []
end

Instance Method Details

#allow?(node) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
# File 'lib/cheap_coder/authorizer.rb', line 11

def allow?(node)
  raise ArgumentError, "not SEND node: #{node}" unless node.type == :send

  receiver, method = node.to_a
  return false unless receiver.nil?

  @allowed_methods.include?(method)
end

#handler_missing(node) ⇒ Object



26
27
28
# File 'lib/cheap_coder/authorizer.rb', line 26

def handler_missing(node)
  default_handler(node)
end

#on_def(node) ⇒ Object



20
21
22
23
24
# File 'lib/cheap_coder/authorizer.rb', line 20

def on_def(node)
  print_debug('DEF', node)
  @allowed_methods.push(node.to_a[0])
  default_handler(node)
end