Class: MetaModel::Command::Generate

Inherits:
MetaModel::Command show all
Defined in:
lib/metamodel/command/generate.rb

Constant Summary

Constants inherited from MetaModel::Command

METAMODEL_COMMAND_ALIAS, METAMODEL_OPTION_ALIAS

Instance Method Summary collapse

Methods inherited from MetaModel::Command

#installer_for_config, options, run

Methods included from MetaModel::Config::Mixin

#config

Constructor Details

#initialize(argv) ⇒ Generate

Returns a new instance of Generate.



11
12
13
14
15
# File 'lib/metamodel/command/generate.rb', line 11

def initialize(argv)
  @model_name = argv.shift_argument
  @metafile_path = config.metafile_path
  super
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/metamodel/command/generate.rb', line 17

def run
  verify_meta_exists!
  UI.section "Generating model scaffold" do
    title_options = { :verbose_prefix => '-> '.green }
    UI.titled_section "Adding `#{@model_name.camelize} model to Metafile", title_options do
      @metafile_path.open('a') do |source|
        source.puts model_template(@model_name)
      end
    end
    UI.notice "Adding `#{@model_name.camelize}` model scaffold to Metafile, use the command below to edit it.\n"
    UI.message "vim Metafile"
  end
end