Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igorkasyanchuk/c23c1cb6218a43b98a1dca0af08dac9e to your computer and use it in GitHub Desktop.
Save igorkasyanchuk/c23c1cb6218a43b98a1dca0af08dac9e to your computer and use it in GitHub Desktop.
x.rb
## ----
settings = DashboardSettings.new(user: current_user)
card = settings.card(params[:id])
json: card.to_json
component = DashboardComponent.new(user: current_user) # inside DashboardSettings
json: component.to_json
## ----
class DashboardSettings
delegate :positions, to: :company_presenter
delegate :project, to: :company_presenter
def initiaze(user: user)
@user = user
@settings = user.dashboard_settings
@company_presenter = CompanyPresenter.new(user.company)
end
def cards
dashboard_settings.fetch(:cards, {}).collect |card_hash|
BaseCard.build(card_hash, provider: self)
end
end
def card(id)
BaseCard.build(dashboard_settings.fetch(:cards, {})[id], self)
end
end
class CardComposer
def initializer(hash, provider:)
@hash = ...
@provider = provider
end
def data
{
positions: parent.positions
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment