Class: Alki::Dsls::Dsl

Inherits:
Alki::Dsl::Base show all
Includes:
Helpers
Defined in:
lib/alki/dsls/dsl.rb

Defined Under Namespace

Modules: Helpers

Instance Attribute Summary

Attributes inherited from Alki::Dsl::Base

#ctx

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#add_helper, #add_helper_module

Methods included from Alki::Dsl::ClassHelpers

#add_accessor, #add_class_method, #add_delegator, #add_initialize_param, #add_instance_class_proxy, #add_method, #add_module, #class_builder, #create_as_module, #set_super_class

Methods inherited from Alki::Dsl::Base

generate, #initialize

Methods included from Alki::Dsl::Builder

#build

Constructor Details

This class inherits a constructor from Alki::Dsl::Base

Class Method Details

.dsl_infoObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/alki/dsls/dsl.rb', line 28

def self.dsl_info
  {
    requires: [['alki/dsls/class',:before]],
    methods: [
      :dsl_method,
      [:init,:dsl_init],
      [:finish,:dsl_finish],
      :require_dsl,
      :helper,
      :helper_module
    ],
    init: :init,
    finish: :finish
  }
end

.helpersObject



24
25
26
# File 'lib/alki/dsls/dsl.rb', line 24

def self.helpers
  [Helpers]
end

Instance Method Details

#dsl_finish(&blk) ⇒ Object



64
65
66
67
# File 'lib/alki/dsls/dsl.rb', line 64

def dsl_finish(&blk)
  add_method :_dsl_finish, private: true, &blk
  @info[:finish] = :_dsl_finish
end

#dsl_init(&blk) ⇒ Object



59
60
61
62
# File 'lib/alki/dsls/dsl.rb', line 59

def dsl_init(&blk)
  add_method :_dsl_init, private: true, &blk
  @info[:init] = :_dsl_init
end

#dsl_method(name, &blk) ⇒ Object



53
54
55
56
57
# File 'lib/alki/dsls/dsl.rb', line 53

def dsl_method(name, &blk)
  method_name = name.to_sym
  add_method method_name, private: true, &blk
  @info[:methods] << [name.to_sym,method_name]
end

#finishObject



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/alki/dsls/dsl.rb', line 86

def finish
  set_super_class 'alki/dsl/base'
  create_as_module(subclass: 'Helpers')

  add_class_method :helpers do
    [self::Helpers]
  end
  info = @info.freeze
  add_class_method :dsl_info do
    info
  end

  add_method(:require_dsl,private: true) do |dsl,order=:before|
    dsl_class = Alki.load dsl
    dsl_class.helpers.each do |helper|
      self.singleton_class.send :include, helper
    end
    @evaluator.update requires: [[dsl,order]]
  end
end

#helper(name, &blk) ⇒ Object



78
79
80
# File 'lib/alki/dsls/dsl.rb', line 78

def helper(name,&blk)
  add_helper name, &blk
end

#helper_module(mod) ⇒ Object



82
83
84
# File 'lib/alki/dsls/dsl.rb', line 82

def helper_module(mod)
  add_helper_module mod
end

#initObject



44
45
46
47
48
49
50
51
# File 'lib/alki/dsls/dsl.rb', line 44

def init
  @info = {
    methods: [],
    requires: []
  }
  @helper_modules = []
  @helpers = {}
end

#require_dsl(dsl, order = :before) ⇒ Object



69
70
71
72
73
74
75
76
# File 'lib/alki/dsls/dsl.rb', line 69

def require_dsl(dsl, order=:before)
  dsl_class = Alki.load dsl
  @info[:requires] << [dsl,order]
  dsl_class.helpers.each do |helper|
    add_module helper
    add_helper_module helper
  end
end