Module: Gen
- Defined in:
- lib/gen.rb
Class Method Summary collapse
- .add(source:, template: nil, template_name: nil, name: nil, executable: false, x: nil) ⇒ Object
- .add_doc(symbol, docstr) ⇒ Object
- .add_task(task:, name: nil, executable: false, x: nil) ⇒ Object
- .add_write_content(name:, content:, executable: false) ⇒ Object
- .document ⇒ Object
- .mod_attr2_accessor(symbol, symbol2, docstr = nil, default = nil) ⇒ Object
- .mod_attr2_reader(symbol, symbol2, docstr = nil, default = nil) ⇒ Object
- .mod_attr_accessor(symbol, docstr = nil, default = nil) ⇒ Object
- .mod_attr_reader(symbol, docstr = nil, default = nil) ⇒ Object
- .read_attr(symbol, default) ⇒ Object
- .rw_attr(symbol, default) ⇒ Object
- .setup(document_content, input_name, output_directory) ⇒ Object
Class Method Details
.add(source:, template: nil, template_name: nil, name: nil, executable: false, x: nil) ⇒ Object
91 92 93 |
# File 'lib/gen.rb', line 91 def self.add(source:, template: nil, template_name: nil, name: nil, executable: false, x: nil) add_task(task: Task.new(source, template, template_name), name: name, executable: executable, x: x) end |
.add_doc(symbol, docstr) ⇒ Object
13 14 15 16 17 |
# File 'lib/gen.rb', line 13 def self.add_doc(symbol, docstr) return if docstr.nil? @docsrc = [] unless instance_variable_defined?('@docsrc') @docsrc.push("- #{symbol.to_s} : #{docstr}") end |
.add_task(task:, name: nil, executable: false, x: nil) ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/gen.rb', line 78 def self.add_task(task:, name: nil, executable: false, x: nil) @tasks.push(task) # Since this method allows the user to pass their own task type instance, # assign optional values with defaults only when clearly given. @tasks.last.name = name unless name.nil? @tasks.last.executable = executable unless executable == false @tasks.last.x = x unless x.nil? end |
.add_write_content(name:, content:, executable: false) ⇒ Object
87 88 89 |
# File 'lib/gen.rb', line 87 def self.add_write_content(name:, content:, executable: false) add_task(task: WriteTask.new(name, content, executable)) end |
.document ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/gen.rb', line 95 def self.document @docsrc.join("\n") + %( - add_task(task:, name: nil, executable: false, x: nil) : Adds task object. - add_write_content(name:, content:, executable: false) : Add file write task. - add(source:, template: nil, template_name: nil, name: nil, executable: false, x: nil) : Adds template task with source as object to process. ) end |
.mod_attr2_accessor(symbol, symbol2, docstr = nil, default = nil) ⇒ Object
44 45 46 47 48 |
# File 'lib/gen.rb', line 44 def self.mod_attr2_accessor(symbol, symbol2, docstr = nil, default = nil) rw_attr(symbol, default) rw_attr(symbol2, default) unless symbol2.nil? add_doc(symbol, docstr) end |
.mod_attr2_reader(symbol, symbol2, docstr = nil, default = nil) ⇒ Object
26 27 28 29 30 |
# File 'lib/gen.rb', line 26 def self.mod_attr2_reader(symbol, symbol2, docstr = nil, default = nil) read_attr(symbol, default) read_attr(symbol2, default) add_doc(symbol, docstr) end |
.mod_attr_accessor(symbol, docstr = nil, default = nil) ⇒ Object
50 51 52 |
# File 'lib/gen.rb', line 50 def self.mod_attr_accessor(symbol, docstr = nil, default = nil) mod_attr2_accessor(symbol, nil, docstr, default) end |
.mod_attr_reader(symbol, docstr = nil, default = nil) ⇒ Object
32 33 34 |
# File 'lib/gen.rb', line 32 def self.mod_attr_reader(symbol, docstr = nil, default = nil) mod_attr2_reader(symbol, nil, docstr, default) end |
.read_attr(symbol, default) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/gen.rb', line 19 def self.read_attr(symbol, default) return if symbol.nil? attr_reader(symbol) module_function(symbol) instance_variable_set("@#{symbol.to_s}", default) end |
.rw_attr(symbol, default) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/gen.rb', line 36 def self.rw_attr(symbol, default) attr_accessor(symbol) module_function(symbol) s = symbol.to_s module_function((s + '=').to_sym) instance_variable_set("@#{s}", default) end |
.setup(document_content, input_name, output_directory) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/gen.rb', line 68 def self.setup(document_content, input_name, output_directory) @doc = document_content @outdir = output_directory unless input_name.nil? @in_name = File.basename(input_name) @in_basename = File.basename(input_name, '.*') end add_task(task: HelperTask.new) end |