-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4221 from alphagov/content-item-model
Convert content_item from simple response to Model
- Loading branch information
Showing
3 changed files
with
29 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class ContentItem | ||
attr_reader :content_store_response, :body, :image, :description, :document_type, :title, :base_path, :locale | ||
|
||
def initialize(content_store_response) | ||
@content_store_response = content_store_response | ||
@body = content_store_response.dig("details", "body") | ||
@image = content_store_response.dig("details", "image") | ||
@description = content_store_response["description"] | ||
@document_type = content_store_response["document_type"] | ||
@title = content_store_response["title"] | ||
@base_path = content_store_response["base_path"] | ||
@locale = content_store_response["locale"] | ||
end | ||
|
||
delegate :to_h, to: :content_store_response | ||
delegate :cache_control, to: :content_store_response | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class ContentItemFactory | ||
def self.build(content_hash) | ||
content_item_class(content_hash).new(content_hash) | ||
end | ||
|
||
def self.content_item_class(_content_hash) | ||
ContentItem | ||
end | ||
end |