class Shoulda::Matchers::ActiveRecord::EncryptMatcher

@private

def class_name

def class_name
  @subject.class.name
end

def description

def description
  "encrypt :#{@attribute}"
end

def deterministic(deterministic)

def deterministic(deterministic)
  with_option(:deterministic, deterministic)
end

def downcase(downcase)

def downcase(downcase)
  with_option(:downcase, downcase)
end

def encrypted_attribute_scheme

def encrypted_attribute_scheme
  @subject.class.type_for_attribute(@attribute).scheme
end

def encrypted_attributes

def encrypted_attributes
  @_encrypted_attributes ||= @subject.class.encrypted_attributes || []
end

def encrypted_attributes_included?

def encrypted_attributes_included?
  if encrypted_attributes.include?(@attribute)
    true
  else
    @failure_message = "Expected to #{description} of #{class_name}, but it did not"
    false
  end
end

def ignore_case(ignore_case)

def ignore_case(ignore_case)
  with_option(:ignore_case, ignore_case)
end

def initialize(attribute)

def initialize(attribute)
  @attribute = attribute.to_sym
  @options = {}
end

def matches?(subject)

def matches?(subject)
  @subject = subject
  result = encrypted_attributes_included? &&
           options_correct?(
             :deterministic,
             :downcase,
             :ignore_case,
           )
  if result
    @failure_message_when_negated = "Did not expect to #{description} of #{class_name}"
    if @options.present?
      @failure_message_when_negated += "
      @failure_message_when_negated += @options.map { |opt, expected|
        ":#{opt} option as ‹#{expected}›"
      }.join(' and
    end
    @failure_message_when_negated += ",
id"
  end
  result
end

def options_correct?(*opts)

def options_correct?(*opts)
  opts.all? do |opt|
    next true unless @options.key?(opt)
    expected = @options[opt]
    actual = encrypted_attribute_scheme.send("#{opt}?")
    next true if expected == actual
    @failure_message = "Expected to #{description} of #{class_name} using :#{opt} option
pected}›, but got ‹#{actual}›"
    false
  end
end

def with_option(option_name, value)

def with_option(option_name, value)
  @options[option_name] = value
  self
end