Class: ActiveSupport::CodeGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/active_support/code_generator.rb

Overview

:nodoc:

Defined Under Namespace

Classes: MethodSet

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(owner, path, line) ⇒ CodeGenerator

Returns a new instance of CodeGenerator.



53
54
55
56
57
58
# File 'lib/active_support/code_generator.rb', line 53

def initialize(owner, path, line)
  @owner = owner
  @path = path
  @line = line
  @namespaces = Hash.new { |h, k| h[k] = MethodSet.new(k) }
end

Class Method Details

.batch(owner, path, line) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/active_support/code_generator.rb', line 41

def batch(owner, path, line)
  if owner.is_a?(CodeGenerator)
    yield owner
  else
    instance = new(owner, path, line)
    result = yield instance
    instance.execute
    result
  end
end

Instance Method Details

#define_cached_method(canonical_name, namespace:, as: nil, &block) ⇒ Object



60
61
62
# File 'lib/active_support/code_generator.rb', line 60

def define_cached_method(canonical_name, namespace:, as: nil, &block)
  @namespaces[namespace].define_cached_method(canonical_name, as: as, &block)
end

#executeObject



64
65
66
67
68
# File 'lib/active_support/code_generator.rb', line 64

def execute
  @namespaces.each_value do |method_set|
    method_set.apply(@owner, @path, @line - 1)
  end
end