Class: CaRuby::Database::Operation

Inherits:
Object
  • Object
show all
Defined in:
lib/caruby/database/operation.rb

Overview

Database CRUD operation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, subject, opts = nil) ⇒ Operation

Returns a new instance of Operation.

Parameters:

  • type (:find, :query, :create, :update, :delete)

    the database operation type

  • subject (Persistable)

    the domain object on which the operation is performed

  • the ({Symbol => Object}, Symbol, nil)

    operation characteristics

  • opts (Hash) (defaults to: nil)

    a customizable set of options

Options Hash (opts):

  • :attribute (Symbol)

    the query attribute

  • :autogenerated (Boolean)

    whether this is an auto-generated subject update



12
13
14
15
16
17
# File 'lib/caruby/database/operation.rb', line 12

def initialize(type, subject, opts=nil)
  @type = type
  @subject = subject
  @attribute = Options.get(:attribute, opts)
  @autogenerated = Options.get(:autogenerated, opts, false)
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



5
6
7
# File 'lib/caruby/database/operation.rb', line 5

def attribute
  @attribute
end

#subjectObject (readonly)

Returns the value of attribute subject.



5
6
7
# File 'lib/caruby/database/operation.rb', line 5

def subject
  @subject
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'lib/caruby/database/operation.rb', line 5

def type
  @type
end

Instance Method Details

#autogenerated?Boolean

Returns whether this operation is an update of an auto-generated subject.

Returns:

  • (Boolean)

    whether this operation is an update of an auto-generated subject



25
26
27
# File 'lib/caruby/database/operation.rb', line 25

def autogenerated?
  @autogenerated
end

#save?Boolean

Returns whether this is a create or update.

Returns:

  • (Boolean)

    whether this is a create or update



20
21
22
# File 'lib/caruby/database/operation.rb', line 20

def save?
  @type == :create or  @type == :update
end

#to_sObject Also known as: inspect



29
30
31
# File 'lib/caruby/database/operation.rb', line 29

def to_s
  "#{@subject.qp} #{attribute} #{type}"
end