Class: Funicular::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/funicular/compiler.rb

Defined Under Namespace

Classes: NodeNotFoundError, PicorbcMissingError

Constant Summary collapse

PICORBC_DIR =

picorbc.js + picorbc.wasm bundled into the gem at build time by ‘rake copy_wasm`.

File.expand_path("vendor/picorbc", __dir__)
PICORBC_JS =
File.join(PICORBC_DIR, "picorbc.js")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_dir:, output_file:, debug_mode: false, logger: nil, prepend_source_files: []) ⇒ Compiler

Returns a new instance of Compiler.



30
31
32
33
34
35
36
# File 'lib/funicular/compiler.rb', line 30

def initialize(source_dir:, output_file:, debug_mode: false, logger: nil, prepend_source_files: [])
  @source_dir = source_dir
  @output_file = output_file
  @debug_mode = debug_mode
  @logger = logger
  @prepend_source_files = prepend_source_files.map(&:to_s)
end

Instance Attribute Details

#debug_modeObject (readonly)

Returns the value of attribute debug_mode.



28
29
30
# File 'lib/funicular/compiler.rb', line 28

def debug_mode
  @debug_mode
end

#loggerObject (readonly)

Returns the value of attribute logger.



28
29
30
# File 'lib/funicular/compiler.rb', line 28

def logger
  @logger
end

#output_fileObject (readonly)

Returns the value of attribute output_file.



28
29
30
# File 'lib/funicular/compiler.rb', line 28

def output_file
  @output_file
end

#prepend_source_filesObject (readonly)

Returns the value of attribute prepend_source_files.



28
29
30
# File 'lib/funicular/compiler.rb', line 28

def prepend_source_files
  @prepend_source_files
end

#source_dirObject (readonly)

Returns the value of attribute source_dir.



28
29
30
# File 'lib/funicular/compiler.rb', line 28

def source_dir
  @source_dir
end

Class Method Details

.source_files(source_dir) ⇒ Object

Ordered list of application source files under app/funicular/. Order matters: models -> stores -> components -> initializer, so that later files can reference classes defined earlier. Shared by the .mrb compiler (client build) and the SSR runtime (server class loading).



18
19
20
21
22
23
24
25
26
# File 'lib/funicular/compiler.rb', line 18

def self.source_files(source_dir)
  models_files = Dir.glob(File.join(source_dir, "models", "**", "*.rb")).sort
  stores_files = Dir.glob(File.join(source_dir, "stores", "**", "*.rb")).sort
  components_files = Dir.glob(File.join(source_dir, "components", "**", "*.rb")).sort
  initializer_files = Dir.glob(File.join(source_dir, "*_initializer.rb")).sort +
                      Dir.glob(File.join(source_dir, "initializer.rb")).sort

  models_files + stores_files + components_files + initializer_files
end

Instance Method Details

#compileObject



38
39
40
41
42
# File 'lib/funicular/compiler.rb', line 38

def compile
  check_picorbc_availability!
  gather_source_files
  compile_to_mrb
end