Sha256: cfaee423abdeb5415e9c5e1ad9b634bdf4e3fba034a0f4f51ce6b3b18be89c1c

Contents?: true

Size: 1.53 KB

Versions: 14

Compression:

Stored size: 1.53 KB

Contents

class Card
  module MachineInput
    module ClassMethods
      attr_accessor :machines_wql

      def machine_input_for args
        @machines_wql = args
      end

      def machine_input &block
        define_method :machine_input, block
      end
    end

    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
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
card-1.17.4 mod/03_machines/lib/card/machine_input.rb
card-1.17.3 mod/03_machines/lib/card/machine_input.rb
card-1.17.2 mod/03_machines/lib/card/machine_input.rb
card-1.17.1 mod/03_machines/lib/card/machine_input.rb
card-1.17.0 mod/03_machines/lib/card/machine_input.rb
card-1.16.15 mod/03_machines/lib/card/machine_input.rb
card-1.16.14 mod/03_machines/lib/card/machine_input.rb
card-1.16.13 mod/03_machines/lib/card/machine_input.rb
card-1.16.12 mod/03_machines/lib/card/machine_input.rb
card-1.16.11 mod/03_machines/lib/card/machine_input.rb
card-1.16.10 mod/03_machines/lib/card/machine_input.rb
card-1.16.9 mod/03_machines/lib/card/machine_input.rb
card-1.16.8 mod/03_machines/lib/card/machine_input.rb
card-1.16.7 mod/03_machines/lib/card/machine_input.rb