Class: LIT::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/lit/loader.rb

Overview

Since:

  • 0.1.0

Constant Summary collapse

FILE_EXTENSION =

Since:

  • 0.1.0

".lit"

Instance Method Summary collapse

Constructor Details

#initializeLoader

Returns a new instance of Loader.

Since:

  • 0.1.0



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lit/loader.rb', line 9

def initialize
  loader = self

  @target_module = Module.new do
    include ::LIT::Object

    define_singleton_method(:reload_file) do |file_path|
      loader.reload_file(file_path)
    end

    define_singleton_method(:serialize) do |object|
      Serializer.new(object).serialize
    end

    define_singleton_method(:deserialize_request) do |data|
      RequestDeserializer.new(data, self).deserialize_request
    end
  end

  @working_module = @target_module
end

Instance Method Details

#load_directory(dir_path) ⇒ Object

Since:

  • 0.1.0



31
32
33
34
35
36
37
38
39
40
# File 'lib/lit/loader.rb', line 31

def load_directory(dir_path)
  glob = File.join("**", "*#{FILE_EXTENSION}")
  @base_dir = Pathname.new(dir_path)

  Dir.glob(glob, base: dir_path) do |filename|
    load_file(filename)
  end

  @target_module
end

#reload_file(file_path) ⇒ Object

Since:

  • 0.1.0



42
43
44
45
# File 'lib/lit/loader.rb', line 42

def reload_file(file_path)
  @working_module = @target_module
  load_file(file_path)
end