Sha256: 7fea0271a47ab0eeb25dd13a1f77626bdfb5141510781c0697f0717af9718ce8

Contents?: true

Size: 1.24 KB

Versions: 12

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

# Copyright (c) 2016 Andy Pike - The MIT license
#
# This file has been copied from https://github.com/andypike/rectify/blob/master/lib/rectify/command.rb
# We have done this so we can decouple Decidim from any Virtus dependency, which is a dead project
# Please follow Decidim discussion to understand more https://github.com/decidim/decidim/discussions/7234
module Decidim
  class Command
    include ::Wisper::Publisher

    def self.call(*args, **kwargs, &block)
      event_recorder = Decidim::EventRecorder.new

      command = new(*args, **kwargs)
      command.subscribe(event_recorder)
      command.evaluate(&block) if block_given?
      command.call

      event_recorder.events
    end

    def evaluate(&block)
      @caller = eval("self", block.binding, __FILE__, __LINE__)
      instance_eval(&block)
    end

    def transaction(&block)
      ActiveRecord::Base.transaction(&block) if block_given?
    end

    def method_missing(method_name, ...)
      if @caller.respond_to?(method_name, true)
        @caller.send(method_name, ...)
      else
        super
      end
    end

    def respond_to_missing?(method_name, include_private = false)
      @caller.respond_to?(method_name, include_private)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
decidim-core-0.27.9 lib/decidim/command.rb
decidim-core-0.27.8 lib/decidim/command.rb
decidim-core-0.27.7 lib/decidim/command.rb
decidim-core-0.27.6 lib/decidim/command.rb
decidim-core-0.27.5 lib/decidim/command.rb
decidim-core-0.27.4 lib/decidim/command.rb
decidim-core-0.27.3 lib/decidim/command.rb
decidim-core-0.27.2 lib/decidim/command.rb
decidim-core-0.27.1 lib/decidim/command.rb
decidim-core-0.27.0 lib/decidim/command.rb
decidim-core-0.27.0.rc2 lib/decidim/command.rb
decidim-core-0.27.0.rc1 lib/decidim/command.rb