Module: Card::MachineInput
- Included in:
- Set::Type::CoffeeScript, Set::Type::Css, Set::Type::JavaScript, Set::Type::Skin
- Defined in:
- mod/machines/lib/card/machine_input.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
- .define_delete_events(event_suffix, host_class) ⇒ Object
- .define_update_event(event_suffix, host_class) ⇒ Object
- .included(host_class) ⇒ Object
- .search_involved_machines(name, host_class) ⇒ Object
Instance Method Summary collapse
Class Method Details
.define_delete_events(event_suffix, host_class) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'mod/machines/lib/card/machine_input.rb', line 26 def self.define_delete_events event_suffix, host_class event_name = "before_machine_input_deleted_#{event_suffix}".to_sym host_class.event event_name, :store, on: :delete do # exclude self because it's on the way to the trash # otherwise it will be created again with the reset_machine_output # call in the event below @involved_machines = Card::MachineInput.search_involved_machines(name, host_class) .reject { |card| card == self } end event_name = "after_machine_input_deleted_#{event_suffix}".to_sym host_class.event event_name, :finalize, on: :delete do expire_machine_cache @involved_machines.each do |item| item.reset_machine_output if item.is_a? Machine end end end |
.define_update_event(event_suffix, host_class) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'mod/machines/lib/card/machine_input.rb', line 45 def self.define_update_event event_suffix, host_class host_class.event( "after_machine_input_updated_#{event_suffix}".to_sym, :integrate, on: :save ) do expire_machine_cache Card::MachineInput.search_involved_machines(name, host_class) .each do |item| item.reset_machine_output if item.is_a? Machine end end end |
.included(host_class) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'mod/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.tr ":", "_" define_update_event event_suffix, host_class define_delete_events event_suffix, host_class end |
.search_involved_machines(name, host_class) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'mod/machines/lib/card/machine_input.rb', line 58 def self.search_involved_machines name, host_class wql_statement = { right_plus: [ { codename: "machine_input" }, { link_to: name } ] }.merge(host_class.machines_wql) Card.search(wql_statement) end |
Instance Method Details
#expire_machine_cache ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'mod/machines/lib/card/machine_input.rb', line 67 def expire_machine_cache Card.search(right_plus: [ { codename: "machine_input" }, { link_to: name } ], return: :name).each do |machine_name| next unless (cache = Card.fetch(name, machine_name, :machine_cache)) Auth.as_bot do cache.update_attributes! trash: true end end end |