Sha256: cdecd96a99bb495e31a03a69a087111c559d6da54524ba44cc01a7ab9d2e74e5

Contents?: true

Size: 762 Bytes

Versions: 1

Compression:

Stored size: 762 Bytes

Contents

# frozen_string_literal: true

require 'mitake/model/attributes'
require 'mitake/model/accessor'

module Mitake
  # Provide attributes accessor
  #
  # @since 0.1.0
  # @api private
  module Model
    # @since 0.1.0
    # @api private
    def self.included(base)
      base.class_eval do
        include Attributes
        extend Accessor
      end
    end

    # Get attributes as hash
    #
    # @return [Hash] the object attributes
    #
    # @since 0.1.0
    def attributes
      self
        .class
        .attribute_names
        .map { |attr| [attr, send(attr)] }
        .reject { |_, value| value.nil? }
        .map do |attr, value|
        [attr, value.respond_to?(:attributes) ? value.attributes : value]
      end
        .to_h
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mitake-0.1.2 lib/mitake/model.rb