Class: Origen::CodeGenerators::Base

Inherits:
Thor::Group
  • Object
show all
Includes:
Actions, Thor::Actions
Defined in:
lib/origen/code_generators/base.rb

Direct Known Subclasses

Block, Dut, Feature, Klass, Mod, Model, Semver, Timever

Class Method Summary collapse

Methods included from Actions

#add_acronyms, #add_autoload, #add_config, #add_source, #camelcase, #comment_config, #config, #environment, #gem, #gem_group, #generate, #git, #initialize, #lib, #rakefile, #readme, #underscored_app_namespace

Methods included from Actions::Helpers

#add_type_to_namespaces, #class_name_to_blocks_dir, #class_name_to_lib_file, #internal_depth, #resource_path, #resource_path_to_blocks_dir, #resource_path_to_class, #resource_path_to_lib_file, #unless_has_method, #unless_valid_underscored_identifier, #validate_resource_path

Class Method Details



59
60
61
# File 'lib/origen/code_generators/base.rb', line 59

def self.banner
  "origen new #{namespace == 'origen' ? '' : namespace + ':'}#{name} [options]"
end

.inherited(base) ⇒ Object

Cache source root and add lib/generators/base/generator/templates to source paths.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/origen/code_generators/base.rb', line 43

def self.inherited(base) # :nodoc:
  super
  if base.name && base.name !~ /Base$/
    if base.namespace == 'origen'
      Origen::CodeGenerators.origen_generators[base.name] = base
    else
      Origen::CodeGenerators.plugin_generators[base.namespace] ||= {}
      Origen::CodeGenerators.plugin_generators[base.namespace][base.name] = base
    end
  end
  # Give all generators access to Origen core files in their source path,
  # with their own app as highest priority
  base.source_paths << Origen.root if Origen.app_loaded?
  base.source_paths << Origen.top
end

.nameObject

Sets the base_name taking into account the current class namespace.



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/origen/code_generators/base.rb', line 28

def self.name
  @name ||= begin
    name = to_s.split('::').last.sub(/(CodeGenerator|Generator)$/, '').underscore
    if name == 'klass'
      'class'
    elsif name == 'mod'
      'module'
    else
      name
    end
  end
end

.namespace(name = nil) ⇒ Object

Convenience method to get the top-level namespace from the class name. It is returned as a lower cased and underscored string.



16
17
18
19
20
21
22
23
24
25
# File 'lib/origen/code_generators/base.rb', line 16

def self.namespace(name = nil)
  @namespace ||= begin
    names = super.split(':')
    if names.size == 1
      nil
    else
      names.first.sub(/^r_gen/, 'origen')
    end
  end
end