Sha256: 8d95e5390c9cf94a2959005a060f4ef552ab846b952b3bf7271f06822247a55f

Contents?: true

Size: 1.18 KB

Versions: 3

Compression:

Stored size: 1.18 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 &block
        self.director = nil
        Director.run_act(self) do
          run_callbacks(:act, &block)
        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

3 entries across 3 versions & 1 rubygems

Version Path
card-1.101.7 lib/card/director/all.rb
card-1.101.6 lib/card/director/all.rb
card-1.101.5 lib/card/director/all.rb