Class: OrigenAppGenerators::Base

Inherits:
Origen::CodeGenerators::Base
  • Object
show all
Includes:
Origen::Utility::InputCapture
Defined in:
lib/origen_app_generators/base.rb

Overview

This is the base generator used by all generators in this application

Direct Known Subclasses

Application, New

Instance Method Summary collapse

Instance Method Details

#get_common_user_inputObject



61
62
63
64
65
# File 'lib/origen_app_generators/base.rb', line 61

def get_common_user_input
  # Don't bother asking the user for this, their life will be easier if they just go with
  # Origen's default namespace based on their app's name
  @namespace = @name.to_s.camelize
end

#get_lastest_origen_versionObject



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/origen_app_generators/base.rb', line 67

def get_lastest_origen_version
  @latest_origen_version ||= begin
    (Gems.info 'origen')['version']
  rescue
    # If the above fails, e.g. due to an SSL error in the runtime environment, try to fetch the
    # latest Origen version from the Origen website, before finally falling back to the version
    # we are currently running if all else fails
    begin
      require 'httparty'
      response = HTTParty.get('http://origen-sdk.org/origen/release_notes/')
      version = Origen::VersionString.new(response.body.match(/Tag: v(\d+\.\d+.\d+)</).to_a.last)
      if version.valid?
        version
      else
        fail "Can't get the latest version!"
      end
    rescue
      Origen.version
    end
  end
end

#set_source_pathsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/origen_app_generators/base.rb', line 23

def set_source_paths
  # The base Origen generator puts the Origen core directory on the source path, in retrospect this
  # was a bad idea and makes for hard to debug errors if an app generator resolves a template from
  # outside of this app.
  # So to keep things sane remove any inherited source paths.
  self.class.source_paths.pop until self.class.source_paths.empty?
  klass = self.class

  until klass == OrigenAppGenerators::Base
    if template_dir = OrigenAppGenerators.template_dirs[klass]
      dir = []
      last_class = nil
      until klass.to_s =~ /^OrigenAppGenerators/
        dir << "#{template_dir}/#{class_dir(klass)}"
        last_class = klass
        klass = klass.superclass
      end
      dir << "#{template_dir}/base"
      klass = last_class
    else
      dir = []
      class_dirs(klass).each do |class_dir|
        dir << "#{Origen.root!}/templates/app_generators/#{class_dir}"
        dir << "#{Origen.root!}/app/templates/app_generators/#{class_dir}"
      end
    end
    Array(dir).each do |dir|
      self.class.source_paths << dir if File.exist?(dir) && !self.class.source_paths.include?(dir)
    end
    klass = klass.superclass
  end
end

#set_typeObject

Just makes the type (:plugin or :application) available to all templates



57
58
59
# File 'lib/origen_app_generators/base.rb', line 57

def set_type
  @type = type
end

#validate_application_nameObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/origen_app_generators/base.rb', line 8

def validate_application_name
  @name = args.first.to_s.strip
  if @name == ''
    puts
    puts "You must supply a name for what you want to call your application: 'origen new my_name'"
    puts
    exit 1
  elsif @name != @name.symbolize.to_s
    puts
    puts 'The name of your new app must be lowercased and underscored and contain no special characters'
    puts
    exit 1
  end
end