Class: Copyable::DeclarationChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/copyable/syntax_checking/declaration_checker.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/copyable/syntax_checking/declaration_checker.rb', line 16

def method_missing(method_name, *args, &block)
  method = method_name.to_s
  if Copyable::Declarations.include?(method)
    @declarations_that_were_called << method
  else
    raise DeclarationError.new("Unknown declaration '#{method}' in copyable.")
  end
end

Instance Method Details

#verify!(declaration_block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/copyable/syntax_checking/declaration_checker.rb', line 4

def verify!(declaration_block)
  @declarations_that_were_called = []
  self.instance_eval(&declaration_block)

  Copyable::Declarations::ALL.each do |declaration|
    if declaration.required? && !@declarations_that_were_called.include?(declaration.method_name)
      message = "The copyable declaration must include #{declaration.name}."
      raise DeclarationError.new(message)
    end
  end
end