Sha256: 7a504d141e883fa5f07d6c6acd2b8b812f47ed4491636462cddbf2889720197c

Contents?: true

Size: 970 Bytes

Versions: 2

Compression:

Stored size: 970 Bytes

Contents

# frozen_string_literal: true

module ActiveSerialize
  module ClassMethods
    def _active_serialize
      ActiveSerialize.configs[name] ||= { **ActiveSerialize.configs[:default].deep_dup, final: nil, recursive: [ ], map: { } }
    end

    def to_ha(**args)
      all.to_a.map { |record| record.to_h(**args) }
    end

    def active_serialize_rmv *attrs
      _active_serialize[:rmv].concat attrs.map(&:to_sym)
    end

    def active_serialize_add *attrs, named: nil, recursive: false
      active_serialize_map attrs[0] => named if named
      _active_serialize[recursive ? :recursive : :add].concat attrs.map(&:to_sym)
    end

    def active_serialize_map **settings
      _active_serialize[:map].merge! settings
    end

    def active_serialize_keys(rmv: [ ], add: [ ])
      _active_serialize[:final] ||= column_names.map(&:to_sym) - _active_serialize[:rmv] + _active_serialize[:add]
      _active_serialize[:final] - Array(rmv) + Array(add)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_serialize-2.2.0 lib/active_serialize/class_methods.rb
active_serialize-2.1.0 lib/active_serialize/class_methods.rb