version: '2.1'

executors:
  ruby:
    parameters:
      tag:
        type: string
    docker:
      - image: ruby:<< parameters.tag >>

jobs:
  build:
    parameters:
       ruby-version:
         type: string
    executor:
      name: ruby
      tag: << parameters.ruby-version >>
    steps:
    - checkout
    - run:
        name: Which bundler?
        command: bundle -v
    - run:
        command: bundle install --path vendor/bundle
    - run:
        name: test
        command: bundle exec rake test
  lint:
    parameters:
       ruby-version:
         type: string
    executor:
      name: ruby
      tag: << parameters.ruby-version >>
    steps:
    - checkout
    - run:
        name: Which bundler?
        command: bundle -v
    - run:
        command: bundle install --path vendor/bundle
    - run:
        name: rubocop
        command: bundle exec rubocop lib/

workflows:
  build:
    jobs:
      - lint:
          name: 'lint'
          ruby-version: '3.0.3'
      - build:
          name: 'ruby-2.7'
          ruby-version: '2.7.5'
          requires:
            - 'lint'
      - build:
          name: 'ruby-3.0'
          ruby-version: '3.0.3'
          requires:
            - 'lint'
      - build:
          name: 'ruby-3.1'
          ruby-version: '3.1.0-preview1'
          requires:
            - 'lint'
