Class: GemMine::Scaffold

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

Constant Summary collapse

DEFAULT_AUTHOR =
"Mr. Smith"
DEFAULT_GIT_USER_EMAIL =
"gem_mine@appraisal-rb.local"
DEFAULT_GIT_USER_NAME =
"GemMine"
DEFAULT_HOMEPAGE_BASE =
"https://github.com/appraisal-rb"
DEFAULT_LICENSE =
"MIT"
DEFAULT_REQUIRED_RUBY_VERSION =
">= 1.8.7"
DEFAULT_SUMMARY =
"summary"
DEFAULT_VERSION =
"1.0.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, root:, version: DEFAULT_VERSION, gem_home: nil, author: DEFAULT_AUTHOR, summary: DEFAULT_SUMMARY, license: DEFAULT_LICENSE, homepage: nil, required_ruby_version: DEFAULT_REQUIRED_RUBY_VERSION, verbose: false) ⇒ Scaffold

Returns a new instance of Scaffold.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gem_mine.rb', line 46

def initialize(
  name,
  root:,
  version: DEFAULT_VERSION,
  gem_home: nil,
  author: DEFAULT_AUTHOR,
  summary: DEFAULT_SUMMARY,
  license: DEFAULT_LICENSE,
  homepage: nil,
  required_ruby_version: DEFAULT_REQUIRED_RUBY_VERSION,
  verbose: false
)
  @name = name.to_s
  @version = version.to_s
  @root = File.expand_path(root)
  @gem_home = gem_home && File.expand_path(gem_home)
  @author = author
  @summary = summary
  @license = license
  @homepage = homepage || "#{DEFAULT_HOMEPAGE_BASE}/#{@name}"
  @required_ruby_version = required_ruby_version
  @verbose = verbose
end

Instance Attribute Details

#authorObject (readonly)

Returns the value of attribute author.



36
37
38
# File 'lib/gem_mine.rb', line 36

def author
  @author
end

#gem_homeObject (readonly)

Returns the value of attribute gem_home.



36
37
38
# File 'lib/gem_mine.rb', line 36

def gem_home
  @gem_home
end

#homepageObject (readonly)

Returns the value of attribute homepage.



36
37
38
# File 'lib/gem_mine.rb', line 36

def homepage
  @homepage
end

#licenseObject (readonly)

Returns the value of attribute license.



36
37
38
# File 'lib/gem_mine.rb', line 36

def license
  @license
end

#nameObject (readonly)

Returns the value of attribute name.



36
37
38
# File 'lib/gem_mine.rb', line 36

def name
  @name
end

#required_ruby_versionObject (readonly)

Returns the value of attribute required_ruby_version.



36
37
38
# File 'lib/gem_mine.rb', line 36

def required_ruby_version
  @required_ruby_version
end

#rootObject (readonly)

Returns the value of attribute root.



36
37
38
# File 'lib/gem_mine.rb', line 36

def root
  @root
end

#summaryObject (readonly)

Returns the value of attribute summary.



36
37
38
# File 'lib/gem_mine.rb', line 36

def summary
  @summary
end

#versionObject (readonly)

Returns the value of attribute version.



36
37
38
# File 'lib/gem_mine.rb', line 36

def version
  @version
end

Instance Method Details

#buildObject



77
78
79
80
81
# File 'lib/gem_mine.rb', line 77

def build
  create unless File.file?(gemspec_path)
  run("gem", "build", gemspec_file, chdir: root)
  self
end

#built_gem_fileObject



120
121
122
# File 'lib/gem_mine.rb', line 120

def built_gem_file
  "#{name}-#{version}.gem"
end

#built_gem_pathObject



124
125
126
# File 'lib/gem_mine.rb', line 124

def built_gem_path
  File.join(root, built_gem_file)
end

#cleanObject



99
100
101
102
# File 'lib/gem_mine.rb', line 99

def clean
  FileUtils.rm_rf(root)
  self
end

#createObject



70
71
72
73
74
75
# File 'lib/gem_mine.rb', line 70

def create
  FileUtils.mkdir_p(lib_dir)
  write_gemspec
  write_lib_file
  self
end

#gemspec_fileObject



112
113
114
# File 'lib/gem_mine.rb', line 112

def gemspec_file
  "#{name}.gemspec"
end

#gemspec_pathObject



116
117
118
# File 'lib/gem_mine.rb', line 116

def gemspec_path
  File.join(root, gemspec_file)
end

#initialize_gitObject



89
90
91
92
93
94
95
96
97
# File 'lib/gem_mine.rb', line 89

def initialize_git
  create unless File.file?(gemspec_path)
  run("git", "init", ".", "--initial-branch=main", chdir: root)
  run("git", "config", "user.email", DEFAULT_GIT_USER_EMAIL, chdir: root)
  run("git", "config", "user.name", DEFAULT_GIT_USER_NAME, chdir: root)
  run("git", "add", ".", chdir: root)
  run("git", "commit", "--all", "--no-verify", "--message", "initial commit", chdir: root)
  self
end

#installObject



83
84
85
86
87
# File 'lib/gem_mine.rb', line 83

def install
  build unless File.file?(built_gem_path)
  run(*install_command, chdir: root, env: gem_home_env)
  self
end

#lib_fileObject



104
105
106
# File 'lib/gem_mine.rb', line 104

def lib_file
  File.join("lib", "#{name}.rb")
end

#lib_pathObject



108
109
110
# File 'lib/gem_mine.rb', line 108

def lib_path
  File.join(root, lib_file)
end