version: 2
references:
  unit: &unit
    run:
      name: Run test suite
      command: bundle exec rake
  restore: &restore
    restore_cache:
      keys:
        - v1-dependencies-{{ checksum "Gemfile.lock" }}
        # fallback to using the latest cache if no exact match is found
        - v1-dependencies-
  bundle: &bundle
    run:
      name: install dependencies
      command: |
        bundle install --jobs=4 --retry=3 --path vendor/bundle
  save: &save
    save_cache:
      paths:
        - ./vendor/bundle
      key: v1-dependencies-{{ checksum "Gemfile.lock" }}
jobs:
  "ruby-2.5":
    docker:
      - image: circleci/ruby:2.5
      - image: circleci/redis:4.0
    steps:
      - checkout
      - <<: *restore
      - <<: *bundle
      - <<: *save
      - <<: *unit
  "ruby-2.6":
    docker:
      - image: circleci/ruby:2.6
      - image: circleci/redis:4.0
    steps:
      - checkout
      - <<: *restore
      - <<: *bundle
      - <<: *save
      - <<: *unit
  "jruby":
    docker:
      - image: circleci/jruby:latest
      - image: circleci/redis:4.0
    steps:
      - checkout
      - <<: *restore
      - <<: *bundle
      - <<: *save
      - <<: *unit

workflows:
  version: 2
  build:
    jobs:
      - "ruby-2.5"
      - "ruby-2.6"
      - "jruby"
