Sha256: b2ce5740b533e28dfec8856c3c60ff683eee1858012e74b39dce3c313d6ea76c

Contents?: true

Size: 1019 Bytes

Versions: 1

Compression:

Stored size: 1019 Bytes

Contents

module ErrandBoy
  class Brain
    def initialize
      @git = Git.new(Dir.pwd)
      @requests = requests
    end

    def command
      case @git.branch
      when /master/ then run
      when /.*request.*/ then validate
      end
    end

    def run
      @requests.each do |request|
        gateway = Gateway.build(request)
        csv = CSV.build(request)

        gateway.call
        next if processed?(gateway, csv)

        csv.push
        request.delete
        @git.commit "[auto][ci skip] add request to index"
        @git.push
      end
    end

    def validate
      @requests.each do |request|
        Validator.build(request).run
        request.rename

        @git.commit '[auto][ci skip] rename request file'
        @git.push
      end
    end

    private

    def requests
      entries.map {|path| Request.new(path) }
    end

    def entries
      Dir.glob("#{Request.dir}/*.toml").sort
    end

    def processed?(gateway, csv)
      gateway.processed? && csv.duplicated?
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
errand-boy-0.1.0 lib/errand_boy/brain.rb