roxy icon indicating copy to clipboard operation
roxy copied to clipboard

Allow calling def mlcp with arguments

Open grtjn opened this issue 9 years ago • 2 comments

It was suggested to use app_specific over import scripts, for instance like:

  def deploy_customers
    log_header "Deploying Customers"

    ARGV.push('import')
    ARGV.push('-input_file_path')
    ARGV.push('data/customers')
    ARGV.push('-output_uri_replace')
    ARGV.push(%Q{"#{ServerConfig.expand_path("#{@@path}/../data")},''"})
    ARGV.push('-output_collections')
    ARGV.push('customers')
    ARGV.push('-output_permissions')

    role_name = @properties['ml.app-name'] + "-role"
    ARGV.push("#{role_name},read,#{role_name},update,#{role_name},insert,#{role_name},execute")
    mlcp
  end

However, allowing an array of (extra) arguments via a param to the mlcp function might be more elegant, something like:

  def deploy_customers
    log_header "Deploying Customers"

    role_name = @properties['ml.app-name'] + "-role"

    mlcp([
      'import',
      '-input_file_path',
      'data/customers',
      '-output_uri_replace',
      %Q{"#{ServerConfig.expand_path("#{@@path}/../data")},''"},
      '-output_collections',
      'customers',
      '-output_permissions',
      "#{role_name},read,#{role_name},update,#{role_name},insert,#{role_name},execute"
    ])
  end

Or maybe even without the [..]?

grtjn avatar Sep 09 '16 12:09 grtjn

+1

FWIW, as a workaround, I typically wrap the included mlcp method with this method that lets me call it with an array of arguments (and also includes the roles, since I find that I almost always want them):

  def ruby_flavored_mlcp(arguments)
    arguments.concat(role_permissions)
    arguments.each do |arg|
      ARGV.push(arg)
    end
    mlcp
  end

Then I can:

  def deploy_users
    logger.info "Deploying default user profile documents"
    arguments = %W{
      import -input_file_path data/users
      -document_type json
      -output_uri_replace
      "#{ServerConfig.expand_path("#{@@path}/../data")},'/api'"
    }
    ruby_flavored_mlcp(arguments)
  end

patrickmcelwee avatar Sep 12 '16 14:09 patrickmcelwee

Based on idea from @patrickmcelwee, I have used the following in app_specific:

  alias_method :original_mlcp, :mlcp

  def mlcp(arguments = [])
    arguments.each do |arg|
      ARGV.push(arg)
    end
    original_mlcp
  end

grtjn avatar Sep 22 '17 13:09 grtjn