Class: Importmap::Framework
- Inherits:
-
Object
- Object
- Importmap::Framework
- Defined in:
- lib/importmap/framework.rb,
lib/importmap/framework/jets_framework.rb,
lib/importmap/framework/rails_framework.rb
Defined Under Namespace
Modules: JetsFramework, RailsFramework
Constant Summary collapse
- @@instance =
nil
Class Method Summary collapse
Instance Method Summary collapse
- #framework_name ⇒ Object
-
#include_framework ⇒ Object
define at bottom so methods take precedence.
- #infer_from_gemfile ⇒ Object
-
#initialize ⇒ Framework
constructor
A new instance of Framework.
-
#supported_frameworks ⇒ Object
To add another framework: 1.
Constructor Details
#initialize ⇒ Framework
Returns a new instance of Framework.
11 12 13 14 |
# File 'lib/importmap/framework.rb', line 11 def initialize require framework_name Importmap::Framework.send(:include, include_framework) end |
Class Method Details
.instance ⇒ Object
7 8 9 |
# File 'lib/importmap/framework.rb', line 7 def self.instance @@instance ||= new end |
Instance Method Details
#framework_name ⇒ Object
16 17 18 |
# File 'lib/importmap/framework.rb', line 16 def framework_name ENV['IMPORTMAP_FRAMEWORK'] || infer_from_gemfile || "jets" end |
#include_framework ⇒ Object
define at bottom so methods take precedence
21 22 23 24 25 26 27 |
# File 'lib/importmap/framework.rb', line 21 def include_framework if supported_frameworks.include?(framework_name) "Importmap::Framework::#{framework_name.camelize}Framework".constantize else raise "Need to use a supported framework: #{supported_frameworks.join(', ')}" end end |
#infer_from_gemfile ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/importmap/framework.rb', line 29 def infer_from_gemfile return unless File.exist?("Gemfile") lines = IO.readlines("Gemfile") lines.each do |line| next if line =~ /^\s*#/ # skip comments gem_name = line.match(/gem ['"](\w+)['"]/)&.captures&.first if supported_frameworks.include?(gem_name) return gem_name end end nil end |
#supported_frameworks ⇒ Object
To add another framework:
-
add to this list
-
define a module in importmap/framework/##framework_name_framework.rb
45 46 47 |
# File 'lib/importmap/framework.rb', line 45 def supported_frameworks %w[jets rails] end |