Skip to content

Commit a248eb5

Browse files
committed
Simplify code and make fetch function private
1 parent 0cee1ec commit a248eb5

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

app/presenters/api/v2/plan_presenter.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ module Api
44
module V2
55
# Helper class for the API V2 project / DMP
66
class PlanPresenter
7-
attr_reader :data_contact, :contributors, :costs
7+
attr_reader :data_contact, :contributors, :costs, :complete_plan_data
88

9-
def initialize(plan:)
9+
def initialize(plan:, complete: false)
1010
@contributors = []
1111
return unless plan.present?
1212

@@ -22,6 +22,8 @@ def initialize(plan:)
2222
end
2323

2424
@costs = plan_costs(plan: @plan)
25+
26+
@complete_plan_data = fetch_all_q_and_a if complete
2527
end
2628

2729
# Extract the ARK or DOI for the DMP OR use its URL if none exists
@@ -35,6 +37,8 @@ def identifier
3537
Identifier.new(value: Rails.application.routes.url_helpers.api_v2_plan_url(@plan))
3638
end
3739

40+
private
41+
3842
# Fetch all questions and answers from a plan, regardless of theme
3943
def fetch_all_q_and_a
4044
return [] unless @plan.questions.present?
@@ -51,8 +55,6 @@ def fetch_all_q_and_a
5155
end
5256
end
5357

54-
private
55-
5658
# Retrieve the answers that have the Budget theme
5759
def plan_costs(plan:)
5860
theme = Theme.where(title: 'Cost').first

app/views/api/v2/plans/_show.json.jbuilder

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
json.schema 'https://github.com/RDA-DMP-Common/RDA-DMP-Common-Standard/tree/master/examples/JSON/JSON-schema/1.0'
66

7-
presenter = Api::V2::PlanPresenter.new(plan: plan)
7+
presenter = Api::V2::PlanPresenter.new(plan: plan, complete: @complete)
88

99
# Note the symbol of the dmproadmap json object
1010
# nested in extensions which is the container for the json template object, etc.
@@ -71,7 +71,7 @@ unless @minimal
7171

7272
if @complete
7373
json.complete_plan do
74-
q_and_a = presenter.send(:fetch_all_q_and_a)
74+
q_and_a = presenter.complete_plan_data
7575
next if q_and_a.blank?
7676

7777
json.array! q_and_a do |item|

0 commit comments

Comments
 (0)