Skip to content

Instantly share code, notes, and snippets.

@reedlaw
Created October 31, 2013 17:21
Show Gist options
  • Save reedlaw/7253542 to your computer and use it in GitHub Desktop.
Save reedlaw/7253542 to your computer and use it in GitHub Desktop.
CRUD action interactors
class LoadLocation < Interactor
def call
@response.location = location.attributes
@response
end
def location
LocationRepository.joins(:manager)
.select("*, user_repository.name AS manager_name")
.where(account_repository_id: @request.current_account_id)
.find(@request.params[:id])
end
end
class LoadLocations < Interactor
def call
@response.locations = locations
@response
end
def locations
LocationRepository.joins(:manager)
.select("*, user_repository.name AS manager_name")
.where(account_repository_id: @request.current_account_id)
.map(&:attributes)
end
end
class SaveLocation < Interactor
def call
location = Location.new(@request.object_attributes)
if location.valid?
repo = save_repository(LocationRepository)
@response.location = repo.attributes
else
@response.location = @request.object_attributes
@response.location.errors = location.errors
end
@response
end
end
class DeleteLocation < Interactor
def call
@response = delete(LocationRepository)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment