class PortalModule::Rake::LoanEntryTasks

Attributes

action[R]
env[RW]
org[RW]
path[RW]
stop_on_exception[R]
valid_actions[R]

Public Class Methods

install() click to toggle source
# File lib/portal_module/rake/loan_entry_tasks.rb, line 147
def install
  new.install
end
new(task_name = 'loan_entry_task', desc = "Modify a Loan Entry configuration") { |self| ... } click to toggle source
# File lib/portal_module/rake/loan_entry_tasks.rb, line 25
def initialize(task_name = 'loan_entry_task', desc = "Modify a Loan Entry configuration")
  @valid_actions = ['upload', 'download']
  @task_name, @desc = task_name, desc

  @stop_on_exception = true

  yield self if block_given?

  define_task
end

Public Instance Methods

action=(task_action) click to toggle source
# File lib/portal_module/rake/loan_entry_tasks.rb, line 52
def action=(task_action)
  raise "action must be one of #{valid_types.join(', ')}" unless valid_actions.include?(task_action.downcase)
  @action = task_action
end
assert_env_is_configured(arg) click to toggle source
# File lib/portal_module/rake/loan_entry_tasks.rb, line 111
def assert_env_is_configured arg
  unless PortalModule.configuration.credentials.key? arg
    init_msg = "Have you initialized your config file?\n Try: portal_module config init <filedir>"
    env_msg = "Have you configured your environments?\n Try: portal_module config add env <envname> <url>"
    raise "Unknown environment: #{arg}\n#{init_msg}\n\n#{env_msg}"
  end
end
assert_org_is_configured(arg) click to toggle source
# File lib/portal_module/rake/loan_entry_tasks.rb, line 119
def assert_org_is_configured arg
  unless PortalModule.configuration.orgs.key? arg
    init_msg = "Have you initialized your config file?\n Try: portal_module config init <filedir>"
    env_msg = "Have you configured your orgs?\n Try: portal_module config add org <orgname> <orgid>"
    raise "Unknown org: #{arg}\n#{init_msg}\n\n#{env_msg}"
  end
end
assert_provided(value, msg) click to toggle source
# File lib/portal_module/rake/loan_entry_tasks.rb, line 105
def assert_provided value, msg
  if value.nil? || value.empty?
    raise msg
  end
end
commit() click to toggle source
# File lib/portal_module/rake/loan_entry_tasks.rb, line 62
def commit
  validate_params

  client = PortalModule::Client.new
  client.env = env

  if self.respond_to? action
    self.send(action, client)
    return
  else
    raise "Unknown action - #{action}"
  end

rescue Exception => e
  raise e if stop_on_exception == true
ensure
  client.quit unless client.nil?
end
default_params() click to toggle source
# File lib/portal_module/rake/loan_entry_tasks.rb, line 89
def default_params
end
download(client) click to toggle source
# File lib/portal_module/rake/loan_entry_tasks.rb, line 85
def download client
  client.loan_entry.download org, path
end
install() click to toggle source
# File lib/portal_module/rake/loan_entry_tasks.rb, line 152
def install
  PortalModule.configuration.credentials.keys.each do |e|
    valid_actions.each do |action|
      PortalModule::Rake::LoanEntryTasks.new("pm:#{e}:loan_entry:#{action}", "#{action} a #{e} loan entry configuration") do |t|
        t.env = e
        t.action = action
      end
    end
  end
end
required_args_for_action() click to toggle source
# File lib/portal_module/rake/loan_entry_tasks.rb, line 127
def required_args_for_action
  args = []

  case action
  when 'upload'
    args << :org
    args << :path

  when 'download'
    args << :org
    args << :path

  else
    # Noop
  end

  args
end
set_vars(args) click to toggle source
# File lib/portal_module/rake/loan_entry_tasks.rb, line 44
def set_vars args
  args.each do |arg,val|
    instance_variable_set "@#{arg}", val
  end

  args
end
stop_on_exception=(do_stop) click to toggle source
# File lib/portal_module/rake/loan_entry_tasks.rb, line 57
def stop_on_exception=(do_stop)
  raise ArgumentError, 'Expecting true or false' unless do_stop === true || do_stop === false
  @stop_on_exception = do_stop
end
upload(client) click to toggle source
# File lib/portal_module/rake/loan_entry_tasks.rb, line 81
def upload client
  client.loan_entry.upload org, path
end
validate_params() click to toggle source
# File lib/portal_module/rake/loan_entry_tasks.rb, line 92
def validate_params
  assert_provided env, 'Missing "env"'
  assert_provided action, 'Missing "action"'

  default_params

  assert_provided path, 'Missing "path"'
  assert_provided org, 'Missing "org"'

  assert_env_is_configured env
  assert_org_is_configured org
end