Sha256: 90cf233d9510f6adadcfeda8c83e79f36e77f0b21290496c395ae095ef886475

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

module CaRuby
  class Database
    # Database CRUD operation.
    class Operation
      attr_reader :type, :subject, :attribute

      # @param [:find, :query, :create, :update, :delete] type the database operation type
      # @param [Persistable] subject the domain object on which the operation is performed
      # @param [{Symbol => Object}, Symbol, nil] the operation characteristics
      # @option opts [Symbol] :attribute the query attribute
      # @option opts [Boolean] :autogenerated whether this is an auto-generated subject update
      def initialize(type, subject, opts=nil)
        @type = type
        @subject = subject
        @attribute = Options.get(:attribute, opts)
        @autogenerated = Options.get(:autogenerated, opts, false)
      end
      
      # @return [Boolean] whether this is a create or update
      def save?
        @type == :create or  @type == :update
      end
      
      # @return [Boolean] whether this operation is an update of an auto-generated subject
      def autogenerated?
        @autogenerated
      end
      
      def to_s
        "#{@subject.qp} #{attribute} #{type}"
      end
      
      alias :inspect :to_s
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
caruby-core-2.1.4 lib/caruby/database/operation.rb
caruby-core-2.1.3 lib/caruby/database/operation.rb
caruby-core-2.1.2 lib/caruby/database/operation.rb