Class: ActionFacade::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/action_facade/base.rb

Overview

Action Facade Base

This is only a base class for extract data from input (payload). This can be inherited to another class and you can implement some mothods for obtaining data. In Ruby on Rails, you can implemented Active Record query methods to the inherited class. For example

class Mypage::IndexFacade < ActionFacade::Base
  attr_reader :current_user

  def initialize(payload)
    @current_user = payload[:current_user]
  end

  def active_users
    @active_users ||= User.active.order(login_at: :desc).limit(10)
  end

  def messages
    @messages ||= current_user.messages.order(created_at: :desc).limit(10)
  end
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload = {}) ⇒ Base

Initialize with payload



33
34
35
# File 'lib/action_facade/base.rb', line 33

def initialize(payload = {})
  @payload = payload
end

Instance Attribute Details

#payloadObject (readonly)

Returns the value of attribute payload.



30
31
32
# File 'lib/action_facade/base.rb', line 30

def payload
  @payload
end