dynamic-fields 0.0.4 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -36,6 +36,6 @@ module DynamicFields
36
36
  end
37
37
  args.join(', ').gsub('\\', '')
38
38
  end
39
-
39
+
40
40
  end
41
41
  end
@@ -50,7 +50,7 @@ module DynamicFields
50
50
 
51
51
  # Any fields which have not been add to the table
52
52
  def new_fields
53
- fields.reject {|f| real_field_names.include?(f.name.to_s) }
53
+ (self.fields ||= []).reject {|f| real_field_names.include?(f.name.to_s) }
54
54
  end
55
55
 
56
56
  # Any fields in the table, but not in the model
@@ -101,7 +101,7 @@ module DynamicFields
101
101
 
102
102
  # Any indicies which have not been add to the table
103
103
  def new_indices
104
- indices.reject { |idx| real_index_ids.include?(idx.id) }
104
+ (self.indices ||= []).reject { |idx| real_index_ids.include?(idx.id) }
105
105
  end
106
106
 
107
107
  # Any indices in the table, but not in the model
@@ -14,7 +14,7 @@ module DynamicFields
14
14
  end
15
15
 
16
16
  def to_s
17
- name
17
+ name.to_s
18
18
  end
19
19
 
20
20
  def unique?
@@ -26,11 +26,10 @@ module DynamicFields
26
26
  case action = action.to_sym
27
27
  when :add
28
28
  args << (fields.is_a?(Array) ? fields : fields.to_sym).inspect
29
- args << ":name => #{name.inspect}" if fields.is_a?(Array)
29
+ args << ":name => #{to_s.inspect}"
30
30
  args << ":unique => true" if unique?
31
31
  when :remove
32
- args << fields.to_sym.inspect unless fields.is_a?(Array)
33
- args << ":name => #{name.to_sym.inspect}" if fields.is_a?(Array)
32
+ args << ":name => #{to_s.inspect}"
34
33
  end
35
34
  args.join(', ').gsub('\\', '')
36
35
  end
@@ -1,15 +1,25 @@
1
1
  class <%= migration_class_name %> < ActiveRecord::Migration
2
- def self.up<% attributes.each do |action, attrs| %><% attrs.each do |attribute| %>
3
- <%= action %>_column :<%= table_name %>, <%= attribute.migration_string_for :update, action %><% end -%>
4
- <% end %><% indices.each do |action, idxs| %><% idxs.each do |index| %>
5
- <%= action %>_index :<%= table_name %>, <%= index.migration_string_for :update, action %><% end -%>
6
- <% end %>
2
+ def self.up
3
+ <%- attributes[:add].each do |attribute| -%>
4
+ add_column :<%= table_name %>, <%= attribute.migration_string_for :update, :add %>
5
+ <%- end -%><%- indices[:add].each do |index| -%>
6
+ add_index :<%= table_name %>, <%= index.migration_string_for :update, :add %>
7
+ <%- end -%><%- indices[:remove].each do |index| -%>
8
+ remove_index :<%= table_name %>, <%= index.migration_string_for :update, :remove %>
9
+ <%- end -%><%- attributes[:remove].each do |attribute| -%>
10
+ remove_column :<%= table_name %>, <%= attribute.migration_string_for :update, :remove %>
11
+ <%- end -%>
7
12
  end
8
13
 
9
- def self.down<% indices.each do |action, idxs| %><% idxs.each do |index| %>
10
- <%= action == :add ? 'remove' : 'add' %>_index :<%= table_name %>, <%= index.migration_string_for(:update, action == :add ? :remove : :add ) %><% end -%>
11
- <% end %><% attributes.each do |action, attrs| %><% attrs.reverse.each do |attribute| %>
12
- <%= action == :add ? 'remove' : 'add' %>_column :<%= table_name %>, <%= attribute.migration_string_for(:update, action == :add ? :remove : :add ) %><% end -%>
13
- <% end %>
14
+ def self.down
15
+ <%- indices[:add].reverse.each do |index| -%>
16
+ remove_index :<%= table_name %>, <%= index.migration_string_for :update, :remove %>
17
+ <%- end -%><%- attributes[:add].reverse.each do |attribute| -%>
18
+ remove_column :<%= table_name %>, <%= attribute.migration_string_for :update, :remove %>
19
+ <%- end -%><%- attributes[:remove].reverse.each do |attribute| -%>
20
+ add_column :<%= table_name %>, <%= attribute.migration_string_for :update, :add %>
21
+ <%- end -%><%- indices[:remove].reverse.each do |index| -%>
22
+ add_index :<%= table_name %>, <%= index.migration_string_for :update, :add %>
23
+ <%- end -%>
14
24
  end
15
25
  end
@@ -1,3 +1,4 @@
1
+ require 'dynamic_fields'
1
2
  require 'dynamic_fields/migration_generator'
2
3
 
3
4
  namespace :dynamic_fields do
@@ -42,7 +43,7 @@ def generate_migration_for(klass)
42
43
  return unless klass.name.present? # no annoymous classes
43
44
  if klass.requires_migration?
44
45
  puts "Generating a migration for #{klass.name}"
45
- DynamicFields::MigrationGenerator.start klass.name
46
+ DynamicFields::MigrationGenerator.start [klass.name]
46
47
  else
47
48
  puts "#{klass.name} is up to date!"
48
49
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynamic-fields
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
4
+ hash: 11
5
+ prerelease:
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 4
9
- version: 0.0.4
9
+ - 10
10
+ version: 0.0.10
10
11
  platform: ruby
11
12
  authors:
12
13
  - Alex Neill
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2010-07-02 00:00:00 +01:00
18
+ date: 2011-06-21 00:00:00 +01:00
18
19
  default_executable:
19
20
  dependencies: []
20
21
 
@@ -43,28 +44,32 @@ homepage: http://github.com/ajn/dynamic-fields
43
44
  licenses: []
44
45
 
45
46
  post_install_message:
46
- rdoc_options:
47
- - --charset=UTF-8
47
+ rdoc_options: []
48
+
48
49
  require_paths:
49
50
  - lib
50
51
  required_ruby_version: !ruby/object:Gem::Requirement
52
+ none: false
51
53
  requirements:
52
54
  - - ">="
53
55
  - !ruby/object:Gem::Version
56
+ hash: 3
54
57
  segments:
55
58
  - 0
56
59
  version: "0"
57
60
  required_rubygems_version: !ruby/object:Gem::Requirement
61
+ none: false
58
62
  requirements:
59
63
  - - ">="
60
64
  - !ruby/object:Gem::Version
65
+ hash: 3
61
66
  segments:
62
67
  - 0
63
68
  version: "0"
64
69
  requirements: []
65
70
 
66
71
  rubyforge_project:
67
- rubygems_version: 1.3.6
72
+ rubygems_version: 1.5.2
68
73
  signing_key:
69
74
  specification_version: 3
70
75
  summary: Auto-migrate ActiveRecord models