Module: Card::Set::Abstract::CodeFile
- Extended by:
- Card::Set
- Defined in:
- tmpsets/set/mod002-core/abstract/code_file.rb
Constant Summary
Constants included from Format
Class Method Summary collapse
-
.included(host_class) ⇒ Object
~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/core/set/abstract/code_file.rb ~~.
-
.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.
- .tmp_mod_dir(backtrace) ⇒ Object
Instance Method Summary collapse
- #existing_source_paths ⇒ Object
- #find_file(filename) ⇒ Object
- #source_dir ⇒ Object
-
#source_files ⇒ Array<String>, String
The name of file(s) to be loaded.
Methods included from I18nScope
Methods included from Loader
#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set
Methods included from Helpers
#abstract_set?, #all_set?, #num_set_parts, #shortname
Methods included from Card::Set::AdvancedApi
#attachment, #ensure_set, #stage_method
Methods included from Format
#all_set_format_mod!, #before, #define_on_format, #format, #register_set_format, #view, #view_for_override
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::Api
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/mod002-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
11 12 13 14 15 16 |
# File 'tmpsets/set/mod002-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
18 19 20 21 22 23 24 25 |
# File 'tmpsets/set/mod002-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_paths ⇒ Object
53 54 55 56 57 |
# File 'tmpsets/set/mod002-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/mod002-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_dir ⇒ Object
37 38 39 40 41 42 |
# File 'tmpsets/set/mod002-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_files ⇒ Array<String>, String
Returns the name of file(s) to be loaded.
28 29 30 31 32 33 34 35 |
# File 'tmpsets/set/mod002-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 |