class Legworker::Legs
Public Instance Methods
sequence(options)
click to toggle source
# File lib/legworker.rb, line 77 def sequence(options) input_directory = options[:input_directory] output_directory = options[:output_directory] file_name = options[:file_name] variable_name = options[:variable] file_count = 0 accepted_file_types = [".jpeg",".jpg",".JPEG",".JPG",".gif",".GIF",".png",".PNG"] extension = "png" encoded_data = "" ## Verify path is valid if File.directory?(input_directory) ## Verify Output Directory Exists if File.directory?(output_directory) puts "Creating #{file_name} in #{output_directory}".green if out_file = File.new("#{output_directory}/#{file_name}.json", "w") encoded_data = "var #{variable_name} = [" puts "//////////////////////////////////////////////////////////////////////////////////////".green Dir.foreach("#{input_directory}") do |item| if accepted_file_types.include? File.extname("#{item}") puts "Encoding: #{item}".cyan if Base64.encode64( open("#{input_directory}/#{item}").read) encoded_string = Base64.encode64( open("#{input_directory}/#{item}").read).gsub("\n", '') encoded_data << "'data:image/#{extension};base64,#{encoded_string}'," end end end puts "//////////////////////////////////////////////////////////////////////////////////////".green encoded_data << "]" out_file.puts encoded_data.gsub("\n","") out_file.close else puts "Failed to create #{file_name} in #{output_directory}".red end else puts "Oops looks like your output directory doesn't exist.".red end else puts "Oops looks like that directory is not valid.".red end end
setup_app(options)
click to toggle source
# File lib/legworker.rb, line 36 def setup_app(options) app_options = {} vagrant_file = 'config/puppet/manifests/vagrant.pp' file = File.open(vagrant_file) contents = file.read contents.gsub!('_APPLICATION_NAME_',options[:application_name]) contents.gsub!('_DEV_USER_',options[:dev_user]) contents.gsub!('_DEV_PASS_',options[:dev_pass]) contents.gsub!('_PROD_USER_',options[:prod_user]) contents.gsub!('_PROD_PASS_',options[:prod_pass]) File.open(vagrant_file, "w") { |f| f.puts contents } database_yml = "config/puppet/templates/database.yml.erb" db = File.open(database_yml) db_contents = db.read db_contents.gsub!("_DEV_DATABASE_",options[:dev_database]) db_contents.gsub!("_PROD_DATABASE_",options[:prod_database]) db_contents.gsub!('_DEV_USER_',options[:dev_user]) db_contents.gsub!('_DEV_PASS_',options[:dev_pass]) db_contents.gsub!('_PROD_USER_',options[:prod_user]) db_contents.gsub!('_PROD_PASS_',options[:prod_pass]) File.open(database_yml, "w") { |f| f.puts db_contents } puts "Starting Vagrant....".green system('vagrant up || exit') system('vagrant provision') end
vagrant(options)
click to toggle source
# File lib/legworker.rb, line 14 def vagrant(options) # download useful things system('curl -sS https://s3.amazonaws.com/legworker/Vagrantfile > Vagrantfile') # download puppet.zip system('curl -sS https://s3.amazonaws.com/legworker/puppet.zip > puppet.zip') system('unzip puppet.zip -d config') system('rm puppet.zip') system('rm -rf config/__MACOSX || exit') system('rm -rf Gemfile') system('curl -sS https://s3.amazonaws.com/legworker/Gemfile > Gemfile') self.setup_app(options) end