Class: Perpetuity::Postgres::SQLUpdate
- Inherits:
-
Object
- Object
- Perpetuity::Postgres::SQLUpdate
- Defined in:
- lib/perpetuity/postgres/sql_update.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
-
#initialize(klass, id, attributes) ⇒ SQLUpdate
constructor
A new instance of SQLUpdate.
- #to_s ⇒ Object
Constructor Details
#initialize(klass, id, attributes) ⇒ SQLUpdate
Returns a new instance of SQLUpdate.
9 10 11 12 13 |
# File 'lib/perpetuity/postgres/sql_update.rb', line 9 def initialize klass, id, attributes @class = klass @id = id @attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
7 8 9 |
# File 'lib/perpetuity/postgres/sql_update.rb', line 7 def attributes @attributes end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/perpetuity/postgres/sql_update.rb', line 7 def id @id end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
7 8 9 |
# File 'lib/perpetuity/postgres/sql_update.rb', line 7 def klass @klass end |
Instance Method Details
#to_s ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/perpetuity/postgres/sql_update.rb', line 15 def to_s sql = "UPDATE #{TableName.new(@class)}" if attributes.any? sql << " SET " sql << attributes.map do |name, value| value = SQLValue.new(value) if attributes.is_a? Hash "#{name} = #{value}" end.join(',') end sql << " WHERE id = #{SQLValue.new(id)}" end |