Class: Mortar::Command::Fixtures

Inherits:
Base
  • Object
show all
Defined in:
lib/mortar/command/fixtures.rb

Overview

create a reusable fixture.

Constant Summary collapse

WARNING_NUM_ROWS =
50

Instance Attribute Summary

Attributes inherited from Base

#args, #options

Instance Method Summary collapse

Methods inherited from Base

#api, #ask_public, #config_parameters, #get_error_message_context, #git, #initialize, #initialize_embedded_project, namespace, #pig_parameters, #project, #register_api_call, #register_do, #register_project, #validate_project_name, #validate_project_structure

Methods included from Helpers

#action, #ask, #confirm, #copy_if_not_present_at_dest, #default_host, #deprecate, #display, #display_header, #display_object, #display_row, #display_table, #display_with_indent, #download_to_file, #ensure_dir_exists, #error, error_with_failure, error_with_failure=, extended, extended_into, #format_bytes, #format_date, #format_with_bang, #get_terminal_environment, #home_directory, #host, #hprint, #hputs, included, included_into, #installed_with_omnibus?, #json_decode, #json_encode, #line_formatter, #longest, #output_with_bang, #quantify, #redisplay, #retry_on_exception, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #spinner, #status, #string_distance, #styled_array, #styled_error, #styled_hash, #styled_header, #suggestion, #test_name, #ticking, #time_ago, #truncate, #warning, #with_tty, #write_to_file

Constructor Details

This class inherits a constructor from Mortar::Command::Base

Instance Method Details

#headObject

fixtures:head [INPUT_URL] [NUM_ROWS] [FIXTURE_NAME]

Create a reusable fixture [FIXTURE_NAME] made up of [NUM_ROWS] number of rows from the head of the input file(s) at [INPUT_URL].

Examples:

$ mortar fixtures:head s3n://tbmmsd/.tsv. 100 samll_song_sample



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/mortar/command/fixtures.rb', line 34

def head
  input_url = shift_argument
  num_rows = shift_argument
  fixture_name = shift_argument
  unless input_url && num_rows && fixture_name
    error("Usage: mortar fixtures:head INPUT_URL NUM_ROWS FIXTURE_NAME\nMust specifiy INPUT_URL, NUM_ROWS, and FIXTURE_NAME.")
  end
  if does_fixture_exist(fixture_name)
    error("Fixture #{fixture_name} already exists.")
  end
  unless num_rows.to_i < WARNING_NUM_ROWS
    warning("Creating fixtures with more than #{WARNING_NUM_ROWS} rows is not recommended.  Large local fixtures may cause slowness when using Mortar.")
    display
  end
  validate_arguments!
  validate_git_based_project!

  fixture_id = nil
  action("Requesting fixture creation") do
    fixture_id = api.post_fixture_limit(project.name, fixture_name, input_url, num_rows).body['fixture_id']
  end

  poll_for_fixture_results(fixture_id)
end