Created
April 18, 2017 14:43
-
-
Save igorkasyanchuk/c23c1cb6218a43b98a1dca0af08dac9e to your computer and use it in GitHub Desktop.
x.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## ---- | |
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