Class: GemInit::App

Inherits:
Object
  • Object
show all
Includes:
FileUtils
Defined in:
lib/gem_init/app.rb

Constant Summary collapse

DEFAULT_GIT_CONFIG =
{
  :user => {
    :name  => "YOUR NAME",
    :email => "YOUR EMAIL",
  },
  :github => {
    :name => "your_github_user_name"
  }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(gem_name) ⇒ App

Returns a new instance of App.



23
24
25
26
# File 'lib/gem_init/app.rb', line 23

def initialize(gem_name)
  @gem_name  = gem_name.downcase
  @templates = File.expand_path("../templates",  __FILE__)
end

Instance Attribute Details

#gem_nameObject (readonly)

Returns the value of attribute gem_name.



9
10
11
# File 'lib/gem_init/app.rb', line 9

def gem_name
  @gem_name
end

#templatesObject (readonly)

Returns the value of attribute templates.



11
12
13
# File 'lib/gem_init/app.rb', line 11

def templates
  @templates
end

Instance Method Details

#authorObject



48
49
50
# File 'lib/gem_init/app.rb', line 48

def author
  @author ||= git_config[:user][:name]
end

#emailObject



52
53
54
# File 'lib/gem_init/app.rb', line 52

def email
  @email ||= git_config[:user][:email]
end

#github_userObject



56
57
58
# File 'lib/gem_init/app.rb', line 56

def github_user
  @github_user ||= git_config[:github][:user]
end

#mainObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gem_init/app.rb', line 28

def main
  if File.exists?(gem_name)
    raise "Directory '#{gem_name}' already exists, bailing out."
  end
  mkdir_p module_lib_dir
  mkdir_p test_dir
  write_template(lib_dir, "module.rb", "#{gem_name}.rb")
  write_template(module_lib_dir, "version.rb")
  write_template(test_dir, "test_helper.rb")
  write_template(test_dir, "module_test.rb", "#{gem_name}_test.rb")
  write_template(gem_name, "gemspec", "#{gem_name}.gemspec")
  write_template(gem_name, "Gemfile.default")
  write_template(gem_name, "Gemfile.default", "Gemfile")
  write_template(gem_name, "Rakefile")
  write_template(gem_name, "MIT-LICENSE")
  write_template(gem_name, "README.md")
  write_template(gem_name, "gitignore", ".gitignore")
  `git init #{gem_name.shellescape}`
end