Class: PlasticRails::PlaRails

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/plastic_rails.rb

Constant Summary collapse

DEFAULT_TEMPLATE_DIR =
File.join(File.dirname(__FILE__) , "tmpl")

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


16
17
18
19
# File 'lib/plastic_rails.rb', line 16

def self.exit_on_failure?
  # コマンドが失敗したときに終了ステータス1を返すようにする設定
  true
end

.source_rootObject



12
13
14
# File 'lib/plastic_rails.rb', line 12

def self.source_root
  Dir.pwd
end

Instance Method Details

#copy_template(dest_dir) ⇒ Object



62
63
64
# File 'lib/plastic_rails.rb', line 62

def copy_template(dest_dir)
  directory(DEFAULT_TEMPLATE_DIR, dest_dir, :mode => :preserve)
end

#downObject



57
58
59
# File 'lib/plastic_rails.rb', line 57

def down
  run("docker-compose down")
end

#loginObject



42
43
44
# File 'lib/plastic_rails.rb', line 42

def 
  run("docker-compose exec web bash")
end

#new(appname) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/plastic_rails.rb', line 24

def new(appname)
  directory(options[:template], appname, :mode => :preserve)
  inside(appname) do
    # DBのファイルパスを設定する
    gsub_file("docker-compose.yml", /%DB_PATH%/, options[:db_path]) 

    # Dockerイメージビルド&rails new (working_dirは `/apps`)
    run("./build.sh #{appname}")

    # working_dirをrailsアプリのディレクトリに変更する
    gsub_file("docker-compose.yml", /(working_dir: \/apps\/)/, '\1' + appname) 

    # Railsアプリの設定(`bundle install`, `rails db:setup` など)
    run("./setup.sh")
  end
end

#stopObject



52
53
54
# File 'lib/plastic_rails.rb', line 52

def stop
  run("docker-compose stop")
end

#upObject



47
48
49
# File 'lib/plastic_rails.rb', line 47

def up
  run("docker-compose up -d")
end