LoginSignup
6
4

More than 5 years have passed since last update.

どう書く用の Ruby のテンプレート作った

Last updated at Posted at 2016-03-19

オフラインリアルタイムどう書く 用のテンプレート作った。

bundler/inline を最近知ったので使ってみたかっただけとも言う。
gemfile(true)bundle install してくれるみたいだけど、毎回問合せされて時間かかって辛かったので強引に Gemfile との複合構成にしてみた。
こうすることで lock も吐けるし binstubs も使うことができる。(多分使わないけど)

template/doukaku.rb

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'

  gem 'activesupport', require: 'active_support/all'

  gem 'minitest', require: 'minitest/autorun'
  gem 'minitest-reporters'

  gem 'awesome_print'
  gem 'tapp'

  gem 'pry'
  gem 'pry-rescue', require: 'pry-rescue/minitest'
  gem 'pry-stack_explorer'
end

def solve(input)
end

TEST_DATA = <<~EOS
EOS

Minitest::Reporters.use!(Minitest::Reporters::ProgressReporter.new)

describe 'Doukaku' do
  TEST_DATA.each_line do |test|
    input, expected = test.scan(/"(.*)", "(.*)"/)[0]

    it input do
      assert_equal expected, solve(input)
    end
  end
end

template/Gemfile

eval File.read('doukaku.rb').scan(/gemfile do\n(.*?)\nend/m)[0][0]

bin/setup

#!/usr/bin/env ruby

require 'pathname'
require 'fileutils'
require 'date'
include FileUtils

def system!(*args)
  system(*args) || abort("\n== Command #{args} failed ==")
end

root_dir     = Pathname.new(File.expand_path('../../', __FILE__))
template_dir = root_dir.join('template')
dir          = root_dir.join(Date.today.strftime('%Y%m%d'))

cp_r template_dir, dir

chdir dir do
  system! 'bundle install --binstubs'
  system! 'git add . && git commit -m "init"'
end
6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4