Module: Atatus::Fields::InstanceMethods

Defined in:
lib/atatus/fields.rb

Instance Method Summary collapse

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
65
# File 'lib/atatus/fields.rb', line 58

def empty?
  self.class.schema.each do |key, field|
    next if send(key).nil?
    return false
  end

  true
end

#initialize(**attrs) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/atatus/fields.rb', line 46

def initialize(**attrs)
  schema.each do |key, field|
    send(:"#{key}=", field.default)
  end

  attrs.each do |key, value|
    send(:"#{key}=", value)
  end

  super()
end

#to_hObject



67
68
69
70
71
# File 'lib/atatus/fields.rb', line 67

def to_h
  schema.each_with_object({}) do |(key, field), hsh|
    hsh[key] = send(key)
  end
end