Sha256: 325178bf69469303e91f637ac8158a46500a55f1f37bf2f9f8a40a5d6b383dc7

Contents?: true

Size: 1.23 KB

Versions: 23

Compression:

Stored size: 1.23 KB

Contents

require 'pathway/rspec/matchers/field_list_helpers'

module Pathway
  module Rspec
    module FormSchemaHelpers
      include FieldListHelpers

      def rules
        @form.rules
      end

      def not_defined_list
        "#{as_list(not_defined)} #{were_was(not_defined)} not defined" if not_defined.any?
      end

      def required
        @required ||= @fields.select { |field| required?(field) }
      end

      def optional
        @optional ||= @fields.select { |field| optional?(field) }
      end

      def not_required
        @not_required ||= defined - required
      end

      def not_optional
        @not_required ||= defined - optional
      end

      def not_defined
        @not_defined ||= @fields - defined
      end

      def defined
        @defined ||= @fields & rules.keys
      end

      def optional?(field)
        if rules[field]&.type == :implication
          left = rules[field].left

          left.type == :predicate && left.name == :key? && left.args.first == field
        end
      end

      def required?(field)
        if rules[field]&.type == :and
          left = rules[field].left

          left.type == :predicate && left.name == :key? && left.args.first == field
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
pathway-0.10.0 lib/pathway/rspec/matchers/form_schema_helpers.rb
pathway-0.9.1 lib/pathway/rspec/matchers/form_schema_helpers.rb
pathway-0.9.0 lib/pathway/rspec/matchers/form_schema_helpers.rb
pathway-0.8.0 lib/pathway/rspec/matchers/form_schema_helpers.rb
pathway-0.7.0 lib/pathway/rspec/matchers/form_schema_helpers.rb
pathway-0.6.2 lib/pathway/rspec/matchers/form_schema_helpers.rb
pathway-0.6.1 lib/pathway/rspec/matchers/form_schema_helpers.rb
pathway-0.6.0 lib/pathway/rspec/matchers/form_schema_helpers.rb
pathway-0.5.1 lib/pathway/rspec/matchers/form_schema_helpers.rb
pathway-0.5.0 lib/pathway/rspec/matchers/form_schema_helpers.rb
pathway-0.4.0 lib/pathway/rspec/matchers/form_schema_helpers.rb
pathway-0.0.20 lib/pathway/rspec/matchers/form_schema_helpers.rb
pathway-0.0.19 lib/pathway/rspec/matchers/form_schema_helpers.rb
pathway-0.0.18 lib/pathway/rspec/matchers/form_schema_helpers.rb
pathway-0.0.17 lib/pathway/rspec/matchers/form_schema_helpers.rb
pathway-0.0.16 lib/pathway/rspec/matchers/form_schema_helpers.rb
pathway-0.0.15 lib/pathway/rspec/matchers/form_schema_helpers.rb
pathway-0.0.14 lib/pathway/rspec/matchers/form_schema_helpers.rb
pathway-0.0.13 lib/pathway/rspec/matchers/form_schema_helpers.rb
pathway-0.0.12 lib/pathway/rspec/matchers/form_schema_helpers.rb