Sha256: 4bddada216dba718dd302edbeec6356f3b4f2c189fa0c7eb5fa58210f2d8120c

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

require 'mayday/reader'
require 'colored'

module Mayday
  class UserDefinitions

    def initialize(mayday_file_path)
      @mayday_file_path = mayday_file_path
    end

    def init
      if File.exist?(@mayday_file_path)
        puts "#{@mayday_file_path} already exists".red
        abort
      else
        File.open(@mayday_file_path, 'w') do |file|
          file.write <<-CODE
xcode_proj '#{nearby_xcodeproj}'

warning_regex 'TODO:', /\\s+\\/\\/\\s?TODO:/
          CODE
          puts "#{@mayday_file_path} created".green
        end
      end
    end

    def up
      mayday_file do |file|
        Reader.new(file).to_target_integrator.integrate
      end
    end

    def down
      mayday_file do |file|
        Reader.new(file).to_target_integrator.deintegrate
      end
    end

    def benchmark
      mayday_file do |file|
        Reader.new(file).to_target_integrator.benchmark
      end
    end
    
    def run
      mayday_file do |file|
        Reader.new(file).to_target_integrator.run
      end
    end

    def mayday_file
      unless File.exist?(@mayday_file_path)
        puts "No #{@mayday_file_path} found".red
        abort
      end

      file = File.open(@mayday_file_path)
      yield file
      file.close
    end
    private :mayday_file

    def nearby_xcodeproj
      nearby = Dir["**/*.xcodeproj"].reject { |xcodeproj_path| xcodeproj_path =~ /Pods\//}.first
      puts "Xcodeproj couldn't be found".yellow unless nearby
      nearby
    end
    private :nearby_xcodeproj

  end 
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mayday-0.2.0 lib/mayday/user_definitions.rb