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
-
#end_all_scopes ⇒ String
End all scope currently on the stack.
-
#include_guard_begin(name = nil) ⇒ String
An include guard statement for the active language.
-
#named_scope_begin(name = nil) ⇒ String
A scope begin statement.
-
#scope_begin(scope) ⇒ String
Begin a scope, pushing it onto the scope stack.
-
#scope_end(opt = {}) ⇒ String?
(also: #named_scope_end, #include_guard_end)
End the scope, popping it off the scope stack.
-
#use_named_scope(name) ⇒ String
A using statement for the named scope.
-
#warning ⇒ String
A warning comment not to edit the generated file.
Instance Method Details
#end_all_scopes ⇒ String
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
Returns an include guard statement for the active language.
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
Returns a scope begin statement.
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
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
Returns a using statement for the named scope.
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 |
#warning ⇒ String
Returns a warning comment not to edit the generated file.
10 11 12 |
# File 'lib/cog/generator/language_methods.rb', line 10 def warning stamp 'warning', :filter => 'comment' end |