schemer 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/schemer.rb +1 -1
- data/lib/schemer/active_record.rb +16 -0
- data/lib/schemer/sequel.rb +18 -10
- metadata +3 -3
data/lib/schemer.rb
CHANGED
|
@@ -2,6 +2,22 @@ require "active_record"
|
|
|
2
2
|
|
|
3
3
|
module Schemer
|
|
4
4
|
module ActiveRecord
|
|
5
|
+
# Define a schema on your ActiveRecord model.
|
|
6
|
+
#
|
|
7
|
+
# schema :name, { :age => :integer }, { :birthdate => :datetime }, :summary
|
|
8
|
+
#
|
|
9
|
+
# Table + columns will be added automatically based on your definition.
|
|
10
|
+
#
|
|
11
|
+
# If you remove a column, it will be removed from the table the next time
|
|
12
|
+
# the class is loaded.
|
|
13
|
+
#
|
|
14
|
+
# If you change the type of a column, it will be also be updated the next
|
|
15
|
+
# time the class is loaded.
|
|
16
|
+
#
|
|
17
|
+
# Likewise, adding a new column will add the column to your schema on the
|
|
18
|
+
# next class load.
|
|
19
|
+
#
|
|
20
|
+
# Columns with no types are assumed to be strings.
|
|
5
21
|
def schema(*args)
|
|
6
22
|
extend ClassMethods
|
|
7
23
|
|
data/lib/schemer/sequel.rb
CHANGED
|
@@ -2,8 +2,23 @@ require "sequel"
|
|
|
2
2
|
|
|
3
3
|
module Schemer
|
|
4
4
|
module Sequel
|
|
5
|
-
module ClassMethods
|
|
6
|
-
#
|
|
5
|
+
module ClassMethods
|
|
6
|
+
# Define a schema on your Sequel model.
|
|
7
|
+
#
|
|
8
|
+
# schema :name, { :age => :integer }, { :birthdate => :datetime }, :summary
|
|
9
|
+
#
|
|
10
|
+
# Table + columns will be added automatically based on your definition.
|
|
11
|
+
#
|
|
12
|
+
# If you remove a column, it will be removed from the table the next time
|
|
13
|
+
# the class is loaded.
|
|
14
|
+
#
|
|
15
|
+
# If you change the type of a column, it will be also be updated the next
|
|
16
|
+
# time the class is loaded.
|
|
17
|
+
#
|
|
18
|
+
# Likewise, adding a new column will add the column to your schema on the
|
|
19
|
+
# next class load.
|
|
20
|
+
#
|
|
21
|
+
# Columns with no types are assumed to be strings.
|
|
7
22
|
def schema(*args)
|
|
8
23
|
@schema_columns = {}
|
|
9
24
|
|
|
@@ -20,14 +35,7 @@ module Schemer
|
|
|
20
35
|
|
|
21
36
|
def schema_columns
|
|
22
37
|
@schema_columns
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
# Update ActiveRecord's automatically generated methods so we don't have to
|
|
26
|
-
# reload for schema changes to take effect
|
|
27
|
-
def update_methods
|
|
28
|
-
# undefine_attribute_methods
|
|
29
|
-
# @columns = @column_names = @columns_hash = @generated_methods = nil
|
|
30
|
-
end
|
|
38
|
+
end
|
|
31
39
|
|
|
32
40
|
# Update the underlying schema as defined by schema call
|
|
33
41
|
def update_schema
|
metadata
CHANGED