File: plugin.rb

package info (click to toggle)
ruby-cucumber-wire 8.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 140 kB
  • sloc: ruby: 499; makefile: 4
file content (41 lines) | stat: -rw-r--r-- 1,208 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true

require 'cucumber/wire/connections'
require 'cucumber/wire/add_hooks_filter'
require 'cucumber/step_match_search'

module Cucumber
  module Wire
    class Plugin
      attr_reader :config, :registry
      private :config, :registry

      def self.installed?
        @@installed ||= false
      end

      def initialize(config, registry)
        @config = config
        @registry = registry
      end

      def install
        connections = Connections.new(wire_files.map { |f| create_connection(f) }, config, registry)
        config.filters << Filters::ActivateSteps.new(StepMatchSearch.new(connections.method(:step_matches), @config), @config)
        config.filters << AddHooksFilter.new(connections) unless @config.dry_run?
        config.register_snippet_generator Snippet::Generator.new(connections)

        @@installed = true
      end

      def create_connection(wire_file)
        Connection.new(Configuration.from_file(wire_file))
      end

      def wire_files
        # TODO: change Cucumber's config object to allow us to get this information
        config.send(:require_dirs).map { |dir| Dir.glob("#{dir}/**/*.wire") }.flatten
      end
    end
  end
end