Sha256: b39b86b6bbf68f6b529f17ac721f78663332407340234e7e495e44a70ba7528b

Contents?: true

Size: 755 Bytes

Versions: 1

Compression:

Stored size: 755 Bytes

Contents

require 'digest/md5'

require 'mayu/relation'

module Mayu
  User = Struct.new(:key, :name, :aliases, :gravatar_email, keyword_init: true) do
    include Mayu::Relation

    def self.load(obj)
      new(**obj)
    end

    def associations
      devices.map(&:association).compact
    end

    def associated_device_kinds
      associations.map(&:device).compact.map(&:kind).uniq
    end

    def devices_key
      key
    end

    def gravatar_hash
      return nil unless gravatar_email
      @gravatar_hash ||= Digest::MD5.hexdigest gravatar_email.strip.downcase
    end

    relates :devices

    def as_json
      {
        key: key,
        name: name,
        aliases: aliases || [],
        gravatar_hash: gravatar_hash,
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mayu-0.1.0.beta1 lib/mayu/user.rb