Class: Cog::Seed::Feature

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

Overview

Template for a method 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(seed, name, opt = {}) ⇒ Feature

Returns a new instance of Feature.

Parameters:

  • seed (Seed)

    seed to which this feature belongs

  • name (String)

    name of the feature

  • opt (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opt):

  • :access (Symbol) — default: :private

    one of ‘:public`, `:protected`, or `private`

  • :abstract (Boolean) — default: false

    is this an abstract feature? If so, no implementation will be generated. Note that all abstract features are virtual

  • :virtual (Boolean) — default: false

    is this a virtual feature? Virtual features can be replaced in subclasses



31
32
33
34
35
36
37
38
39
# File 'lib/cog/seed/feature.rb', line 31

def initialize(seed, name, opt={})
  @seed = seed
  @name = name.to_s.to_ident
  @access = (opt[:access] || :private).to_sym
  @abstract = !!opt[:abstract]
  @virtual = !!opt[:virtual]
  @params = [] # [Var]
  @return_type = :void
end

Instance Attribute Details

#accessSymbol (readonly)

Returns access modifier. One of ‘:public`, `:protected`, or `:private`.

Returns:

  • (Symbol)

    access modifier. One of ‘:public`, `:protected`, or `:private`



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

def access
  @access
end

#nameString (readonly)

Returns name of the method.

Returns:

  • (String)

    name of the method



17
18
19
# File 'lib/cog/seed/feature.rb', line 17

def name
  @name
end

#paramsArray<Var> (readonly)

Returns list of parameters.

Returns:



20
21
22
# File 'lib/cog/seed/feature.rb', line 20

def params
  @params
end

#return_typeSymbol (readonly)

Returns the return type of the feature.

Returns:

  • (Symbol)

    the return type of the feature



23
24
25
# File 'lib/cog/seed/feature.rb', line 23

def return_type
  @return_type
end

#seedSeed (readonly)

Returns seed to which this feature belongs.

Returns:

  • (Seed)

    seed to which this feature belongs



11
12
13
# File 'lib/cog/seed/feature.rb', line 11

def seed
  @seed
end

Instance Method Details

#<=>(other) ⇒ Object

Sort by name



71
72
73
# File 'lib/cog/seed/feature.rb', line 71

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

#abstract?Boolean

Returns is this an abstract method?.

Returns:

  • (Boolean)

    is this an abstract method?



42
43
44
# File 'lib/cog/seed/feature.rb', line 42

def abstract?
  @abstract
end

#descObject



56
57
58
# File 'lib/cog/seed/feature.rb', line 56

def desc
  @desc || 'Undocumented'
end

#keep_nameObject



60
61
62
# File 'lib/cog/seed/feature.rb', line 60

def keep_name
  "#{@seed.name}_#{@name}"
end

#returns_a_value?Boolean

Returns does this feature return a value?.

Returns:

  • (Boolean)

    does this feature return a value?



52
53
54
# File 'lib/cog/seed/feature.rb', line 52

def returns_a_value?
  @return_type != :void
end

#stamp_methodObject



64
65
66
67
68
# File 'lib/cog/seed/feature.rb', line 64

def stamp_method
  l = Cog.active_language
  ext = @seed.in_header? ? l.seed_header : l.seed_extension
  stamp "cog/#{l.key}/feature.#{ext}"
end

#virtual?Boolean

Returns is this a virtual method?.

Returns:

  • (Boolean)

    is this a virtual method?



47
48
49
# File 'lib/cog/seed/feature.rb', line 47

def virtual?
  @abstract || @virtual
end