Sha256: c093b8deecc1a95b5a329e949305ba1c8f72f1df0c07f73abddd6f304a07c94f

Contents?: true

Size: 782 Bytes

Versions: 8

Compression:

Stored size: 782 Bytes

Contents

module Cms

  # Wrap User for JSON formatting.
  class UserPresenter

    attr_reader :resource

    def initialize(user)
      @resource = user
    end

    def as_json(_options = nil)
      basic_hash.merge Cms.user_key_field.to_sym  => login,
                       Cms.user_name_field.to_sym => full_name
    end

    def basic_hash
      {
        id:           id,
        login:        login,
        full_name:    full_name,
        is_logged_in: logged_in?,
        guest:        guest?,
      }
    end

    def full_name
      resource.send Cms.user_name_field
    end

    def login
      resource.send Cms.user_key_field
    end

    def id
      resource.try :id
    end

    def guest?
      resource.guest?
    end

    def logged_in?
      !guest?
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
browsercms-artirix-4.0.4 app/presenters/cms/user_presenter.rb
browsercms-artirix-4.0.3.3 app/presenters/cms/user_presenter.rb
browsercms-artirix-4.0.3.2 app/presenters/cms/user_presenter.rb
browsercms-artirix-4.0.3.1 app/presenters/cms/user_presenter.rb
browsercms-artirix-4.0.3 app/presenters/cms/user_presenter.rb
browsercms-artirix-4.0.2 app/presenters/cms/user_presenter.rb
browsercms-artirix-4.0.1.1 app/presenters/cms/user_presenter.rb
browsercms-artirix-4.0.0.rc1.art4 app/presenters/cms/user_presenter.rb