Class: Swift::Scheme
- Inherits:
-
Object
- Object
- Swift::Scheme
- Defined in:
- lib/swift/scheme.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
-
.all(conditions = '', *binds, &block) ⇒ Swift::Result
Select one or more.
-
.attribute(name, type, options = {}) ⇒ Object
Define a new attribute for this scheme.
-
.create(resources = {}) ⇒ Object
Create (insert).
-
.first(conditions = '', *binds, &block) ⇒ Swift::Scheme?
Select one.
-
.get(keys) ⇒ Swift::Scheme?
Select by id(s).
- .inherited(klass) ⇒ Object
-
.load(tuple) ⇒ Object
– TODO: Redefined method :(.
- .migrate!(db = Swift.db) ⇒ Object
- .migrations(&migrations) ⇒ Object
-
.store(name = nil) ⇒ Symbol
Define the store (table).
- .validations(&validations) ⇒ Object
Instance Method Summary collapse
- #destroy(resources = self) ⇒ 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.
24 25 26 27 |
# File 'lib/swift/scheme.rb', line 24 def initialize = {} @tuple = scheme.header.new_tuple .each{|k, v| send(:"#{k}=", v)} end |
Class Attribute Details
.header ⇒ Swift::Header
Attribute set.
58 59 60 |
# File 'lib/swift/scheme.rb', line 58 def header @header end |
Instance Attribute Details
#tuple ⇒ Object
Returns the value of attribute tuple.
14 15 16 |
# File 'lib/swift/scheme.rb', line 14 def tuple @tuple end |
Class Method Details
.all(conditions = '', *binds, &block) ⇒ Swift::Result
Select one or more.
131 132 133 |
# File 'lib/swift/scheme.rb', line 131 def all conditions = '', *binds, &block Swift.db.all(self, conditions, *binds, &block) end |
.attribute(name, type, options = {}) ⇒ Object
Define a new attribute for this scheme.
76 77 78 79 |
# File 'lib/swift/scheme.rb', line 76 def attribute name, type, = {} header.push(attribute = type.new(self, name, )) (class << self; self end).send(:define_method, name, lambda{ attribute }) end |
.create(resources = {}) ⇒ Object
Create (insert).
99 100 101 |
# File 'lib/swift/scheme.rb', line 99 def create resources = {} Swift.db.create(self, resources) end |
.first(conditions = '', *binds, &block) ⇒ Swift::Scheme?
Select one.
150 151 152 |
# File 'lib/swift/scheme.rb', line 150 def first conditions = '', *binds, &block Swift.db.first(self, conditions, *binds, &block) end |
.get(keys) ⇒ Swift::Scheme?
Select by id(s).
112 113 114 |
# File 'lib/swift/scheme.rb', line 112 def get keys Swift.db.get(self, keys) end |
.inherited(klass) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/swift/scheme.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 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) ⇒ Symbol
Define the store (table).
85 86 87 |
# File 'lib/swift/scheme.rb', line 85 def store name = nil name ? @store = name : @store end |
Instance Method Details
#destroy(resources = self) ⇒ Object
50 51 52 |
# File 'lib/swift/scheme.rb', line 50 def destroy resources = self Swift.db.destroy(scheme, resources) end |
#update(options = {}) ⇒ Object
38 39 40 41 |
# File 'lib/swift/scheme.rb', line 38 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 |