Module: Tengine::Core::DslLoader

Includes:
DslEvaluator
Defined in:
lib/tengine/core/dsl_loader.rb

Instance Attribute Summary collapse

Attributes included from DslEvaluator

#config

Instance Method Summary collapse

Methods included from DslEvaluator

#__evaluate__, #__safety_driver__, #__safety_event__

Instance Attribute Details

#__kernel__Object

Returns the value of attribute __kernel__.



7
8
9
# File 'lib/tengine/core/dsl_loader.rb', line 7

def __kernel__
  @__kernel__
end

Instance Method Details

#ack_policy(policy, *args) ⇒ Object

どのようなポリシーでackを返すのかをイベント種別名毎に指定できます。

例:

例:

例:

Parameters:

  • policy (Symbol)

    ackポリシー

  • args ([Symbol/String])

    イベント種別名の配列



24
25
26
# File 'lib/tengine/core/dsl_loader.rb', line 24

def ack_policy(policy, *args)
  args.each{|arg| @__kernel__.add_ack_policy(arg, policy)}
end

#driver(name, options = {}, &block) ⇒ Tengine::Core::Driver

イベントドライバを登録します。

イベントドライバはonメソッドで定義されるイベントハンドラを持つことができます。 イベントドライバは実行時のユーザーによる有効化、無効化の対象になります。 無効化されたイベントドライバのイベントハンドラは、イベントが発生した際に それがフィルタにマッチしたとしても、その処理を実行しません。 つまりイベントハンドラの有効化、無効化は、それをまとめているイベントドライバ毎に 指定することが可能です。

例:

Parameters:

  • name (String)

    イベントドライバ名

  • options (Hash) (defaults to: {})

    オプション

Options Hash (options):

  • :enabled_on_activation (String)

    実行時に有効にするならばtrue、でなければfalse。デフォルトはtrue

Returns:

See Also:

  • #on


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/tengine/core/dsl_loader.rb', line 55

def driver(name, options = {}, &block)
  unless block_given?
    # Tengine::Core::stdout.info("no block given at #{caller.first}")
    return
  end

  if dsl_version_document = Tengine::Core::Setting.where({:name => "dsl_version"}).first
    dsl_version_document.value = config.dsl_version
    dsl_version_document.save!
  else
    Tengine::Core::Setting.create!(:name => "dsl_version", :value => config.dsl_version)
  end
  c = config
  klass = Class.new
  const_name = name.to_s.camelize
#     if Object.constants.include?(const_name) || defined?(const_name)
#       puts "#{const_name} is already defined\n  " << caller.join("\n  ")
#     end
  Object.send :remove_const, const_name if Object.const_defined? const_name
  Object.const_set(const_name, klass)
  klass.module_eval do
    include Tengine::Core::Driveable::ByDsl
    self.singleton_class.config = c
    self.singleton_class.options = options
    include Tengine::Core::Driveable
  end
  begin
    klass.module_eval(&block)
  rescue Exception => e
    driver = klass.driver
    driver.destroy if driver && !driver.new_record?
    raise e
  end
end

#dsl_version(*args) ⇒ Object

現時点ではMM1との互換性のためのダミーのメソッドです 必要があれば将来ちゃんと役割を見直して復活するかもしれません



105
106
# File 'lib/tengine/core/dsl_loader.rb', line 105

def dsl_version(*args)
end

#fire(*args, &blcok) ⇒ Object



96
97
98
99
100
101
# File 'lib/tengine/core/dsl_loader.rb', line 96

def fire(*args, &blcok)
  options = args.extract_options!
  options[:keep_connection] = true
  args = args + [options]
  Tengine::Event.fire(*args, &blcok)
end

#sessionObject

Raises:

See Also:

  • Tengine::Core::DslBinder#session


91
92
93
94
# File 'lib/tengine/core/dsl_loader.rb', line 91

def session
  raise Tengine::Core::DslError, "session is not available outside of event driver block." unless @__session__
  @__session_wrapper__ ||= Tengine::Core::SessionWrapper.new(@__session__)
end

#setup_eventmachine(&block) ⇒ Object

このメソッドにブロックを渡すことで、Tengineコアが使用するEventMachineの初期化を行うために設定を行うことができます。

例:



33
34
35
36
# File 'lib/tengine/core/dsl_loader.rb', line 33

def setup_eventmachine(&block)
  return unless block
  @__kernel__.em_setup_blocks << block
end