Class: Origen::CodeGenerators::Model

Inherits:
Base
  • Object
show all
Defined in:
lib/origen/code_generators/model.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

inherited, name, namespace

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



4
5
6
# File 'lib/origen/code_generators/model.rb', line 4

def self.banner
  'origen new model NAME'
end

Instance Method Details

#create_model_fileObject



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

def create_model_file
  @resource_path = args.first
  klass = resource_path_to_class(args.first)
  @namespaces = klass.split('::').map(&:underscore)
  @name = @namespaces.pop
  @namespaces = add_type_to_namespaces(@namespaces)
  @root_class = true
  file = class_name_to_lib_file(klass)
  template 'templates/code_generators/model.rb', file
  if yes? 'Does this model need a controller? (n):'
    file = file.to_s.sub(/\.rb/, '_controller.rb')
    template 'templates/code_generators/controller.rb', file
  end
  add_acronyms
end

#validate_argsObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/origen/code_generators/model.rb', line 32

def validate_args
  if args.size > 1 || args.size == 0
    msg = args.size > 1 ? 'Only one' : 'One'
    msg << " argument is expected by the model generator, e.g. 'origen new model sequencer', 'origen new model bist/sequencer'"
    puts msg
    exit 1
  end

  validate_resource_name(args.first)
end