Class: Skele::Runner

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

Instance Method Summary collapse

Constructor Details

#initialize(skeleton, destination, root = SKELETON_ROOT) ⇒ Runner

Returns a new instance of Runner.



103
104
105
# File 'lib/skele.rb', line 103

def initialize(skeleton, destination, root=SKELETON_ROOT)
  @skeleton = Skeleton.new(skeleton, destination, root)
end

Instance Method Details

#blue(text) ⇒ Object



169
170
171
# File 'lib/skele.rb', line 169

def blue(text)
  colorize text, 34
end

#bundle_installObject



116
117
118
119
120
121
122
123
124
# File 'lib/skele.rb', line 116

def bundle_install
  STDOUT.puts "\nRunning bundle install\n\n"

  bundle = @skeleton.bundle_install

  unless bundle.nil?
    STDOUT.puts indent bundle
  end
end

#colorize(text, color_code) ⇒ Object



157
158
159
# File 'lib/skele.rb', line 157

def colorize(text, color_code)
  "\e[#{color_code}m#{text}\e[0m"
end

#copy_filesObject



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/skele.rb', line 126

def copy_files
  STDOUT.puts "\nCopying files\n\n"
  file_result = @skeleton.copy_files

  if file_result.nil?
    STDOUT.puts indent(red("Error:") + "Skeleton '#{@skeleton.skeleton}' does not exist or is not a directory")
  else

    file_result.each do |result|
      case result[:action]
        when "mkdir"
          STDOUT.puts indent(" " + green(result[:action]) + "  " + result[:file])
        when "create"
          STDOUT.puts indent(green(result[:action]) + "  " + result[:file])
        when "exists"
          STDOUT.puts indent(red(result[:action]) + "  " + result[:file])
      end
    end
  end
end

#green(text) ⇒ Object



165
166
167
# File 'lib/skele.rb', line 165

def green(text)
  colorize text, 32
end

#indent(string) ⇒ Object



147
148
149
150
151
152
153
154
155
# File 'lib/skele.rb', line 147

def indent(string)
  indented = ""

  string.split("\n").each do |line|
    indented += INDENTATION + line + "\n"
  end

  return indented
end

#red(text) ⇒ Object



161
162
163
# File 'lib/skele.rb', line 161

def red(text)
  colorize text, 31 
end

#summonObject



107
108
109
110
111
112
113
114
# File 'lib/skele.rb', line 107

def summon
  STDOUT.puts "\nSummoning skeleton '#{@skeleton.skeleton}' from '#{@skeleton.destination}'"

  copy_files
  bundle_install

  STDOUT.puts "\nSkeleton complete. Enjoy!\n\n"
end