Module: Servactory::TestKit::Rspec::Matchers::Concerns::AttributeDataAccess::InstanceMethods

Defined in:
lib/servactory/test_kit/rspec/matchers/concerns/attribute_data_access.rb

Overview

Instance methods added by this concern.

Instance Method Summary collapse

Instance Method Details

#attribute_dataHash

Returns the attribute definition data hash.

Returns:

  • (Hash)

    The attribute data from context



68
69
70
# File 'lib/servactory/test_kit/rspec/matchers/concerns/attribute_data_access.rb', line 68

def attribute_data
  context.attribute_data
end

#attribute_nameSymbol?

Returns The attribute name from context.

Returns:

  • (Symbol, nil)

    The attribute name from context



57
# File 'lib/servactory/test_kit/rspec/matchers/concerns/attribute_data_access.rb', line 57

def attribute_name = context&.attribute_name

#attribute_typeSymbol?

Returns The attribute type from context.

Returns:

  • (Symbol, nil)

    The attribute type from context



54
# File 'lib/servactory/test_kit/rspec/matchers/concerns/attribute_data_access.rb', line 54

def attribute_type = context&.attribute_type

#attribute_type_pluralSymbol?

Returns The pluralized attribute type from context.

Returns:

  • (Symbol, nil)

    The pluralized attribute type from context



60
# File 'lib/servactory/test_kit/rspec/matchers/concerns/attribute_data_access.rb', line 60

def attribute_type_plural = context&.attribute_type_plural

#described_classClass?

Returns The Servactory service class from context.

Returns:

  • (Class, nil)

    The Servactory service class from context



51
# File 'lib/servactory/test_kit/rspec/matchers/concerns/attribute_data_access.rb', line 51

def described_class = context&.described_class

#fetch_option(key, default = nil) ⇒ Object

Fetches a specific option from attribute data.

Parameters:

  • key (Symbol)

    The option key to fetch

  • default (Object, nil) (defaults to: nil)

    Default value if key not present

Returns:

  • (Object)

    The option value or default



77
78
79
# File 'lib/servactory/test_kit/rspec/matchers/concerns/attribute_data_access.rb', line 77

def fetch_option(key, default = nil)
  attribute_data.fetch(key, default)
end

#i18n_root_keyString?

Returns The i18n root key from context.

Returns:

  • (String, nil)

    The i18n root key from context



63
# File 'lib/servactory/test_kit/rspec/matchers/concerns/attribute_data_access.rb', line 63

def i18n_root_key = context&.i18n_root_key

#option_present?(key) ⇒ Boolean

Checks if an option is present and has a meaningful value.

Returns false if the key doesn’t exist, or if the value is nil or empty (for collections).

Parameters:

  • key (Symbol)

    The option key to check

Returns:

  • (Boolean)

    True if option exists with non-empty value



88
89
90
91
92
93
# File 'lib/servactory/test_kit/rspec/matchers/concerns/attribute_data_access.rb', line 88

def option_present?(key)
  return false unless attribute_data.key?(key)

  value = attribute_data[key]
  !value.nil? && (!value.respond_to?(:empty?) || !value.empty?)
end