class SolidusDevSupport::Extension

Constants

PREFIX

Public Class Methods

source_root() click to toggle source
# File lib/solidus_dev_support/extension.rb, line 124
def self.source_root
  "#{__dir__}/templates/extension"
end

Public Instance Methods

default_gemspec() click to toggle source
# File lib/solidus_dev_support/extension.rb, line 72
def default_gemspec
  @default_gemspec ||= Gem::Specification.new(file_name, '0.0.1') do |gem|
    gem.author = git('config user.name', 'TODO: Write your name')
    gem.email = git('config user.email', 'TODO: Write your email address')

    gem.summary = 'TODO: Write a short summary, because RubyGems requires one.'
    gem.description = 'TODO: Write a longer description or delete this line.'
    gem.license = 'BSD-3-Clause'

    gem.metadata['homepage_uri'] = gem.homepage = "https://github.com/#{repo}#readme"
    gem.metadata['changelog_uri'] = "https://github.com/#{repo}/blob/master/CHANGELOG.md"
    gem.metadata['source_code_uri'] = "https://github.com/#{repo}"
  end
end
default_repo() click to toggle source
# File lib/solidus_dev_support/extension.rb, line 104
def default_repo
  "solidusio-contrib/#{file_name}"
end
existing_gemspec() click to toggle source
# File lib/solidus_dev_support/extension.rb, line 87
def existing_gemspec
  return unless File.exist?(gemspec_path)

  @existing_gemspec ||= Gem::Specification.load(gemspec_path).tap do |spec|
    spec.author ||= default_gemspec.author
    spec.email ||= default_gemspec.email

    spec.summary ||= default_gemspec.summary
    spec.license ||= default_gemspec.license

    spec.homepage ||= default_gemspec.homepage
    spec.metadata['source_code_uri'] ||= default_gemspec.metadata['source_code_uri']
    spec.metadata['changelog_uri'] ||= default_gemspec.metadata['changelog_uri']
    spec.metadata['source_code_uri'] ||= default_gemspec.metadata['source_code_uri']
  end
end
existing_repo() click to toggle source
# File lib/solidus_dev_support/extension.rb, line 108
def existing_repo
  git('remote get-url origin')&.sub(%r{^.*github\.com.([^/]+)/([^/.]+).*$}, '\1/\2')
end
gemspec_path() click to toggle source
# File lib/solidus_dev_support/extension.rb, line 68
def gemspec_path
  @gemspec_path ||= File.join(path, "#{file_name}.gemspec")
end
generate(raw_path = '.') click to toggle source
# File lib/solidus_dev_support/extension.rb, line 16
def generate(raw_path = '.')
  self.path = raw_path

  empty_directory path

  directory 'app', "#{path}/app"
  directory 'lib', "#{path}/lib"
  directory 'bin', "#{path}/bin"
  directory '.circleci', "#{path}/.circleci"
  directory '.github', "#{path}/.github"

  Dir["#{path}/bin/*"].each do |bin|
    make_executable bin
  end

  template 'CHANGELOG.md', "#{path}/CHANGELOG.md"
  template 'extension.gemspec', "#{path}/#{file_name}.gemspec"
  template 'Gemfile', "#{path}/Gemfile"
  template 'gitignore', "#{path}/.gitignore"
  template 'gem_release.yml.tt', "#{path}/.gem_release.yml"
  template 'LICENSE', "#{path}/LICENSE"
  template 'Rakefile', "#{path}/Rakefile"
  template 'README.md', "#{path}/README.md"
  template 'config/routes.rb', "#{path}/config/routes.rb"
  template 'config/locales/en.yml', "#{path}/config/locales/en.yml"
  template 'rspec', "#{path}/.rspec"
  template 'spec/spec_helper.rb.tt', "#{path}/spec/spec_helper.rb"
  template 'rubocop.yml', "#{path}/.rubocop.yml"
  template 'github_changelog_generator', "#{path}/.github_changelog_generator"
end
git(command, default = nil) click to toggle source
# File lib/solidus_dev_support/extension.rb, line 112
def git(command, default = nil)
  result = `git #{command} 2> /dev/null`.strip
  result.empty? ? default : result
end
make_executable(path) click to toggle source
# File lib/solidus_dev_support/extension.rb, line 117
def make_executable(path)
  path = Pathname(path)
  executable = (path.stat.mode | 0o111)
  path.chmod(executable)
end
path=(path) click to toggle source
# File lib/solidus_dev_support/extension.rb, line 48
def path=(path)
  path = File.expand_path(path)

  @file_name = Thor::Util.snake_case(File.basename(path))
  @file_name = PREFIX + @file_name unless @file_name.start_with?(PREFIX)

  @class_name = Thor::Util.camel_case file_name

  @root = File.dirname(path)
  @path = File.join(root, file_name)

  @repo = existing_repo || default_repo

  @gemspec = existing_gemspec || default_gemspec
end