citrusbyte-schemer 0.0.5 → 0.0.6
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 +4 -10
- data/test/schemer_test.rb +12 -8
- metadata +2 -2
data/lib/schemer.rb
CHANGED
|
@@ -2,11 +2,13 @@ require 'activerecord'
|
|
|
2
2
|
|
|
3
3
|
module Schemer
|
|
4
4
|
def schema(*args)
|
|
5
|
-
extend
|
|
6
|
-
include InstanceMethods
|
|
5
|
+
extend ClassMethods
|
|
7
6
|
|
|
8
7
|
class_inheritable_accessor :schema_columns
|
|
9
8
|
self.schema_columns = args.collect(&:to_s)
|
|
9
|
+
|
|
10
|
+
update_schema
|
|
11
|
+
update_methods
|
|
10
12
|
end
|
|
11
13
|
|
|
12
14
|
module ClassMethods
|
|
@@ -35,14 +37,6 @@ module Schemer
|
|
|
35
37
|
(column_names - protected_columns - schema_columns).each { |column| ActiveRecord::Migration.remove_column(table_name, column) }
|
|
36
38
|
end
|
|
37
39
|
end
|
|
38
|
-
|
|
39
|
-
module InstanceMethods
|
|
40
|
-
def initialize(*args)
|
|
41
|
-
self.class.update_schema
|
|
42
|
-
self.class.update_methods
|
|
43
|
-
super
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
40
|
end
|
|
47
41
|
|
|
48
42
|
ActiveRecord::Base.extend(Schemer)
|
data/test/schemer_test.rb
CHANGED
|
@@ -12,26 +12,30 @@ class FooTest < Test::Unit::TestCase
|
|
|
12
12
|
context "defining the schema" do
|
|
13
13
|
setup do
|
|
14
14
|
Foo.schema :foo, :bar
|
|
15
|
-
@foo = Foo.new
|
|
16
15
|
end
|
|
17
16
|
|
|
18
17
|
should "create the foos table" do
|
|
19
18
|
assert Foo.table_exists?
|
|
20
19
|
end
|
|
21
20
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
context "with an instance" do
|
|
22
|
+
setup do
|
|
23
|
+
@foo = Foo.new
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
should "create the foo column" do
|
|
27
|
+
assert @foo.respond_to?(:foo)
|
|
28
|
+
end
|
|
25
29
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
30
|
+
should "create the bar column" do
|
|
31
|
+
assert @foo.respond_to?(:bar)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
29
34
|
end
|
|
30
35
|
|
|
31
36
|
context "updating the schema" do
|
|
32
37
|
setup do
|
|
33
38
|
Foo.schema :foo, :bar
|
|
34
|
-
@foo = Foo.new
|
|
35
39
|
Foo.schema :foo
|
|
36
40
|
@foo = Foo.new
|
|
37
41
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: citrusbyte-schemer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ben Alavi
|
|
@@ -22,10 +22,10 @@ extensions: []
|
|
|
22
22
|
extra_rdoc_files: []
|
|
23
23
|
|
|
24
24
|
files:
|
|
25
|
-
- lib/schemer.rb
|
|
26
25
|
- README.markdown
|
|
27
26
|
- LICENSE
|
|
28
27
|
- Rakefile
|
|
28
|
+
- lib/schemer.rb
|
|
29
29
|
- rails/init.rb
|
|
30
30
|
- test/schemer_test.rb
|
|
31
31
|
has_rdoc: false
|