Class: Legworker::Legs
- Inherits:
-
Object
- Object
- Legworker::Legs
- Defined in:
- lib/legworker.rb
Instance Method Summary collapse
-
#sequence(options) ⇒ Object
——————————————————————————.
-
#setup_app(options) ⇒ Object
—————————————————————————-.
-
#vagrant(options) ⇒ Object
—————————————————————————-.
Instance Method Details
#sequence(options) ⇒ Object
Sequence
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/legworker.rb', line 77 def sequence() input_directory = [:input_directory] output_directory = [:output_directory] file_name = [:file_name] variable_name = [: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) ⇒ Object
Setup Application & Databases
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/legworker.rb', line 36 def setup_app() = {} vagrant_file = 'config/puppet/manifests/vagrant.pp' file = File.open(vagrant_file) contents = file.read contents.gsub!('_APPLICATION_NAME_',[:application_name]) contents.gsub!('_DEV_USER_',[:dev_user]) contents.gsub!('_DEV_PASS_',[:dev_pass]) contents.gsub!('_PROD_USER_',[:prod_user]) contents.gsub!('_PROD_PASS_',[: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_",[:dev_database]) db_contents.gsub!("_PROD_DATABASE_",[:prod_database]) db_contents.gsub!('_DEV_USER_',[:dev_user]) db_contents.gsub!('_DEV_PASS_',[:dev_pass]) db_contents.gsub!('_PROD_USER_',[:prod_user]) db_contents.gsub!('_PROD_PASS_',[: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) ⇒ Object
Download Vagrant & Puppet
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/legworker.rb', line 14 def vagrant() # 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() end |