Class: Swift::Record
- Inherits:
-
Object
- Object
- Swift::Record
- Extended by:
- Migrations::ClassMethods
- Defined in:
- lib/swift/record.rb,
lib/swift/migrations.rb,
lib/swift/validations.rb,
lib/swift/identity_map.rb
Overview
Errors
Class Attribute Summary collapse
-
.header ⇒ Swift::Header
Attribute set.
Instance Attribute Summary collapse
-
#tuple ⇒ Object
Returns the value of attribute tuple.
Class Method Summary collapse
-
.attribute(name, type, options = {}) ⇒ Object
Define a new attribute for this record.
-
.create(resources = {}) ⇒ Object
Create (insert).
-
.execute(statement = '', *binds) {|Swift::Result| ... } ⇒ Swift::Result
Execute a single statement.
-
.get(keys) ⇒ Swift::Record?
Select by id(s).
- .inherited(klass) ⇒ Object
-
.load(tuple) ⇒ Object
– TODO: Redefined method :(.
-
.prepare(statement = '') ⇒ Swift::Statement
Prepare a statement for on or more executions.
-
.store(name = nil) ⇒ Symbol
Define the store (table).
-
.to_s ⇒ String
Store (table) name.
- .validations(&validations) ⇒ Object
Instance Method Summary collapse
- #delete(resources = self) ⇒ Object
-
#initialize(options = {}) ⇒ Record
constructor
A new instance of Record.
- #update(options = {}) ⇒ Object
- #valid? ⇒ Boolean
- #validate(errors = Errors.new(self)) ⇒ Object
Methods included from Migrations::ClassMethods
Constructor Details
#initialize(options = {}) ⇒ Record
Returns a new instance of Record.
24 25 26 27 |
# File 'lib/swift/record.rb', line 24 def initialize = {} @tuple = record.header.new_tuple .each{|k, v| public_send(:"#{k}=", v)} end |
Class Attribute Details
.header ⇒ Swift::Header
Attribute set.
58 59 60 |
# File 'lib/swift/record.rb', line 58 def header @header end |
Instance Attribute Details
#tuple ⇒ Object
Returns the value of attribute tuple.
14 15 16 |
# File 'lib/swift/record.rb', line 14 def tuple @tuple end |
Class Method Details
.attribute(name, type, options = {}) ⇒ Object
Define a new attribute for this record.
76 77 78 79 |
# File 'lib/swift/record.rb', line 76 def attribute name, type, = {} header.push(attribute = type.new(self, name, )) define_singleton_method(name, lambda{ attribute }) end |
.create(resources = {}) ⇒ Object
Create (insert).
106 107 108 |
# File 'lib/swift/record.rb', line 106 def create resources = {} Swift.db.create(self, resources) end |
.execute(statement = '', *binds) {|Swift::Result| ... } ⇒ Swift::Result
Execute a single statement.
146 147 148 |
# File 'lib/swift/record.rb', line 146 def execute statement = '', *binds Swift::Result.new(self, Swift.db.execute(statement, *binds)) end |
.get(keys) ⇒ Swift::Record?
Select by id(s).
119 120 121 |
# File 'lib/swift/record.rb', line 119 def get keys Swift.db.get(self, keys) end |
.inherited(klass) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/swift/record.rb', line 60 def inherited klass klass.header = Header.new klass.header.push(*header) if header klass.store store if store Swift.schema.push(klass) if klass.name end |
.load(tuple) ⇒ Object
– TODO: Redefined method :(
39 40 41 42 43 |
# File 'lib/swift/identity_map.rb', line 39 def load tuple record = allocate record.tuple = tuple record end |
.prepare(statement = '') ⇒ Swift::Statement
Prepare a statement for on or more executions.
132 133 134 |
# File 'lib/swift/record.rb', line 132 def prepare statement = '' Swift.db.prepare(self, statement) end |
.store(name = nil) ⇒ Symbol
Define the store (table).
85 86 87 |
# File 'lib/swift/record.rb', line 85 def store name = nil name ? @store = name : @store end |
.to_s ⇒ String
Store (table) name.
92 93 94 |
# File 'lib/swift/record.rb', line 92 def to_s store.to_s end |
Instance Method Details
#delete(resources = self) ⇒ Object
50 51 52 |
# File 'lib/swift/record.rb', line 50 def delete resources = self Swift.db.delete(record, resources) end |
#update(options = {}) ⇒ Object
38 39 40 41 |
# File 'lib/swift/record.rb', line 38 def update = {} .each{|k, v| public_send(:"#{k}=", v)} Swift.db.update(record, self) end |
#valid? ⇒ Boolean
23 24 25 |
# File 'lib/swift/validations.rb', line 23 def valid? validate.empty? end |