Class: RubyDir::Instruct

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_dir.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Instruct

Returns a new instance of Instruct.



8
9
10
# File 'lib/ruby_dir.rb', line 8

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/ruby_dir.rb', line 6

def name
  @name
end

Instance Method Details

#create_directoryObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ruby_dir.rb', line 12

def create_directory
  `mkdir #{name}`
  puts "created #{name}/"
  `cd #{name} && mkdir app`
  puts "created #{name}/app"
  `cd #{name}/app && mkdir models`
  puts "created #{name}/app/models"
  `touch #{name}/app/run.rb`
  `echo "class App\n\n  def self.run\n    # Your code here...\n  end\n\nend" >> #{name}/app/run.rb`
  puts "created #{name}/app/run.rb"
  `cd #{name} && bundle init`
  puts "created #{name}/Gemfile"
  `cd #{name} && echo '\ngem "rspec"\ngem "require_all"\ngem "pry"' >> Gemfile`
  puts "added pry and rspec to Gemfile"
  `cd #{name} && mkdir config && touch config/environment.rb`
  `cd #{name} && echo "require 'bundler/setup'\nBundler.require\nrequire_rel '../app'" >> config/environment.rb`
  puts "created #{name}/config/environment.rb"
  `cd #{name} && rspec --init`
  `cd #{name} && echo 'require_relative "../config/environment.rb"' | cat - spec/spec_helper.rb > temp && mv temp spec/spec_helper.rb`
  puts "created #{name}/spec/spec_helper.rb"
  `cd #{name} && touch spec/#{name}_spec.rb`
  `echo "describe 'App' do\n  it 'executes successfully without errors' do\n    expect{App.run}.to_not raise_error\n  end\nend" >> #{name}/spec/#{name}_spec.rb`
  puts "created #{name}/spec/#{name}_spec.rb"
  `cd #{name} && mkdir tools && touch tools/console.rb`
  `echo "require_relative '../config/environment.rb'\n\ndef reload\n  load 'config/environment.rb'\nend\n\n# Insert code here to run before hitting the binding.pry\n# This is a convenient place to define variables and/or set up new object instances,\n# so they will be available to test and play around with in your console\n\nbinding.pry\nputs 'goodbye'" >> #{name}/tools/console.rb`
  puts "created #{name}/tools/console.rb"
  `cd #{name} && bundle`
end