Module: Hashie::Extensions::KeyConflictWarning

Included in:
Mash
Defined in:
lib/hashie/extensions/key_conflict_warning.rb

Defined Under Namespace

Classes: CannotDisableMashWarnings

Instance Method Summary collapse

Instance Method Details

#disable_warnings(*method_keys) ⇒ void

This method returns an undefined value.

Disable the logging of warnings based on keys conflicting keys/methods


17
18
19
20
21
22
23
24
25
26
# File 'lib/hashie/extensions/key_conflict_warning.rb', line 17

def disable_warnings(*method_keys)
  raise CannotDisableMashWarnings if self == Hashie::Mash
  if method_keys.any?
    disabled_warnings.concat(method_keys).tap(&:flatten!).uniq!
  else
    disabled_warnings.clear
  end

  @disable_warnings = true
end

#disable_warnings?(method_key = nil) ⇒ Boolean

Checks whether this class disables warnings for conflicting keys/methods

Returns:

  • (Boolean)

32
33
34
35
# File 'lib/hashie/extensions/key_conflict_warning.rb', line 32

def disable_warnings?(method_key = nil)
  return disabled_warnings.include?(method_key) if disabled_warnings.any? && method_key
  @disable_warnings ||= false
end

#disabled_warningsBoolean

Returns an array of methods that this class disables warnings for.

Returns:

  • (Boolean)

41
42
43
# File 'lib/hashie/extensions/key_conflict_warning.rb', line 41

def disabled_warnings
  @_disabled_warnings ||= []
end

#inherited(subclass) ⇒ void

This method returns an undefined value.

Inheritance hook that sets class configuration when inherited.


49
50
51
52
# File 'lib/hashie/extensions/key_conflict_warning.rb', line 49

def inherited(subclass)
  super
  subclass.disable_warnings(disabled_warnings) if disable_warnings?
end