Module: Alki::Execution::ContextClassBuilder

Defined in:
lib/alki/execution/context_class_builder.rb

Class Method Summary collapse

Class Method Details

.build(config) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/alki/execution/context_class_builder.rb', line 7

def self.build(config)
  if config[:body]
    methods = {
      __call__: {body: (config[:body])},
      meta: {body: ->{@__meta__}}
    }
  else
    methods = {}
  end
  (config[:lookup_methods]||config[:scope]||{}).each do |name,path|
    methods[name] = {
      body:->(*args,&blk) {
         __execute__ path, args, blk
      }
    }

    methods[:"__raw_#{name}__"] = {
      body:->(*args,&blk) {
        __executor__.execute @__meta__, path, args, blk
      },
      private: true
    }

    methods[:"__reference_#{name}__"] = {
      body:->(*args,&blk) {
        __reference__ path, args, blk
      },
    }
  end
  (config[:methods]||{}).each do |name,body|
    methods[name] = {
      body: body,
      private: name.to_s.start_with?('__'),
    }
  end
  ClassBuilder.build(
    super_class: Alki::Execution::Context,
    modules: config[:modules],
    instance_methods: methods,
  )
end