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.



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

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)


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

def author
  @author
end

#gem_homeString? (readonly)

Returns the value of attribute gem_home.

Returns:

  • (String, nil)


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

def gem_home
  @gem_home
end

#homepageString (readonly)

Returns the value of attribute homepage.

Returns:

  • (String)


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

def homepage
  @homepage
end

#licenseString (readonly)

Returns the value of attribute license.

Returns:

  • (String)


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

def license
  @license
end

#nameString (readonly)

Returns the value of attribute name.

Returns:

  • (String)


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

def name
  @name
end

#required_ruby_versionString (readonly)

Returns the value of attribute required_ruby_version.

Returns:

  • (String)


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

def required_ruby_version
  @required_ruby_version
end

#rootString (readonly)

Returns the value of attribute root.

Returns:

  • (String)


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

def root
  @root
end

#summaryString (readonly)

Returns the value of attribute summary.

Returns:

  • (String)


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

def summary
  @summary
end

#versionString (readonly)

Returns the value of attribute version.

Returns:

  • (String)


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

def version
  @version
end

Instance Method Details

#buildself

Returns:

  • (self)


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

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

#built_gem_fileString

Returns:

  • (String)


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

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

#built_gem_pathString

Returns:

  • (String)


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

def built_gem_path
  File.join(root, built_gem_file)
end

#cleanself

Returns:

  • (self)


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

def clean
  FileUtils.rm_rf(root)
  self
end

#createself

Returns:

  • (self)


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

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

#gemspec_fileString

Returns:

  • (String)


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

def gemspec_file
  "#{name}.gemspec"
end

#gemspec_pathString

Returns:

  • (String)


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

def gemspec_path
  File.join(root, gemspec_file)
end

#initialize_gitself

Returns:

  • (self)


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

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)


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

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

#lib_fileString

Returns:

  • (String)


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

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

#lib_pathString

Returns:

  • (String)


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

def lib_path
  File.join(root, lib_file)
end