Class: Proscenium::Builder

Inherits:
Object show all
Defined in:
lib/proscenium/builder.rb

Defined Under Namespace

Modules: Request Classes: BuildError, CompileError, ResolveError, Result

Constant Summary collapse

ENVIRONMENTS =
{ development: 1, test: 2, production: 3 }.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root: nil) ⇒ Builder

Returns a new instance of Builder.



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/proscenium/builder.rb', line 81

def initialize(root: nil)
  @request_config = FFI::MemoryPointer.from_string({
    RootPath: (root || Rails.root).to_s,
    GemPath: gem_root,
    Environment: ENVIRONMENTS.fetch(Rails.env.to_sym, 2),
    Engines: engines,
    EnvVars: env_vars,
    CodeSplitting: Proscenium.config.code_splitting,
    Bundle: Proscenium.config.bundle,
    Debug: Proscenium.config.debug
  }.to_json)
end

Class Method Details

.build_to_path(path, root: nil) ⇒ Object



64
65
66
# File 'lib/proscenium/builder.rb', line 64

def self.build_to_path(path, root: nil)
  new(root:).build_to_path(path)
end

.build_to_string(path, root: nil) ⇒ Object



68
69
70
# File 'lib/proscenium/builder.rb', line 68

def self.build_to_string(path, root: nil)
  new(root:).build_to_string(path)
end

.reset_config!Object

Intended for tests only.



77
78
79
# File 'lib/proscenium/builder.rb', line 77

def self.reset_config!
  Request.reset_config
end

.resolve(path, root: nil) ⇒ Object



72
73
74
# File 'lib/proscenium/builder.rb', line 72

def self.resolve(path, root: nil)
  new(root:).resolve(path)
end

Instance Method Details

#build_to_path(path) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/proscenium/builder.rb', line 94

def build_to_path(path)
  ActiveSupport::Notifications.instrument('build_to_path.proscenium',
                                          identifier: path,
                                          cached: Proscenium.cache.exist?(path)) do
    Proscenium.cache.fetch path do
      result = Request.build_to_path(path, @request_config)

      raise BuildError, result[:response] unless result[:success]

      result[:response]
    end
  end
end

#build_to_string(path) ⇒ Object



108
109
110
111
112
113
114
115
116
# File 'lib/proscenium/builder.rb', line 108

def build_to_string(path)
  ActiveSupport::Notifications.instrument('build_to_string.proscenium', identifier: path) do
    result = Request.build_to_string(path, @request_config)

    raise BuildError, result[:response] unless result[:success]

    result[:response]
  end
end

#resolve(path) ⇒ Object



118
119
120
121
122
123
124
125
126
# File 'lib/proscenium/builder.rb', line 118

def resolve(path)
  ActiveSupport::Notifications.instrument('resolve.proscenium', identifier: path) do
    result = Request.resolve(path, @request_config)

    raise ResolveError.new(path, result[:response]) unless result[:success]

    result[:response]
  end
end