Sha256: 219f093b287ef8bae22ad46bf853d14229596a6bea00cca282ab75ce2091b339

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

require 'growi/client/model/growi_model'

# Growi User model class
class GrowiUser < GrowiModelBase
  attr_reader :_id, :email, :username, :name,
              :admin, :createdAt, :status, :lang, :isGravatarEnabled

  # Constractor
  # @param [Hash] User model shown as hash
  # @todo Except running register method always called parse method.
  def initialize(params = {})
    init_params = {
      _id: nil, email: nil, username: nil, name: '',
      admin: false, createdAt: '', status: 0, lang: '', isGravatarEnabled: false
    }

    params = init_params.merge(params.map { |k,v| [k.to_sym, v] }.to_h)
    if (params[:_id].nil?)
      raise ArgumentError.new('Parameter _id is required.')
    end

    GrowiModelFactory.instance.register({
      user_createdAt: Proc.new { |date_str| !date_str.nil? && date_str != "" ? DateTime.parse(date_str) : "" },
    })
    maked_params = {}
    params.each do |k,v|
      maker = GrowiModelFactory.instance.maker('user_' + k.to_s)
      maked_params[k] = maker.call(v)
    end
    super(maked_params)
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
growi-client-1.0.1 lib/growi/client/model/growi_user.rb
growi-client-1.0.0 lib/growi/client/model/growi_user.rb