Module: Formed::Attributes

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/formed/attributes.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#_has_attribute?(name) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/formed/attributes.rb', line 7

def _has_attribute?(name)
  attributes.key?(name)
end

#attribute_present?(attr_name) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
# File 'lib/formed/attributes.rb', line 11

def attribute_present?(attr_name)
  attr_name = attr_name.to_s
  attr_name = self.class.attribute_aliases[attr_name] || attr_name
  value = _read_attribute(attr_name)
  !value.nil? && !(value.respond_to?(:empty?) && value.empty?)
end

#attributes_with_valuesObject



32
33
34
# File 'lib/formed/attributes.rb', line 32

def attributes_with_values
  attributes.select { |_, v| v.present? }
end

#column_for_attribute(attr) ⇒ Object



22
23
24
# File 'lib/formed/attributes.rb', line 22

def column_for_attribute(attr)
  model.column_for_attribute(attr)
end

#has_attribute?(attr_name) ⇒ Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/formed/attributes.rb', line 26

def has_attribute?(attr_name)
  attr_name = attr_name.to_s
  attr_name = self.class.attribute_aliases[attr_name] || attr_name
  @attributes.key?(attr_name)
end

#type_for_attribute(attr) ⇒ Object



18
19
20
# File 'lib/formed/attributes.rb', line 18

def type_for_attribute(attr)
  self.class.attribute_types[attr].type
end