lib/swift/scheme.rb in swift-0.8.1 vs lib/swift/scheme.rb in swift-0.9.0
- old
+ new
@@ -1,30 +1,28 @@
module Swift
- # A relation (instance) definition.
+ # A resource (instance) definition.
#
# @example A user scheme.
# class User < Swift::Scheme
# store :users
# attribute :id, Swift::Type::Integer, serial: true, key: true
# attribute :name, Swift::Type::String
# attribute :email, Swift::Type::String
# attribute :updated_at, Swift::Type::Time
# end # User
- #
- # @todo Tuple should be renamed tuples (plural?)
class Scheme
attr_accessor :tuple
alias_method :scheme, :class
# @example
# User.new(
# name: 'Apple Arthurton',
# email: 'apple@arthurton.local',
# updated_at: Time.now
# )
- # @param [Hash] options Create relation and set attributes. <tt>{name: value}</tt>
+ # @param [Hash] options Create resource and set attributes. <tt>{name: value}</tt>
def initialize options = {}
@tuple = scheme.header.new_tuple
options.each{|k, v| send(:"#{k}=", v)}
end
@@ -47,12 +45,12 @@
# name: 'Apple Arthurton',
# email: 'apple@arthurton.local',
# updated_at: Time.now
# )
# apple.destroy
- def destroy
- Swift.db.destroy(scheme, self)
+ def destroy resources = self
+ Swift.db.destroy(scheme, resources)
end
class << self
# Attribute set.
#
@@ -60,10 +58,11 @@
attr_accessor :header
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
def load tuple
scheme = allocate
@@ -94,12 +93,12 @@
# name: 'Apple Arthurton',
# email: 'apple@arthurton.local',
# updated_at: Time.now
# )
#
- # @param [Hash] options Create with attributes. <tt>{name: value}</tt>
- def create options = {}
- Swift.db.create(self, options)
+ # @param [Hash, Array<Hash>] options Create with attributes. <tt>{name: value}</tt>
+ def create resources = {}
+ Swift.db.create(self, resources)
end
# Select by id(s).
#
# @example Single key.