module MxxRu::Externals::Impl::ExternalBasics
Attributes
name[R]
paths[R]
url[R]
url=[R]
Public Instance Methods
map(value)
click to toggle source
# File lib/mxx_ru/externals.rb, line 259 def map(value) STDERR.print("#{caller(1)[0]}: 'map_dir' must be used instead of 'map'," + " 'map' is deprecated\n") map_dir(value) end
map_dir(value)
click to toggle source
# File lib/mxx_ru/externals.rb, line 253 def map_dir(value) raise "map_dir() value must be a Hash" unless value.is_a?(Hash) @paths.merge!(value) end
map_file(value)
click to toggle source
# File lib/mxx_ru/externals.rb, line 266 def map_file(value) raise "map_file() value must be a Hash" unless value.is_a?(Hash) @files.merge!(value) end
Private Instance Methods
basics_to_map()
click to toggle source
# File lib/mxx_ru/externals.rb, line 284 def basics_to_map { url: @url, paths: @paths, files: @files } end
defaults(name)
click to toggle source
# File lib/mxx_ru/externals.rb, line 274 def defaults(name) @name = name @install_task_name = "#{@name}_#{object_id}" @remove_task_name = "#{@install_task_name}:remove" @reget_task_name = "#{@install_task_name}:reget" @paths = {} @files = {} @verbose = Rake.verbose end
define(old_or_new, &exporter)
click to toggle source
Note: argument old_or_new can receive values :new_rules or :old_rules.
# File lib/mxx_ru/externals.rb, line 326 def define(old_or_new, &exporter) ensure_basics_correctness(@name) ext_prj_sources_dir, dir_subtargets, file_subtargets = define_basic_task(old_or_new, &exporter) define_remove_task( old_or_new, ext_prj_sources_dir, dir_subtargets, file_subtargets) if :new_rules == old_or_new define_reget_task(ext_prj_sources_dir, dir_subtargets, file_subtargets) end end
define_basic_task(old_or_new, &exporter)
click to toggle source
# File lib/mxx_ru/externals.rb, line 343 def define_basic_task(old_or_new, &exporter) ext_prj_sources_dir = subdir_name(@name.to_s) directory EXTERNALS_STORAGE_DIR dir_subtargets = [] @paths.each do |src, dst| src, actual_dst, dir_dep = handle_dir_map_pair(src, dst) define_only_if_new_rules(old_or_new) do directory dir_dep directory actual_dst => [ext_prj_sources_dir, dir_dep] do cp_r(File.join(ext_prj_sources_dir, src), actual_dst, fileop_options) end end dir_subtargets << actual_dst end file_subtargets = [] @files.each do |src, dst| dst, dir_dep = handle_file_map_pair(src, dst) define_only_if_new_rules(old_or_new) do directory dir_dep file dst => [ext_prj_sources_dir, dir_dep] do cp(File.join(ext_prj_sources_dir, src), dst, fileop_options) end end file_subtargets << dst end define_only_if_new_rules(old_or_new) do directory ext_prj_sources_dir => [EXTERNALS_STORAGE_DIR] do # All old destinations must be removed because source code # will be exported again. rm_directories(dir_subtargets) rm_files(file_subtargets) ext_prj_sources_tmp_dir = subdir_name(make_tmp_name(@name)) exporter.call(ext_prj_sources_tmp_dir) mv(ext_prj_sources_tmp_dir, ext_prj_sources_dir, fileop_options) end task @install_task_name => [:mxxru_cleanup_previous, dir_subtargets, file_subtargets].flatten! task install: @install_task_name end return ext_prj_sources_dir, dir_subtargets, file_subtargets end
define_only_if_new_rules(old_or_new, &block)
click to toggle source
Helper function for doing some actions only if old_or_new is :new_rules.
# File lib/mxx_ru/externals.rb, line 456 def define_only_if_new_rules(old_or_new, &block) if :new_rules == old_or_new block.call end end
define_reget_task(ext_prj_sources_dir, dir_subtargets, file_subtargets)
click to toggle source
# File lib/mxx_ru/externals.rb, line 415 def define_reget_task(ext_prj_sources_dir, dir_subtargets, file_subtargets) task @reget_task_name => [@remove_task_name, @install_task_name] task :reget => @reget_task_name end
define_remove_task( old_or_new, ext_prj_sources_dir, dir_subtargets, file_subtargets)
click to toggle source
# File lib/mxx_ru/externals.rb, line 399 def define_remove_task( old_or_new, ext_prj_sources_dir, dir_subtargets, file_subtargets) task @remove_task_name do rm_files(file_subtargets) rm_directories(dir_subtargets) rm_dir_if_exists(ext_prj_sources_dir) end if :new_rules == old_or_new task :remove => @remove_task_name else task :mxxru_cleanup_previous => @remove_task_name end end
ensure_basics_correctness(name)
click to toggle source
# File lib/mxx_ru/externals.rb, line 308 def ensure_basics_correctness(name) raise "#{name}: url not specified" unless @url raise "#{name}: path or file map must be specified" if @paths.empty? and @files.empty? end
fileop_options()
click to toggle source
# File lib/mxx_ru/externals.rb, line 288 def fileop_options { :verbose => @verbose } end
handle_dir_map_pair(src, dst)
click to toggle source
Check the presence of start in src and make actual_dst and dir_dep in dependence of the result. If start is present then it is removed from actual_src.
Returns triplet: [actual_src, actual_dst, dir_dep]
# File lib/mxx_ru/externals.rb, line 427 def handle_dir_map_pair(src, dst) src_parts = File.split(src) if '*' == src_parts.last # Since v.1.6.9: source path must be copied with different name. # Source name must not contain '*' at the end. src = src_parts.first # The first part original dst must be used as destination. [src, dst, File.split(dst).first] else # Last name of src must be added to dst to create actual destination. [src, File.join(dst, src_parts.last), dst] end end
handle_file_map_pair(src, dst)
click to toggle source
Check the presence of start in dst and make actual_dst and dir_dep in dependence of the result.
Returns pair: [actual_dst, dir_dep]
# File lib/mxx_ru/externals.rb, line 446 def handle_file_map_pair(src, dst) dst_parts = File.split(dst) if '*' == dst_parts.last # Since v.1.6.9: original name of file must be preserved. dst = File.join(dst_parts.first, File.split(src).last) end [dst, dst_parts.first] end
make_name(prefix, suffix)
click to toggle source
# File lib/mxx_ru/externals.rb, line 313 def make_name(prefix, suffix) prefix.to_s + suffix end
make_tmp_name(*prefixes)
click to toggle source
# File lib/mxx_ru/externals.rb, line 321 def make_tmp_name(*prefixes) "#{prefixes.join('.')}.#{Process.pid}.#{Thread.current.object_id}" end
rm_dir_if_exists(dir_name)
click to toggle source
# File lib/mxx_ru/externals.rb, line 292 def rm_dir_if_exists(dir_name) rm_r(dir_name, fileop_options) if Dir.exists?(dir_name) end
rm_directories(dirs)
click to toggle source
# File lib/mxx_ru/externals.rb, line 296 def rm_directories(dirs) dirs.each { |d| rm_dir_if_exists(d) } end
rm_file_if_exists(file_name)
click to toggle source
# File lib/mxx_ru/externals.rb, line 300 def rm_file_if_exists(file_name) rm(file_name, fileop_options) if File.exists?(file_name) end
rm_files(files)
click to toggle source
# File lib/mxx_ru/externals.rb, line 304 def rm_files(files) files.each { |f| rm_file_if_exists(f) } end
subdir_name(subdir)
click to toggle source
# File lib/mxx_ru/externals.rb, line 317 def subdir_name(subdir) File.join(EXTERNALS_STORAGE_DIR, subdir) end