Sha256: 747f33b671641cc5347e50ce46032235c8a6d819fd6b5f1b16447fe9e9fa179f

Contents?: true

Size: 1.17 KB

Versions: 1

Compression:

Stored size: 1.17 KB

Contents

class Card
  class Director
    # director-related Card instance methods
    module All
      def act options={}, &block
        if act_card
          add_to_act options, &block
        else
          start_new_act(&block)
        end
      end

      def act_card
        Card::Director.act_card
      end

      def act_card?
        self == act_card
      end

      def save! *args
        as_subcard = args.first&.delete :as_subcard
        act(as_subcard: as_subcard) { super }
      end

      def save *args
        act { super }
      end

      def valid? *args
        act(validating: true) { super }
      end

      def update *args
        act { super }
      end

      def update! *args
        act { super }
      end

      alias_method :update_attributes, :update
      alias_method :update_attributes!, :update!

      private

      def start_new_act
        self.director = nil
        Director.run_act(self) do
          run_callbacks(:act) { yield }
        end
      end

      def add_to_act options={}
        director.appoint self unless @director
        director.head = true unless options[:validating] || options[:as_subcard]
        yield
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
card-1.101.4 lib/card/director/all.rb