Class: Proscenium::Builder

Inherits:
Object
  • 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.



73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/proscenium/builder.rb', line 73

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),
    EnvVars: env_vars,
    CodeSplitting: Proscenium.config.code_splitting,
    RubyGems: Proscenium::BundledGems.paths,
    Bundle: Proscenium.config.bundle,
    QueryString: cache_query_string,
    Debug: Proscenium.config.debug
  }.to_json)
end

Class Method Details

.build_to_string(path, root: nil) ⇒ Object



60
61
62
# File 'lib/proscenium/builder.rb', line 60

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

.reset_config!Object

Intended for tests only.



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

def self.reset_config!
  Request.reset_config
end

.resolve(path, root: nil) ⇒ Object



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

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

Instance Method Details

#build_to_string(path) ⇒ Object



87
88
89
90
91
92
93
94
95
# File 'lib/proscenium/builder.rb', line 87

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

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

    result
  end
end

#resolve(path) ⇒ Object



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

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