Class: Cog::Seed::Var

Inherits:
Object
  • Object
show all
Includes:
Generator
Defined in:
lib/cog/seed/var.rb

Overview

Template for a variable in a target language

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Generator

#embed, #gcontext, #stamp

Methods included from Generator::LanguageMethods

#end_all_scopes, #include_guard_begin, #named_scope_begin, #scope_begin, #scope_end, #use_named_scope, #warning

Methods included from Generator::Filters

#call_filter, #comment

Methods included from Generator::FileMethods

#copy_file_if_missing, #files_are_same?, #get_template, #touch_directory, #touch_file

Constructor Details

#initialize(type, name, opt = {}) ⇒ Var

Returns a new instance of Var.



19
20
21
22
23
24
# File 'lib/cog/seed/var.rb', line 19

def initialize(type, name, opt={})
  @type = type
  @name = name.to_s.to_ident
  @desc = opt[:desc]
  @scope = opt[:scope]
end

Instance Attribute Details

#descObject (readonly)

Returns the value of attribute desc.



12
13
14
# File 'lib/cog/seed/var.rb', line 12

def desc
  @desc
end

#nameString (readonly)

Returns name of the variable.

Returns:

  • (String)

    name of the variable



10
11
12
# File 'lib/cog/seed/var.rb', line 10

def name
  @name
end

#scopeObject (readonly)

Returns the value of attribute scope.



16
17
18
# File 'lib/cog/seed/var.rb', line 16

def scope
  @scope
end

#typeObject (readonly)

Returns the value of attribute type.



14
15
16
# File 'lib/cog/seed/var.rb', line 14

def type
  @type
end

Instance Method Details

#<=>(other) ⇒ Object

Sort by name



37
38
39
# File 'lib/cog/seed/var.rb', line 37

def <=>(other)
  @name <=> other
end

#qualify?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/cog/seed/var.rb', line 26

def qualify?
  @qualify
end

#stamp_decl(qualify = false) ⇒ Object



30
31
32
33
34
# File 'lib/cog/seed/var.rb', line 30

def stamp_decl(qualify = false)
  l = Cog.active_language
  @qualify = qualify && @scope
  stamp "cog/#{l.key}/var_decl.#{l.seed_extension}"
end