Module: Mobility::Attributes::ClassMethods

Defined in:
lib/mobility/attributes.rb

Instance Method Summary collapse

Instance Method Details

#mobility_attribute?(name) ⇒ Boolean

Return true if attribute name is translated on this model.

Parameters:

  • Attribute (String, Symbol)

    name

Returns:

  • (Boolean)

287
288
289
# File 'lib/mobility/attributes.rb', line 287

def mobility_attribute?(name)
  mobility_attributes.include?(name.to_s)
end

#mobility_attributesArray<String> Also known as: translated_attribute_names

Return translated attribute names on this model.

Returns:

  • (Array<String>)

    Attribute names


280
281
282
# File 'lib/mobility/attributes.rb', line 280

def mobility_attributes
  mobility_modules.map(&:names).flatten.uniq
end

#mobility_backend_class(name) ⇒ Class

Return backend class for a given attribute name.

Parameters:

  • Name (Symbol, String)

    of attribute

Returns:

  • (Class)

    Backend class


298
299
300
301
# File 'lib/mobility/attributes.rb', line 298

def mobility_backend_class(name)
  @backends ||= BackendsCache.new(self)
  @backends[name.to_sym]
end

#mobility_modulesArray<Mobility::Attributes>

Return all Mobility::Attribute module instances from among ancestors of this model.

Returns:


274
275
276
# File 'lib/mobility/attributes.rb', line 274

def mobility_modules
  ancestors.grep(Attributes)
end