citrusbyte-schemer 0.0.3 → 0.0.4

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.
Files changed (3) hide show
  1. data/README.markdown +14 -2
  2. data/lib/schemer.rb +2 -19
  3. metadata +1 -1
data/README.markdown CHANGED
@@ -8,8 +8,8 @@ Description
8
8
 
9
9
  Loosely define your schema in your ActiveRecord model and have it created and
10
10
  updated for you without worrying about migrations. Useful for when you want to
11
- play around with real data handling during extremely rapid prototyping but you
12
- really don't care about keeping the data or how it's defined.
11
+ play around with real data handling during prototyping but you really don't
12
+ care about keeping the data or how it's defined.
13
13
 
14
14
  **WARNING:** This will create and delete data definitions on the fly with no
15
15
  warning! Only use this with volatile data! Never attach it to an existing model
@@ -42,6 +42,18 @@ Don't want a column anymore?
42
42
 
43
43
  Removes the `username` column the next time `User.new` is called.
44
44
 
45
+ Want a relationship?
46
+
47
+ class Widget < ActiveRecord::Base
48
+ schema :user_id
49
+
50
+ belongs_to :user
51
+ end
52
+
53
+ Works just fine!
54
+
55
+ **NOTE:** All columns are created as string columns.
56
+
45
57
  Installation
46
58
  ------------
47
59
 
data/lib/schemer.rb CHANGED
@@ -15,26 +15,14 @@ module Schemer
15
15
 
16
16
  module InstanceMethods
17
17
  def initialize(*args)
18
- setup_schema
18
+ update_schema
19
19
  super
20
20
  end
21
21
 
22
22
  private
23
23
 
24
- def setup_schema
25
- begin
26
- ActiveRecord::Migration.table_structure(self.class.table_name)
27
- update_schema
28
- rescue ActiveRecord::StatementInvalid => e
29
- if e.message.match(/Could not find table/)
30
- create_schema
31
- else
32
- raise e
33
- end
34
- end
35
- end
36
-
37
24
  def update_schema
25
+ ActiveRecord::Migration.create_table(self.class.table_name) do |t|;end; unless self.class.table_exists?
38
26
  self.class.schema_columns.each do |column|
39
27
  ActiveRecord::Migration.add_column(self.class.table_name, column, :string) unless respond_to?(column.to_sym)
40
28
  (self.class.column_names - self.class.protected_columns).each do |column|
@@ -42,10 +30,5 @@ module Schemer
42
30
  end
43
31
  end
44
32
  end
45
-
46
- def create_schema
47
- ActiveRecord::Migration.create_table(self.class.table_name) do |t|;end;
48
- update_schema
49
- end
50
33
  end
51
34
  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.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Alavi