Sha256: 4ffc2c1c957aa848c6a2a424fc349441d6cfc1e57bb46b4e55bee0c49d85312b

Contents?: true

Size: 1.92 KB

Versions: 1

Compression:

Stored size: 1.92 KB

Contents

require "rubygems"
require 'yaml'
require 'environment_parser'

module Travish
  class Runner

    def help
      puts ""
      puts "Travish - emulates the OSX experience for travis."
      puts ""
      puts "          run     - Runs the .travis.yml."
      puts "          script  - Runs only the \"script\" portion of .travis.yml."
      puts ""
      puts "                                               ./"
    end

    def run
      validate
      travis_file = default_yml.merge local_travis_yml
      parser = EnvironmentParser.new(travis_file.fetch('env', {}).fetch('global', {}), ENV)

      run_commands(travis_file["before_install"], parser.environment_hash)
      run_commands(travis_file["install"], parser.environment_hash)
      run_commands(travis_file["before_script"], parser.environment_hash)
      run_commands(travis_file["script"], parser.environment_hash)
    end

    def script
      validate
      travis_file = default_yml.merge local_travis_yml
      parser = EnvironmentParser.new(travis_file.fetch('env', {}).fetch('global', {}), ENV)

      run_commands(travis_file["script"], parser.environment_hash)
    end

    # -- faffing

    def initialize(args)
      # find a command
      @params = args
      command = @params[0].to_sym rescue :help
      commands.include?(command) ? send(command.to_sym) : help
    end

    private

    def run_commands(array, environment = {})
      return if array.nil?
      array = [array] if array.is_a?(String)
      array.each do |command|
        puts "> " + command
        system(environment, command)
      end
    end

    def local_travis_yml
      YAML.load_file('.travis.yml')
    end

    def default_yml
      {}
    end

    def validate
      unless File.exists? ".travis.yml"
        puts "You need to have a `travis.yml` in this folder."
        exit
      end
    end

    def commands
      (public_methods - Object.public_methods).sort.map{ |c| c.to_sym }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
travish-1.0.0 lib/travish.rb