Module: GemConstructor

Defined in:
lib/gem_constructor.rb,
lib/gem_constructor/version.rb

Constant Summary collapse

VERSION =
"0.0.7"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.construct(lib_name) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/gem_constructor.rb', line 13

def construct(lib_name)
  @lib_name = lib_name

  run_bundler
  construct_rake_file
  construct_readme
  construct_specs
end

.construct_rake_fileObject



28
29
30
31
32
# File 'lib/gem_constructor.rb', line 28

def construct_rake_file
  File.open("#{@lib_name}/RakeFile", "w") do |file|
    file.write(template("rake_file"))
  end
end

.construct_readmeObject



34
35
36
37
38
# File 'lib/gem_constructor.rb', line 34

def construct_readme
  File.open("#{@lib_name}/README.md", "w") do |file|
    file.write(erubis("readme"))
  end
end

.construct_specsObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/gem_constructor.rb', line 40

def construct_specs
  # Directories
  FileUtils.mkdir_p(spec_path + "/#{@lib_name}")

  # Fixture directory
  FileUtils.mkdir_p(spec_path + "/fixtures")

  # Spec helper
  File.open("#{spec_path}/spec_helper.rb", "w") do |file|
    file.write(erubis("spec_helper"))
  end

  # .rspec
  File.open("#{@lib_name}/.rspec", "w") do |file|
    file.write("--color\n")
    file.write("--profile")
  end
end

.erubis(template_name) ⇒ Object



63
64
65
# File 'lib/gem_constructor.rb', line 63

def erubis(template_name)
  Erubis::Eruby.new(template(template_name)).result(binding())
end

.run_bundlerObject



24
25
26
# File 'lib/gem_constructor.rb', line 24

def run_bundler
  system("bundle gem #{@lib_name}")
end

.spec_pathObject



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

def spec_path
  File.join(@lib_name, "spec")
end

.template(name) ⇒ Object



67
68
69
# File 'lib/gem_constructor.rb', line 67

def template(name)
  File.read(File.expand_path("../", __FILE__) + "/gem_constructor/templates/#{name}.erb")
end

Instance Method Details

#construct(lib_name) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/gem_constructor.rb', line 13

def construct(lib_name)
  @lib_name = lib_name

  run_bundler
  construct_rake_file
  construct_readme
  construct_specs
end