Class: FLGen::FileList
- Inherits:
-
Object
- Object
- FLGen::FileList
- Defined in:
- lib/flgen/file_list.rb
Instance Method Summary collapse
- #compile_argument(argument, tool: nil) ⇒ Object
- #default_search_path(**search_paths) ⇒ Object
- #define_macro(macro, value = nil) ⇒ Object
- #env(name) ⇒ Object
- #env?(name) ⇒ Boolean
- #file?(path, from: :current) ⇒ Boolean
- #file_list(path, from: nil, raise_error: true) ⇒ Object
- #find_file(patterns, from: nil) ⇒ Object
- #find_files(patterns, from: nil, &block) ⇒ Object
-
#initialize(context, path) ⇒ FileList
constructor
A new instance of FileList.
- #macro(name) ⇒ Object
- #macro?(macro) ⇒ Boolean (also: #macro_defined?)
- #reset_default_search_path(*target_types) ⇒ Object
- #runtime_argument(argument, tool: nil) ⇒ Object
- #source_file(path, from: nil, raise_error: true) ⇒ Object
- #target_tool?(tool) ⇒ Boolean
- #undefine_macro(macro) ⇒ Object
Constructor Details
#initialize(context, path) ⇒ FileList
Returns a new instance of FileList.
5 6 7 8 9 10 |
# File 'lib/flgen/file_list.rb', line 5 def initialize(context, path) @context = context @path = path @root_directories = extract_root @default_search_path = init_default_search_path end |
Instance Method Details
#compile_argument(argument, tool: nil) ⇒ Object
79 80 81 |
# File 'lib/flgen/file_list.rb', line 79 def compile_argument(argument, tool: nil) @context.add_compile_argument(Arguments::Generic.new(argument, tool)) end |
#default_search_path(**search_paths) ⇒ Object
12 13 14 |
# File 'lib/flgen/file_list.rb', line 12 def default_search_path(**search_paths) @default_search_path.update(search_paths) end |
#define_macro(macro, value = nil) ⇒ Object
48 49 50 |
# File 'lib/flgen/file_list.rb', line 48 def define_macro(macro, value = nil) @context.define_macro(macro, value) end |
#env(name) ⇒ Object
70 71 72 |
# File 'lib/flgen/file_list.rb', line 70 def env(name) ENV.fetch(name.to_s, nil) end |
#env?(name) ⇒ Boolean
66 67 68 |
# File 'lib/flgen/file_list.rb', line 66 def env?(name) ENV.key?(name.to_s) end |
#file?(path, from: :current) ⇒ Boolean
42 43 44 |
# File 'lib/flgen/file_list.rb', line 42 def file?(path, from: :current) !extract_path(path, from, __callee__, caller_location).nil? end |
#file_list(path, from: nil, raise_error: true) ⇒ Object
20 21 22 |
# File 'lib/flgen/file_list.rb', line 20 def file_list(path, from: nil, raise_error: true) load_file_list(path, from, raise_error, caller_location) end |
#find_file(patterns, from: nil) ⇒ Object
37 38 39 40 |
# File 'lib/flgen/file_list.rb', line 37 def find_file(patterns, from: nil) glob_files(patterns, from, __callee__, caller_location) .first&.then { |f| block_given? && (return yield f) || f } end |
#find_files(patterns, from: nil, &block) ⇒ Object
32 33 34 35 |
# File 'lib/flgen/file_list.rb', line 32 def find_files(patterns, from: nil, &block) glob_files(patterns, from, __callee__, caller_location) .then { |e| block_given? && (return e.each(&block)) || e.to_a } end |
#macro(name) ⇒ Object
62 63 64 |
# File 'lib/flgen/file_list.rb', line 62 def macro(name) @context.macros[name.to_sym] end |
#macro?(macro) ⇒ Boolean Also known as: macro_defined?
56 57 58 |
# File 'lib/flgen/file_list.rb', line 56 def macro?(macro) @context.macros.key?(macro.to_sym) end |
#reset_default_search_path(*target_types) ⇒ Object
16 17 18 |
# File 'lib/flgen/file_list.rb', line 16 def reset_default_search_path(*target_types) target_types.each { |type| @default_search_path.delete(type) } end |
#runtime_argument(argument, tool: nil) ⇒ Object
83 84 85 |
# File 'lib/flgen/file_list.rb', line 83 def runtime_argument(argument, tool: nil) @context.add_runtime_argument(Arguments::Generic.new(argument, tool)) end |
#source_file(path, from: nil, raise_error: true) ⇒ Object
24 25 26 |
# File 'lib/flgen/file_list.rb', line 24 def source_file(path, from: nil, raise_error: true) add_entry(path, from, raise_error, __callee__, caller_location) end |
#target_tool?(tool) ⇒ Boolean
74 75 76 77 |
# File 'lib/flgen/file_list.rb', line 74 def target_tool?(tool) target_tool = @context.[:tool] target_tool && tool.to_sym == target_tool || false end |
#undefine_macro(macro) ⇒ Object
52 53 54 |
# File 'lib/flgen/file_list.rb', line 52 def undefine_macro(macro) @context.undefine_macro(macro) end |