Module: Card::MachineInput

Included in:
Set::Type::CoffeeScript, Set::Type::Css, Set::Type::JavaScript, Set::Type::Skin
Defined in:
mod/03_machines/lib/card/machine_input.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Class Method Details

.included(host_class) ⇒ Object



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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'mod/03_machines/lib/card/machine_input.rb', line 15

def self.included host_class
  host_class.extend( ClassMethods )
  host_class.machines_wql = {}
  host_class.machine_input do
    format._render_raw
  end

  event_suffix = host_class.name.gsub ':', '_'

  host_class.event(
    "after_machine_input_updated_#{ event_suffix }".to_sym,
    after: :extend, on: :save
  ) do

    wql_statement = { right_plus: [
      { codename: "machine_input" },
      { link_to: name}
    ]}.merge(host_class.machines_wql)
    machines = Card.search(wql_statement)
    machines.each do |item|
      item.reset_machine_output! if item.kind_of? Machine
    end
  end

  host_class.event(
    "before_machine_input_deleted_#{ event_suffix }".to_sym,
    after: :approve, on: :delete
  ) do

    @involved_machines = Card.search(
      {right_plus: [
        {codename: "machine_input"},
        {link_to: name}
      ]}.merge(host_class.machines_wql)
    )
  end

  host_class.event(
   "after_machine_input_deleted_#{ event_suffix }".to_sym,
   after: :store_subcards, on: :delete
  ) do

    @involved_machines.each do |item|
      item.reset_machine_output! if item.kind_of? Machine
    end
  end
end