Class: Dokkit::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/dokkit/application.rb

Constant Summary collapse

OPTIONS =
[
 [ "--usage", "-u", GetoptLong::NO_ARGUMENT,
   "Display usage information." ],
 [ "--help", "-h", GetoptLong::NO_ARGUMENT,
   "Synonim for usage."],
 [ "--version", "-v", GetoptLong::NO_ARGUMENT,
   "Display the version number and quit." ],
 [ "--list", '-l', GetoptLong::NO_ARGUMENT,
   "List the available models."],
 [ "--model", '-m', GetoptLong::REQUIRED_ARGUMENT,
   "Specify a documentation model" ]
]
USAGE_PREAMBLE =
<<-EOU
Usage: dokkit [options] <dest_dir>

Where dest_dir is the directory in which to setup the documentation
environment.

EOU

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, configuration = { }) ⇒ Application

Returns a new instance of Application.



61
62
63
64
65
66
67
# File 'lib/dokkit/application.rb', line 61

def initialize(logger, configuration = { })
  @logger = logger
  @configuration = configuration
  @user_dir = configuration[:user_dir] || relative_to_home('.dokkit')
  @model_dir = configuration[:model_dir] || 'models'
  @default_model = configuration[:default_model] || 'simple'
end

Instance Attribute Details

#default_modelObject (readonly)

Returns the value of attribute default_model.



59
60
61
# File 'lib/dokkit/application.rb', line 59

def default_model
  @default_model
end

Class Method Details

.get_model_dir_from(array_of_path) ⇒ Object



22
23
24
# File 'lib/dokkit/application.rb', line 22

def get_model_dir_from(array_of_path)
  array_of_path.select { |path| path =~ /\.?dokkit-?/ }.collect { |path| File.join(path, 'models')}
end

.get_modelname_from(path) ⇒ Object



18
19
20
# File 'lib/dokkit/application.rb', line 18

def get_modelname_from(path)
  File.basename(path)
end

.get_models_from(array_of_path) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/dokkit/application.rb', line 26

def get_models_from(array_of_path)
  models = { }
  get_model_dir_from(array_of_path).each do |model_path|
    Dir.glob(File.join(model_path, '*')).each do |model_path|
      name = get_modelname_from(model_path)
      models[name] = model_path
    end
  end
  models
end

Instance Method Details

#modelsObject



69
70
71
# File 'lib/dokkit/application.rb', line 69

def models
  Application::get_models_from(Gem.latest_load_paths.push(@user_dir))
end

#runObject



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/dokkit/application.rb', line 73

def run
  
  process_args
  
  unless ARGV.empty?
    create_environment(ARGV.to_s)
  else
    do_option('--help')        
  end

end