module Cog::Generator::LanguageMethods

Methods to help with generating language constructs

Public Instance Methods

end_all_scopes() click to toggle source

End all scope currently on the stack @return [String]

# 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) click to toggle source

@param name [String] name of the module @return [String] an include guard statement for the active language

# File lib/cog/generator/language_methods.rb, line 60
def include_guard_begin(name = nil)
  scope_begin Scope.new(:include_guard, name)
end
include_guard_end(opt={})
Alias for: scope_end
named_scope_begin(name = nil) click to toggle source

@param name [String] name of the scope @return [String] a scope begin statement

# File lib/cog/generator/language_methods.rb, line 52
def named_scope_begin(name = nil)
  scope_begin Scope.new(:named_scope, name)
end
named_scope_end(opt={})
Alias for: scope_end
scope_begin(scope) click to toggle source

Begin a scope, pushing it onto the scope stack @param scope [Scope] the scope to begin @return [String] the scope begin statement

# 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={}) click to toggle source

End the scope, popping it off the scope stack @option opt [Boolean] :safe_pop (false) do not throw an exception if the stack is empty, instead, return nil @return [String, nil] the scope end statement, or nil if :safe_pop and the stack is empty

# 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) click to toggle source

@param name [String] name of the scope to use @return [String] a using statement for the named scope

# File lib/cog/generator/language_methods.rb, line 46
def use_named_scope(name)
  Cog.active_language.use_named_scope(name)
end
warning() click to toggle source

@return [String] a warning comment not to edit the generated file

# File lib/cog/generator/language_methods.rb, line 10
def warning
  stamp 'warning', :filter => 'comment'
end