-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
91 additions
and
5 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,19 @@ | ||
# frozen_string_literal: true | ||
|
||
require "json" | ||
|
||
module WhatsOpt | ||
class MdajsonGenerator | ||
|
||
def initialize(mda) | ||
@mda = mda | ||
end | ||
|
||
def generate | ||
as_json = AnalysisAttrsSerializer.new(@mda).as_json | ||
|
||
as_json.to_json | ||
end | ||
|
||
end | ||
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
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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class AnalysisAttrsSerializer < ActiveModel::Serializer | ||
attributes :name | ||
|
||
has_many :disciplines, key: :disciplines_attributes, serializer: DisciplineAttrsSerializer | ||
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,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class DisciplineAttrsSerializer < ActiveModel::Serializer | ||
attributes :name, :type | ||
|
||
has_many :variables, key: :variables_attributes | ||
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
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class Api::V1::ExportsControllerTest < ActionDispatch::IntegrationTest | ||
setup do | ||
@auth_headers = { "Authorization" => "Token " + TEST_API_KEY } | ||
@mda = analyses(:cicav) | ||
end | ||
|
||
test "should dump analysis as json" do | ||
get api_v1_mda_exports_new_url(@mda, format: :mdajson), as: :json, headers: @auth_headers | ||
assert_response :success | ||
resp = JSON.parse(response.body) | ||
end | ||
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 @@ | ||
{"name":"CICAV","disciplines_attributes":[{"name":"__DRIVER__","type":"null_driver","variables_attributes":[{"name":"obj","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"x1","io_mode":"out","shape":"1","type":"Float","active":true,"parameter_attributes":{"init":"3.14","lower":"1","upper":"10"},"distributions_attributes":[]},{"name":"y2","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"z","io_mode":"out","shape":"(2,)","type":"Float","active":true,"parameter_attributes":{"init":"3.14","lower":"1","upper":"10"},"distributions_attributes":[]}]},{"name":"Geometry","type":"analysis","variables_attributes":[{"name":"obj","io_mode":"out","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"x1","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"ya","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"yg","io_mode":"out","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"z","io_mode":"in","shape":"(2,)","type":"Float","active":true,"distributions_attributes":[]}]},{"name":"Aerodynamics","type":"analysis","variables_attributes":[{"name":"y2","io_mode":"out","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"ya","io_mode":"out","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"yg","io_mode":"in","shape":"1","type":"Float","active":true,"distributions_attributes":[]},{"name":"z","io_mode":"in","shape":"(2,)","type":"Float","active":true,"distributions_attributes":[]}]},{"name":"Propulsion","type":"analysis","variables_attributes":[]}]} |
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,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class MdajsonGeneratorTest < ActiveSupport::TestCase | ||
def setup | ||
@mda = analyses(:cicav) | ||
@jsongen = WhatsOpt::MdajsonGenerator.new(@mda) | ||
end | ||
|
||
test "should generate mda json" do | ||
content = @jsongen.generate | ||
expected = sample_file("cicav_mda.json").read | ||
assert_equal expected, content | ||
end | ||
end |