Class: Swift::Scheme
- Inherits:
-
Object
- Object
- Swift::Scheme
- Defined in:
- lib/swift/validations.rb,
lib/swift/scheme.rb,
lib/swift/migrations.rb,
lib/swift/identity_map.rb
Overview
Errors
Class Attribute Summary collapse
-
.header ⇒ Object
Returns the value of attribute header.
Instance Attribute Summary collapse
-
#tuple ⇒ Object
Returns the value of attribute tuple.
Class Method Summary collapse
- .all(conditions = '', *binds, &block) ⇒ Object
- .attribute(name, type, options = {}) ⇒ Object
- .create(options = {}) ⇒ Object
- .first(conditions = '', *binds, &block) ⇒ Object
- .get(keys) ⇒ Object
- .inherited(klass) ⇒ Object
-
.load(tuple) ⇒ Object
– TODO: Redefined method :(.
- .migrate!(db = Swift.db) ⇒ Object
- .migrations(&migrations) ⇒ Object
- .store(name = nil) ⇒ Object
- .validations(&validations) ⇒ Object
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(options = {}) ⇒ Scheme
constructor
A new instance of Scheme.
- #update(options = {}) ⇒ Object
- #valid? ⇒ Boolean
- #validate(errors = Errors.new(self)) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Scheme
Returns a new instance of Scheme.
6 7 8 9 |
# File 'lib/swift/scheme.rb', line 6 def initialize = {} @tuple = scheme.header.new_tuple .each{|k, v| send(:"#{k}=", v)} end |
Class Attribute Details
.header ⇒ Object
Returns the value of attribute header.
21 22 23 |
# File 'lib/swift/scheme.rb', line 21 def header @header end |
Instance Attribute Details
#tuple ⇒ Object
Returns the value of attribute tuple.
3 4 5 |
# File 'lib/swift/scheme.rb', line 3 def tuple @tuple end |
Class Method Details
.all(conditions = '', *binds, &block) ⇒ Object
52 53 54 |
# File 'lib/swift/scheme.rb', line 52 def all conditions = '', *binds, &block Swift.db.all(self, conditions, *binds, &block) end |
.attribute(name, type, options = {}) ⇒ Object
35 36 37 38 |
# File 'lib/swift/scheme.rb', line 35 def attribute name, type, = {} header.push(attribute = type.new(self, name, )) (class << self; self end).send(:define_method, name, lambda{ attribute }) end |
.create(options = {}) ⇒ Object
44 45 46 |
# File 'lib/swift/scheme.rb', line 44 def create = {} Swift.db.create(self, ) end |
.first(conditions = '', *binds, &block) ⇒ Object
56 57 58 |
# File 'lib/swift/scheme.rb', line 56 def first conditions = '', *binds, &block Swift.db.first(self, conditions, *binds, &block) end |
.get(keys) ⇒ Object
48 49 50 |
# File 'lib/swift/scheme.rb', line 48 def get keys Swift.db.get(self, keys) end |
.inherited(klass) ⇒ Object
23 24 25 26 27 |
# File 'lib/swift/scheme.rb', line 23 def inherited klass klass.header = Header.new klass.header.push(*header) if header 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 scheme = allocate scheme.tuple = tuple scheme end |
.migrate!(db = Swift.db) ⇒ Object
7 8 9 |
# File 'lib/swift/migrations.rb', line 7 def self.migrate! db = Swift.db db.migrate! self end |
.migrations(&migrations) ⇒ Object
3 4 5 |
# File 'lib/swift/migrations.rb', line 3 def self.migrations &migrations (class << self; self end).send :define_method, :migrate!, lambda{|db = Swift.db| migrations.call(db) } end |
.store(name = nil) ⇒ Object
40 41 42 |
# File 'lib/swift/scheme.rb', line 40 def store name = nil name ? @store = name : @store end |
Instance Method Details
#destroy ⇒ Object
16 17 18 |
# File 'lib/swift/scheme.rb', line 16 def destroy Swift.db.destroy(scheme, self) end |
#update(options = {}) ⇒ Object
11 12 13 14 |
# File 'lib/swift/scheme.rb', line 11 def update = {} .each{|k, v| send(:"#{k}=", v)} Swift.db.update(scheme, self) end |
#valid? ⇒ Boolean
23 24 25 |
# File 'lib/swift/validations.rb', line 23 def valid? validate.empty? end |