Module: Cog::Generator::LanguageMethods

Included in:
Cog::Generator
Defined in:
lib/cog/generator/language_methods.rb,
lib/cog/generator/language_methods/scope.rb

Overview

Methods to help with generating language constructs

Defined Under Namespace

Classes: Scope

Instance Method Summary collapse

Instance Method Details

#end_all_scopesString

End all scope currently on the stack



36
37
38
39
40
41
42
# File 'lib/cog/generator/language_methods.rb', line 36

def end_all_scopes
  lines = []
  while line = scope_end(:safe_pop => true)
    lines << line
  end
  lines.join "\n"
end

#include_guard_begin(name = nil) ⇒ String



60
61
62
# File 'lib/cog/generator/language_methods.rb', line 60

def include_guard_begin(name = nil)
  scope_begin Scope.new(:include_guard, name)
end

#named_scope_begin(name = nil) ⇒ String



52
53
54
# File 'lib/cog/generator/language_methods.rb', line 52

def named_scope_begin(name = nil)
  scope_begin Scope.new(:named_scope, name)
end

#scope_begin(scope) ⇒ String

Begin a scope, pushing it onto the scope stack



17
18
19
20
# File 'lib/cog/generator/language_methods.rb', line 17

def scope_begin(scope)
  gcontext[:scopes] << scope
  Cog.active_language.method("#{scope.type}_begin").call(scope.name)
end

#scope_end(opt = {}) ⇒ String? Also known as: named_scope_end, include_guard_end

End the scope, popping it off the scope stack

Options Hash (opt):

  • :safe_pop (Boolean) — default: false

    do not throw an exception if the stack is empty, instead, return nil



25
26
27
28
29
30
31
32
# File 'lib/cog/generator/language_methods.rb', line 25

def scope_end(opt={})
  if gcontext[:scopes].empty?
    raise Errors::ScopeStackUnderflow.new(self) unless opt[:safe_pop]
    return nil
  end
  scope = gcontext[:scopes].pop
  Cog.active_language.method("#{scope.type}_end").call(scope.name)
end

#use_named_scope(name) ⇒ String



46
47
48
# File 'lib/cog/generator/language_methods.rb', line 46

def use_named_scope(name)
  Cog.active_language.use_named_scope(name)
end

#warningString



10
11
12
# File 'lib/cog/generator/language_methods.rb', line 10

def warning
  stamp 'warning', :filter => 'comment'
end