Class: MrMurano::Module

Inherits:
ServiceBase show all
Defined in:
lib/MrMurano/Solution-Services.rb

Overview

What Murano calls “Modules”. Snippets of Lua code.

Defined Under Namespace

Classes: ModuleItem

Constant Summary

Constants included from Verbose

Verbose::TABULARIZE_DATA_FORMAT_ERROR

Constants included from SolutionId

SolutionId::INVALID_API_ID, SolutionId::UNEXPECTED_TYPE_OR_ERROR_MSG

Constants included from AccountBase

AccountBase::LOGIN_ADVICE, AccountBase::LOGIN_NOTICE

Instance Attribute Summary

Attributes included from SolutionId

#api_id, #sid, #valid_api_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ServiceBase

#cache_dump_filename, #cache_dump_filepath, #cache_file_name, #cache_update_time_for, #cached_update_time_for, #create_new_cache_file, #docmp, #dodiff, #dump_cache_file, #fetch, #local_path_file_hash, #remove, #remove_or_clear, #upload, #upload_script, #write_updated_cache_file

Methods inherited from SolutionBase

#==, #endpoint, #search

Methods included from SyncUpDown

#config_vars_decode, #config_vars_encode, #debug_print_localitems, #diff_download, #diff_item_write, #docmp, #download, #ignore?, #ignoring, #localitems, #locallist, #locallist_add_item, #locallist_complain_missing, #locallist_mark_seen, #location, #match, #remove, #remove_or_clear, #removelocal, #resolve_config_var_usage!, #resurrect_undeletables, #searchFor, #syncdown_after, #syncdown_before, #syncup_after, #syncup_before, #tolocalpath, #update_mtime, #upload

Methods included from Verbose

ask_yes_no, #ask_yes_no, #assert, assert, cmd_confirm_delete!, #cmd_confirm_delete!, debug, #debug, dump_file_json, dump_file_plain, dump_file_yaml, #dump_output_file, #error, error, #error_file_format!, fancy_ticks, #fancy_ticks, #load_file_json, #load_file_plain, #load_file_yaml, #load_input_file, outf, #outf, #outformat_engine, #pluralize?, pluralize?, #prepare_hash_csv, #read_hashf!, #tabularize, tabularize, verbose, #verbose, warning, #warning, #whirly_interject, whirly_interject, #whirly_linger, whirly_linger, #whirly_msg, whirly_msg, #whirly_pause, whirly_pause, #whirly_start, whirly_start, #whirly_stop, whirly_stop, #whirly_unpause, whirly_unpause

Methods included from SyncCore

#debug_selected, #dodiff, #dodiff_build_cmd, #dodiff_cull_tempfile_paths, #dodiff_do_diff, #dodiff_download_remote, #dodiff_flexible, #dodiff_header_aware, #dodiff_local_to_tempfile, #dodiff_prepare_local_and_diff, #dodiff_resolve_localname, #dodiff_tempfile_paths, #filter_solution, #init_mods_and_chgs_arrs, #item_dirty_set_status, #item_local_there_merged, #item_merged_diff_status, #item_merged_set_status, #item_select_selected!, #items_classify_and_find_duplicates, #items_cull_clashes!, #items_lists, #items_log_duplicates, #items_log_duplicates_there_local, #items_mods_and_chgs!, #items_new_and_old!, #select_selected!, #sort_by_name, #status, #sync_update_progress, #syncable_validate_api_id, #syncdown, #syncdown_item, #syncup, #syncup_item

Methods included from SyncAllowed

#download_item_allowed, #remove_item_allowed, #removelocal_item_allowed, #sync_item_allowed, #upload_item_allowed

Methods included from SolutionId

#affirm_valid, #api_id?, #endpoint, #init_api_id!, #valid_api_id?

Methods included from AccountBase

#add_headers, #ask_for_password!, #ask_for_user!, #cfg_clear_user_and_business, #credentials_reset, #get, #invalidate_token, #login_info, #logout, #must_prompt_if_logged_off!, #token, #token_reset, #verify_cfg_auth!, #verify_cfg_auth_persist, #verify_cfg_auth_scheme!, #verify_cfg_auth_ttl, #verify_set, warn_configfile_env_maybe

Methods included from Http

#add_headers, #curldebug, curldebug_after, curldebug_elapsed, curldebug_log, #delete, #endpoint, #get, #host, #http, #http_reset, #isJSON, #json_opts, #patch, #post, #postf, #put, #showHttpError, #user, #workit, #workit_response

Constructor Details

#initialize(api_id = nil) ⇒ Module

Returns a new instance of Module.



377
378
379
380
381
382
383
# File 'lib/MrMurano/Solution-Services.rb', line 377

def initialize(api_id=nil)
  @solntype = 'application.id'
  super
  @uriparts << :module
  @itemkey = :alias
  @project_section = :modules
end

Class Method Details

.descriptionObject



385
386
387
388
# File 'lib/MrMurano/Solution-Services.rb', line 385

def self.description
  # MAYBE/2017-07-31: Rename to "Script Modules", per Renaud's suggestion? [lb]
  %(Module)
end

Instance Method Details

#listObject



409
410
411
412
413
414
415
416
417
# File 'lib/MrMurano/Solution-Services.rb', line 409

def list
  ret = get
  return [] unless ret.is_a?(Hash) && !ret.key?(:error)
  return [] unless ret.key?(:items)
  ret[:items].map { |i| ModuleItem.new(i) }
  # MAYBE/2017-08-17:
  #   ret[:items].map!
  #   sort_by_name(ret[:items])
end

#mkalias(remote) ⇒ Object



399
400
401
402
# File 'lib/MrMurano/Solution-Services.rb', line 399

def mkalias(remote)
  raise "Missing parts! #{remote.to_h.to_json}" if remote.name.nil?
  [@api_id, remote[:name]].join('_')
end

#mkname(remote) ⇒ Object



404
405
406
407
# File 'lib/MrMurano/Solution-Services.rb', line 404

def mkname(remote)
  raise "Missing parts! #{remote.to_h.to_json}" if remote.name.nil?
  remote[:name]
end

#remote_item_nested_name(root, path) ⇒ Object



429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
# File 'lib/MrMurano/Solution-Services.rb', line 429

def remote_item_nested_name(root, path)
  # 2017-07-26: Nested Lua support.
  root = root.expand_path
  if path.basename.sub(/\.lua$/i, '').to_s.include?('.')
    warning(
      'WARNING: Do not use periods in filenames.' \
      " Rename: #{fancy_ticks(path.basename)}"
    )
  end
  path.dirname.ascend do |ancestor|
    break if ancestor == root
    if ancestor.basename.to_s.include?('.')
      warning(
        'WARNING: Do not use periods in directory names.' \
        " Rename: #{fancy_ticks(ancestor.basename)}"
      )
    end
  end
  relpath = path.relative_path_from(root).to_s
  # MAYBE: Use ALT_SEPARATOR to support Windows?
  #   ::File::ALT_SEPARATOR || ::File::SEPARATOR
  #relpath.sub(/\..*$/, '').tr(::File::SEPARATOR, '.')
  relpath.sub(/\.lua$/i, '').tr(::File::SEPARATOR, '.')
end

#synckey(item) ⇒ Object



454
455
456
# File 'lib/MrMurano/Solution-Services.rb', line 454

def synckey(item)
  item[:name]
end

#to_remote_items(root, path) ⇒ Object



419
420
421
422
423
424
425
426
427
# File 'lib/MrMurano/Solution-Services.rb', line 419

def to_remote_items(root, path)
  if $cfg['modules.no-nesting']
    name = path.basename.to_s.sub(/\..*/, '')
  else
    name = remote_item_nested_name(root, path)
  end
  item = ModuleItem.new(name: name)
  [item]
end

#tolocalname(item, _key) ⇒ Object



390
391
392
393
394
395
396
397
# File 'lib/MrMurano/Solution-Services.rb', line 390

def tolocalname(item, _key)
  name = item[:name]
  # Nested Lua support: the platform dot-delimits modules in a require.
  name = File.join(name.split('.')) unless $cfg['modules.no-nesting']
  # NOTE: On syncup, user can specify file extension (or use * glob),
  # but on syncdown, the ".lua" extension is hardcoded (here).
  "#{name}.lua"
end