Module: PGTrunk::Operation::Attributes

Extended by:
ActiveSupport::Concern
Includes:
ActiveModel::Attributes, ActiveModel::Model
Included in:
PGTrunk::Operation
Defined in:
lib/pg_trunk/core/operation/attributes.rb

Overview

Define getters/setters for the operation attributes

Instance Method Summary collapse

Instance Method Details

#attributesObject Also known as: to_h

The hash of the operation’s serialized attributes



71
72
73
74
75
# File 'lib/pg_trunk/core/operation/attributes.rb', line 71

def attributes
  super.to_h do |k, v|
    [k.to_sym, self.class.attribute_types[k].serialize(v)]
  end
end

#initialize(**opts) ⇒ Object



59
60
61
62
63
64
65
66
67
68
# File 'lib/pg_trunk/core/operation/attributes.rb', line 59

def initialize(**opts)
  # enable aliases during the initialization
  self.class.attr_aliases.each do |a, n|
    opts[n] = opts.delete(a) if opts.key?(a)
  end
  # ignore unknown attributes (to simplify calls of `#invert`)
  opts = opts.slice(*self.class.attribute_names.map(&:to_sym))

  super(**opts)
end