Class: GovukConditionalContentItemLoader
- Inherits:
-
Object
- Object
- GovukConditionalContentItemLoader
- Defined in:
- lib/govuk_content_item_loader/govuk_conditional_content_item_loader.rb
Instance Attribute Summary collapse
-
#base_path ⇒ Object
readonly
Returns the value of attribute base_path.
-
#content_store_client ⇒ Object
readonly
Returns the value of attribute content_store_client.
-
#publishing_api_client ⇒ Object
readonly
Returns the value of attribute publishing_api_client.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #can_load_from_graphql? ⇒ Boolean
-
#initialize(request:, content_store_client: GdsApi.content_store, publishing_api_client: GdsApi.publishing_api, base_path: nil) ⇒ GovukConditionalContentItemLoader
constructor
A new instance of GovukConditionalContentItemLoader.
- #load ⇒ Object
Constructor Details
#initialize(request:, content_store_client: GdsApi.content_store, publishing_api_client: GdsApi.publishing_api, base_path: nil) ⇒ GovukConditionalContentItemLoader
Returns a new instance of GovukConditionalContentItemLoader.
4 5 6 7 8 9 |
# File 'lib/govuk_content_item_loader/govuk_conditional_content_item_loader.rb', line 4 def initialize(request:, content_store_client: GdsApi.content_store, publishing_api_client: GdsApi.publishing_api, base_path: nil) @content_store_client = content_store_client @publishing_api_client = publishing_api_client @request = request @base_path = base_path || request&.path end |
Instance Attribute Details
#base_path ⇒ Object (readonly)
Returns the value of attribute base_path.
2 3 4 |
# File 'lib/govuk_content_item_loader/govuk_conditional_content_item_loader.rb', line 2 def base_path @base_path end |
#content_store_client ⇒ Object (readonly)
Returns the value of attribute content_store_client.
2 3 4 |
# File 'lib/govuk_content_item_loader/govuk_conditional_content_item_loader.rb', line 2 def content_store_client @content_store_client end |
#publishing_api_client ⇒ Object (readonly)
Returns the value of attribute publishing_api_client.
2 3 4 |
# File 'lib/govuk_content_item_loader/govuk_conditional_content_item_loader.rb', line 2 def publishing_api_client @publishing_api_client end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
2 3 4 |
# File 'lib/govuk_content_item_loader/govuk_conditional_content_item_loader.rb', line 2 def request @request end |
Instance Method Details
#can_load_from_graphql? ⇒ Boolean
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/govuk_content_item_loader/govuk_conditional_content_item_loader.rb', line 17 def can_load_from_graphql? return false unless request return false if draft_host? return force_graphql_param unless force_graphql_param.nil? schema_name = content_item_from_content_store["schema_name"] return false unless graphql_schema_allowed?(schema_name) within_graphql_traffic_rate?(schema_name) end |
#load ⇒ Object
11 12 13 14 15 |
# File 'lib/govuk_content_item_loader/govuk_conditional_content_item_loader.rb', line 11 def load return content_item_from_content_store unless can_load_from_graphql? content_item_from_graphql || content_item_from_content_store end |