Module: Card::Set::Abstract::CodeFile

Extended by:
Card::Set
Defined in:
tmpsets/set/mod001-core/abstract/code_file.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #pattern_and_modules_from_path, #process_base_modules, #register_set, #tmp_file_frame, #tmp_file_template, #tmp_file_wrapped_content, #write_tmp_file

Methods included from Helpers

#abstract_set?, #all_set?, #shortname

Methods included from Card::Set::AdvancedApi

#attachment, #ensure_set, #stage_method

Methods included from Format

#all_set_format_mod!, #define_on_format, #format, #register_set_format, #view

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer

Methods included from Event

#event

Class Method Details

.included(host_class) ⇒ Object

~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/core/set/abstract/code_file.rb ~~



4
5
6
7
# File 'tmpsets/set/mod001-core/abstract/code_file.rb', line 4

def self.included host_class
  host_class.mattr_accessor :file_content_mod_name
  host_class.file_content_mod_name = mod_name(caller)
end

.mod_name(backtrace) ⇒ Object

try to extract the mod name from the path of the set's tmp file the caller that included the set file is set.rb

Raises:



11
12
13
14
15
16
# File 'tmpsets/set/mod001-core/abstract/code_file.rb', line 11

def self.mod_name backtrace
  mod_dir = tmp_mod_dir backtrace
  raise Error, "not a valid set path: #{path}" unless mod_dir
  match = mod_dir.match(/^mod\d+-(?<mod_name>.+)$/)
  match[:mod_name]
end

.tmp_mod_dir(backtrace) ⇒ Object

Raises:



18
19
20
21
22
23
24
25
# File 'tmpsets/set/mod001-core/abstract/code_file.rb', line 18

def self.tmp_mod_dir backtrace
  path = backtrace.find { |line| line.include? "tmp/set/" }
  raise Error, "couldn't find set path in backtrace: #{backtrace}" unless path
  path_parts = path.split(File::SEPARATOR)
  path_parts.fetch(path_parts.index("set") + 1) do
    raise Error, "not a valid set path: #{path}"
  end
end

Instance Method Details

#existing_source_pathsObject



53
54
55
56
57
# File 'tmpsets/set/mod001-core/abstract/code_file.rb', line 53

def existing_source_paths
  Array.wrap(source_files).map do |filename|
    find_file(filename)
  end.compact
end

#find_file(filename) ⇒ Object



44
45
46
47
48
49
50
51
# File 'tmpsets/set/mod001-core/abstract/code_file.rb', line 44

def find_file filename
  Card.paths["mod"].to_a.each do |mod_path|
    file_path =
      File.join(mod_path, file_content_mod_name, "lib", source_dir, filename)
    return file_path if File.exist? file_path
  end
  nil
end

#source_dirObject



37
38
39
40
41
42
# File 'tmpsets/set/mod001-core/abstract/code_file.rb', line 37

def source_dir
  case type_id
  when CoffeeScriptID, JavaScriptID then "javascript"
  when CssID, ScssID then "stylesheets"
  end
end

#source_filesArray<String>, String

Returns the name of file(s) to be loaded.

Returns:

  • (Array<String>, String)

    the name of file(s) to be loaded



28
29
30
31
32
33
34
35
# File 'tmpsets/set/mod001-core/abstract/code_file.rb', line 28

def source_files
  case type_id
  when CoffeeScriptID then "#{codename}.js.coffee"
  when JavaScriptID then "#{codename}.js"
  when CssID then "#{codename}.css"
  when ScssID then "#{codename}.scss"
  end
end