Class: Working::Initializer

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

Direct Known Subclasses

PlainInitializer

Constant Summary collapse

RAILS_TODO_APOLOGY =
<<-EOT
No automatic setup for Rails, yet. ☹
Try mimicking https://github.com/rking/monkeynote
# Basically, it'll be:
# test/test_helper.rb
#   %{require 'working/rails_test_helper'},
#   %{# Spork.prefork doesn't like when this is missing},
# Gemfile
#   %{group :development do\n   gem 'pry-rails'\nend},
# Guardfile
#   require 'working/guard-rails'
EOT

Instance Method Summary collapse

Constructor Details

#initialize(contents) ⇒ Initializer

Returns a new instance of Initializer.



45
46
47
# File 'lib/working/init.rb', line 45

def initialize contents
  (@contents ||= {}).merge! contents
end

Instance Method Details

#heading(verb, noun) ⇒ Object



49
50
51
# File 'lib/working/init.rb', line 49

def heading verb, noun
  puts "\e[32m #{verb}\e[0;1m: \e[36;1m#{noun}\e[0m ".center 60, ?—
end

#run(argv) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/working/init.rb', line 24

def run argv
  unless Dir.exists? 'test'
    heading 'mkdir', 'test'
    Dir.mkdir 'test'
  end
  @contents.each do |path, content|
    if File.exist? path
      heading 'found', path
    else
      heading 'create', path
      File.write path, ''
    end
    existing = File.read path
    content.each do |line|
      next if existing[line]
      puts line
      File.write path, line + "\n", mode: 'a'
    end
  end
end