Class: Corundum::CLI::Skelfiles

Inherits:
Object
  • Object
show all
Defined in:
lib/corundum/cli/skelfiles.rb

Defined Under Namespace

Classes: Skelfile, SkelfileScope

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Skelfiles

Returns a new instance of Skelfiles.



37
38
39
# File 'lib/corundum/cli/skelfiles.rb', line 37

def initialize(args)
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



40
41
42
# File 'lib/corundum/cli/skelfiles.rb', line 40

def args
  @args
end

Instance Method Details

#default_project_nameObject



63
64
65
# File 'lib/corundum/cli/skelfiles.rb', line 63

def default_project_name
  File.basename(Dir.pwd)
end

#goObject



85
86
87
88
89
90
91
92
# File 'lib/corundum/cli/skelfiles.rb', line 85

def go
  parse_args

  skelfiles.each do |skelfile|
    skelfile.create!(scope)
    puts skelfile.message
  end
end

#optionsObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/corundum/cli/skelfiles.rb', line 44

def options
  @options ||= OptionParser.new do |opti|
    opti.banner = "Spits out skeleton files to start a gem with.\nUsage: #$0 [options]"
    opti.on("-h", "--help", "This help message") do
      puts opti
      puts "Will emit these files:"
      puts skelfiles.map{|desc| desc.target}.join(", ")
      puts
      puts "Files are copied from the skel-files directory out of this search path:"
      puts Corundum.configuration_store.valise
      exit 0
    end

    opti.on("-p", "--project NAME", "Sets the name of the project (defaults to dirname, i.e. '#{default_project_name}')") do |name| #ok
      scope.project_name = name
    end
  end
end

#parse_argsObject



81
82
83
# File 'lib/corundum/cli/skelfiles.rb', line 81

def parse_args
  options.parse(args)
end

#scopeObject



67
68
69
# File 'lib/corundum/cli/skelfiles.rb', line 67

def scope
  @scope ||= SkelfileScope.new(default_project_name)
end

#skelfilesObject



71
72
73
74
75
76
77
78
79
# File 'lib/corundum/cli/skelfiles.rb', line 71

def skelfiles
  @skelfiles ||= [
    Skelfile.new( 'rakefile',   'Rakefile',                       Rake::Application::DEFAULT_RAKEFILES),
    Skelfile.new( 'simplecov',  '.simplecov',                     %w[.simplecov] ),
    Skelfile.new( 'travis',     '.travis.yml',                    %w[.travis.yml] ),
    Skelfile.new( 'gemspec',    "#{scope.project_name}.gemspec",  %w{gemspec.rb *.gemspec} ),
    Skelfile.new( 'gemfile',    'Gemfile',                        %w[Gemfile] )
  ]
end