Class: Dry::Web::Roda::Generate
- Inherits:
-
Object
- Object
- Dry::Web::Roda::Generate
- Defined in:
- lib/dry/web/roda/generate.rb
Constant Summary collapse
- TEMPLATES_DIR =
"templates".freeze
- SOURCE_DIR =
Pathname(__FILE__).dirname.join(TEMPLATES_DIR)
Instance Attribute Summary collapse
-
#processor ⇒ Object
readonly
Returns the value of attribute processor.
-
#target_dir ⇒ Object
readonly
Returns the value of attribute target_dir.
-
#template_files ⇒ Object
readonly
Returns the value of attribute template_files.
-
#template_scope ⇒ Object
readonly
Returns the value of attribute template_scope.
Instance Method Summary collapse
- #call(source, target) ⇒ Object
-
#initialize(target_dir, template_scope) ⇒ Generate
constructor
A new instance of Generate.
Constructor Details
#initialize(target_dir, template_scope) ⇒ Generate
Returns a new instance of Generate.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/dry/web/roda/generate.rb', line 13 def initialize(target_dir, template_scope) @target_dir = target_dir @template_scope = template_scope @template_files = Dir[SOURCE_DIR.join('**/{.,}*')] @processor = Class.new(Thor) do include Thor::Actions end.new @processor.class.source_root SOURCE_DIR end |
Instance Attribute Details
#processor ⇒ Object (readonly)
Returns the value of attribute processor.
11 12 13 |
# File 'lib/dry/web/roda/generate.rb', line 11 def processor @processor end |
#target_dir ⇒ Object (readonly)
Returns the value of attribute target_dir.
11 12 13 |
# File 'lib/dry/web/roda/generate.rb', line 11 def target_dir @target_dir end |
#template_files ⇒ Object (readonly)
Returns the value of attribute template_files.
11 12 13 |
# File 'lib/dry/web/roda/generate.rb', line 11 def template_files @template_files end |
#template_scope ⇒ Object (readonly)
Returns the value of attribute template_scope.
11 12 13 |
# File 'lib/dry/web/roda/generate.rb', line 11 def template_scope @template_scope end |
Instance Method Details
#call(source, target) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dry/web/roda/generate.rb', line 24 def call(source, target) source = Pathname(source) aboslute_source_path = source.(SOURCE_DIR) target_file = get_target_file(target) template_file = template_files.find { |f| f == aboslute_source_path.to_s } or raise "missing template file +#{source}+" template_file = Pathname(template_file) processor.template template_file, target_file, template_scope create_executable(target_file) if executable?(template_file) end |