Module: Herb::Bootstrap
- Defined in:
- lib/herb/bootstrap.rb
Constant Summary collapse
- ROOT_PATH =
File.("../..", __dir__)
- PRISM_VENDOR_DIR =
File.join(ROOT_PATH, "vendor", "prism")
- PRISM_ENTRIES =
[ "config.yml", "Rakefile", "src/", "include/", "templates/" ].freeze
Class Method Summary collapse
- .find_prism_as_bundler_sibling ⇒ Object
- .find_prism_from_gem_spec ⇒ Object
- .find_prism_gem_path ⇒ Object
- .generate_prism_templates ⇒ Object
- .generate_templates ⇒ Object
- .git_source? ⇒ Boolean
- .prism_ast_header_exists? ⇒ Boolean
- .prism_vendored? ⇒ Boolean
- .templates_generated? ⇒ Boolean
- .vendor_prism(prism_gem_path:) ⇒ Object
Class Method Details
.find_prism_as_bundler_sibling ⇒ Object
69 70 71 72 73 74 |
# File 'lib/herb/bootstrap.rb', line 69 def self.find_prism_as_bundler_sibling bundler_gems_dir = File.("..", ROOT_PATH) candidates = Dir.glob(File.join(bundler_gems_dir, "prism-*")) candidates.find { |path| File.directory?(File.join(path, "src")) } end |
.find_prism_from_gem_spec ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/herb/bootstrap.rb', line 76 def self.find_prism_from_gem_spec path = Gem::Specification.find_by_name("prism").full_gem_path return path if File.directory?(File.join(path, "src")) nil rescue Gem::MissingSpecError nil end |
.find_prism_gem_path ⇒ Object
60 61 62 |
# File 'lib/herb/bootstrap.rb', line 60 def self.find_prism_gem_path find_prism_as_bundler_sibling || find_prism_from_gem_spec end |
.generate_prism_templates ⇒ Object
64 65 66 67 |
# File 'lib/herb/bootstrap.rb', line 64 def self.generate_prism_templates puts "Generating Prism template files..." system("ruby", "#{PRISM_VENDOR_DIR}/templates/template.rb", exception: true) end |
.generate_templates ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/herb/bootstrap.rb', line 19 def self.generate_templates require "pathname" require_relative "../../templates/template" Dir.chdir(ROOT_PATH) do Dir.glob("#{ROOT_PATH}/templates/**/*.erb").each do |template| Herb::Template.render(template) end end end |
.git_source? ⇒ Boolean
30 31 32 |
# File 'lib/herb/bootstrap.rb', line 30 def self.git_source? File.directory?(File.join(ROOT_PATH, ".git")) end |
.prism_ast_header_exists? ⇒ Boolean
56 57 58 |
# File 'lib/herb/bootstrap.rb', line 56 def self.prism_ast_header_exists? File.exist?(File.join(PRISM_VENDOR_DIR, "include", "prism", "ast.h")) end |
.prism_vendored? ⇒ Boolean
52 53 54 |
# File 'lib/herb/bootstrap.rb', line 52 def self.prism_vendored? File.directory?(File.join(PRISM_VENDOR_DIR, "include")) end |
.templates_generated? ⇒ Boolean
34 35 36 |
# File 'lib/herb/bootstrap.rb', line 34 def self.templates_generated? File.exist?(File.join(ROOT_PATH, "ext", "herb", "nodes.c")) end |
.vendor_prism(prism_gem_path:) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/herb/bootstrap.rb', line 38 def self.vendor_prism(prism_gem_path:) FileUtils.mkdir_p(PRISM_VENDOR_DIR) PRISM_ENTRIES.each do |entry| source = File.join(prism_gem_path, entry) next unless File.exist?(source) puts "Vendoring '#{entry}' Prism file to #{PRISM_VENDOR_DIR}/#{entry}" FileUtils.cp_r(source, PRISM_VENDOR_DIR) end generate_prism_templates unless prism_ast_header_exists? end |