Created
August 16, 2010 22:31
-
-
Save deepfryed/527877 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/examples/db.rb b/examples/db.rb | |
index da5b728..c43daf1 100755 | |
--- a/examples/db.rb | |
+++ b/examples/db.rb | |
@@ -8,9 +8,9 @@ require 'swift/migrations' | |
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 :id, Integer, serial: true, key: true | |
+ attribute :name, String | |
+ attribute :email, String | |
end # User | |
adapter = ARGV.first =~ /mysql/i ? Swift::DB::Mysql : Swift::DB::Postgres | |
diff --git a/examples/scheme.rb b/examples/scheme.rb | |
index 0e9bf64..f8f5d19 100755 | |
--- a/examples/scheme.rb | |
+++ b/examples/scheme.rb | |
@@ -9,12 +9,12 @@ require 'swift/validations' | |
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 :active, Swift::Type::Boolean | |
- attribute :created, Swift::Type::Time, default: proc { Time.now } | |
- attribute :optional, Swift::Type::String, default: 'woot' | |
+ attribute :id, Integer, serial: true, key: true | |
+ attribute :name, String | |
+ attribute :email, String | |
+ attribute :active, Boolean | |
+ attribute :created, Time, default: proc { Time.now } | |
+ attribute :optional, String, default: 'woot' | |
validations do |errors| | |
errors << [:name, 'is blank'] if name.to_s.empty? | |
diff --git a/lib/swift/scheme.rb b/lib/swift/scheme.rb | |
index 845eb03..37fc11d 100644 | |
--- a/lib/swift/scheme.rb | |
+++ b/lib/swift/scheme.rb | |
@@ -33,6 +33,7 @@ module Swift | |
end | |
def attribute name, type, options = {} | |
+ type = Swift::Type.const_get(type.name) rescue type | |
header.push(attribute = type.new(self, name, options)) | |
(class << self; self end).send(:define_method, name, lambda{ attribute }) | |
end | |
diff --git a/lib/swift/type.rb b/lib/swift/type.rb | |
index 4a7a187..016aabd 100644 | |
--- a/lib/swift/type.rb | |
+++ b/lib/swift/type.rb | |
@@ -8,5 +8,9 @@ module Swift | |
class String < Attribute; end | |
class Time < Attribute; end | |
end # Type | |
+ | |
+ class Scheme | |
+ Boolean = Type::Boolean | |
+ end # Scheme | |
end # Swift | |
diff --git a/test/test_io.rb b/test/test_io.rb | |
index eec8363..a6e82ad 100644 | |
--- a/test/test_io.rb | |
+++ b/test/test_io.rb | |
@@ -6,9 +6,9 @@ describe 'Adapter' do | |
before do | |
user = Class.new(Swift::Scheme) do | |
store :users | |
- attribute :id, Swift::Type::Integer, serial: true, key: true | |
- attribute :name, Swift::Type::String | |
- attribute :image, Swift::Type::IO | |
+ attribute :id, Integer, serial: true, key: true | |
+ attribute :name, String | |
+ attribute :image, IO | |
end | |
Swift.db.migrate! user | |
end | |
diff --git a/test/test_validations.rb b/test/test_validations.rb | |
index b23249f..3eca63a 100644 | |
--- a/test/test_validations.rb | |
+++ b/test/test_validations.rb | |
@@ -5,8 +5,8 @@ describe 'validations' do | |
before do | |
@user = Class.new(Swift::Scheme) do | |
store :users | |
- attribute :id, Swift::Type::Integer, serial: true, key: true | |
- attribute :name, Swift::Type::String | |
+ attribute :id, Integer, serial: true, key: true | |
+ attribute :name, String | |
validations do |errors| | |
errors << [:name, 'is blank'] if name.to_s.empty? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment