Sha256: 860a503d58cebe33197e45bb3e731aa32753a074b94ce90ba675c7dd5b468845

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

require "guard"
require "guard/guard"
require "active_support/concern"

module RoSupport
  module RoGuard
    def start
      commands = Pry::CommandSet.new do
        block_command "install" do |*args|
          system "rake install"
          output.out "nimabi"
        end
      end

      Pry::Commands.import commands
    end

    def run_on_modifications(paths)
      @paths = paths
      handle('Guardfile') do
        bash "bundle exec guard"
      end

      bash "rake install"
    end

    def paths
      @paths.flatten! if @paths.respond_to?(:flatten!)
      @paths.uniq! if @paths.respond_to?(:uniq!)
      @paths ||= []
    end

    def notify(msg)
      puts msg
      Notifier.notify msg
    end

    def handle(file, &blk)
      #puts "Handling #{paths.flatten}"
      r = paths.flatten.grep /#{file}$/
      unless r.empty?
        blk.call
      end
    end

    extend ActiveSupport::Concern

    included do
      def_meth "bash" do |*cmds|
        Kernel.system cmds.flatten.join(" && ")
      end
    end

    module ClassMethods
      def def_meth(meth, &blk)
        define_singleton_method meth, &blk
        define_method meth, &blk
        Pry::Command.send :define_method, meth, &blk
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ro_support-0.0.7 lib/ro_support/ro_guard.rb