Sutto-reversible_data 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.
@@ -6,17 +6,19 @@ module ReversibleData
6
6
 
7
7
  attr_accessor :table_name, :model_name, :options
8
8
 
9
- def initialize(table_name, model_name = nil, opts = {}, &blk)
9
+ def initialize(table_name, opts = {}, &blk)
10
10
  @table_name = table_name.to_s.tableize.to_sym
11
- @model_name = (model_name || @table_name).to_s.classify
11
+ @model_name = (opts[:class_name] || @table_name).to_s.classify
12
12
  @migrator = blk
13
13
  @model_definition = nil
14
- @options = opts
14
+ default_options = {:skip_model => Object.const_defined?(@model_name), :skip_table => connection.table_exists?(@table_name)}
15
+ @options = opts.reverse_merge(default_options)
16
+ @blueprint = nil
15
17
  self.known_models[table_name.to_sym] = self
16
18
  end
17
19
 
18
20
  def drop_table
19
- return if @options[:skip_model]
21
+ return if @options[:skip_table]
20
22
  connection.drop_table(@table_name) if connection.table_exists?(@table_name)
21
23
  end
22
24
 
@@ -40,6 +42,7 @@ module ReversibleData
40
42
  return if Object.const_defined?(@model_name)
41
43
  @model = Class.new(ActiveRecord::Base)
42
44
  @model.class_eval(&@model_definition) unless @model_definition.nil?
45
+ @model.blueprint(&@blueprint) unless @blueprint.nil?
43
46
  Object.const_set(@model_name, @model)
44
47
  end
45
48
 
@@ -47,6 +50,10 @@ module ReversibleData
47
50
  @model_definition = blk unless blk.nil?
48
51
  end
49
52
 
53
+ def blueprint(&blk)
54
+ @blueprint = blk unless blk.nil?
55
+ end
56
+
50
57
  def clear_model_definition!
51
58
  @model_definition = nil
52
59
  end
@@ -9,8 +9,12 @@ module ReversibleData
9
9
  autoload :TableManager, 'reversible_data/table_manager'
10
10
  autoload :ShouldaMacros, 'reversible_data/shoulda_macros'
11
11
 
12
- def self.add(name, model_name = nil, opts = {}, &blk)
13
- Table.new(name, model_name, opts, &blk)
12
+ def self.add(name, opts = {}, &blk)
13
+ Table.new(name, opts, &blk)
14
+ end
15
+
16
+ def self.[](name)
17
+ Table.known_models[name]
14
18
  end
15
19
 
16
20
  def self.manager_for(*tables)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: Sutto-reversible_data
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
  - Darcy Laycock