Class: GemMine::Scaffold

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

Constant Summary collapse

DEFAULT_AUTHOR =

Returns:

  • (String)
"Mr. Smith"
DEFAULT_GIT_USER_EMAIL =

Returns:

  • (String)
"gem_mine@appraisal-rb.local"
DEFAULT_GIT_USER_NAME =

Returns:

  • (String)
"GemMine"
DEFAULT_HOMEPAGE_BASE =

Returns:

  • (String)
"https://github.com/appraisal-rb"
DEFAULT_LICENSE =

Returns:

  • (String)
"MIT"
DEFAULT_REQUIRED_RUBY_VERSION =

Returns:

  • (String)
">= 1.8.7"
DEFAULT_SUMMARY =

Returns:

  • (String)
"summary"
DEFAULT_VERSION =

Returns:

  • (String)
"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

#authorString (readonly)

Returns the value of attribute author.

Returns:

  • (String)


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

def author
  @author
end

#gem_homeString? (readonly)

Returns the value of attribute gem_home.

Returns:

  • (String, nil)


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

def gem_home
  @gem_home
end

#homepageString (readonly)

Returns the value of attribute homepage.

Returns:

  • (String)


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

def homepage
  @homepage
end

#licenseString (readonly)

Returns the value of attribute license.

Returns:

  • (String)


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

def license
  @license
end

#nameString (readonly)

Returns the value of attribute name.

Returns:

  • (String)


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

def name
  @name
end

#required_ruby_versionString (readonly)

Returns the value of attribute required_ruby_version.

Returns:

  • (String)


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

def required_ruby_version
  @required_ruby_version
end

#rootString (readonly)

Returns the value of attribute root.

Returns:

  • (String)


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

def root
  @root
end

#summaryString (readonly)

Returns the value of attribute summary.

Returns:

  • (String)


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

def summary
  @summary
end

#versionString (readonly)

Returns the value of attribute version.

Returns:

  • (String)


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

def version
  @version
end

Instance Method Details

#buildself

Returns:

  • (self)


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_fileString

Returns:

  • (String)


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

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

#built_gem_pathString

Returns:

  • (String)


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

def built_gem_path
  File.join(root, built_gem_file)
end

#cleanself

Returns:

  • (self)


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

def clean
  FileUtils.rm_rf(root)
  self
end

#createself

Returns:

  • (self)


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_fileString

Returns:

  • (String)


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

def gemspec_file
  "#{name}.gemspec"
end

#gemspec_pathString

Returns:

  • (String)


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

def gemspec_path
  File.join(root, gemspec_file)
end

#initialize_gitself

Returns:

  • (self)


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

#installself

Returns:

  • (self)


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_fileString

Returns:

  • (String)


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

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

#lib_pathString

Returns:

  • (String)


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

def lib_path
  File.join(root, lib_file)
end