Class: UnimatrixCLI::Archivist::Blueprint::CreateCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/unimatrix_cli/archivist/blueprint/create_command.rb

Instance Method Summary collapse

Methods inherited from Command

available_commands, descendants, #initialize, #read_file, #validate, #validate_collection, #write

Methods included from UnimatrixParser

included

Constructor Details

This class inherits a constructor from UnimatrixCLI::Command

Instance Method Details

#executeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/unimatrix_cli/archivist/blueprint/create_command.rb', line 11

def execute
  contents = read_file( @options[ :file ] )

  if contents.respond_to?( :each )

    requests = build_requests( contents )

    blueprint_response = make_resource_request( requests[ :blueprints ], 'blueprints' )

    if blueprint_response[ 'errors' ].nil?

      requests[ :blueprint_attributes ] = attach_blueprint_ids_to_attributes(
        blueprint_response[ 'blueprints' ],
        requests[ :blueprint_attributes ]
      )

      blueprint_attribute_response =
        make_resource_request( requests[ :blueprint_attributes ], 'blueprint_attributes' )

      if blueprint_attribute_response[ 'errors' ].nil?

        write( message: "Success! To verify, in your browser, visit:\n" +
          "#{ Configuration.default_config[ 'archivist_url' ] }/realms" +
          "/#{ @options[ :realm ] }/blueprints/" +
          "?access_token=#{ Configuration.access_token }&" +
          "include[blueprint_attributes]=true" )

      else
        write( message: "Error creating blueprint_attributes: " +
          "#{ blueprint_attribute_response[ 'errors' ].inspect }", error: true )
      end
    else
      write( message: "Error creating blueprint: " +
        "#{ blueprint_response[ 'errors' ].inspect }", error: true )
    end
  else
    write( message: "File empty or not correctly formatted", error: true )
  end
end