migrant 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/Gemfile +9 -0
  2. data/Gemfile.lock +91 -0
  3. data/Rakefile +21 -22
  4. data/VERSION +1 -1
  5. data/lib/migrant/schema.rb +46 -16
  6. data/migrant.gemspec +22 -11
  7. metadata +70 -30
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source :gemcutter
2
+
3
+ gem "jeweler"
4
+ gem "thoughtbot-shoulda"
5
+ gem "ansi"
6
+ gem "turn"
7
+ gem "sqlite3-ruby"
8
+ gem "simplecov", "0.3.5"
9
+ gem "rails", "3.0.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,91 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.0)
6
+ actionpack (= 3.0.0)
7
+ mail (~> 2.2.5)
8
+ actionpack (3.0.0)
9
+ activemodel (= 3.0.0)
10
+ activesupport (= 3.0.0)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.4.1)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.12)
16
+ rack-test (~> 0.5.4)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.0)
19
+ activesupport (= 3.0.0)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.4.1)
22
+ activerecord (3.0.0)
23
+ activemodel (= 3.0.0)
24
+ activesupport (= 3.0.0)
25
+ arel (~> 1.0.0)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.0)
28
+ activemodel (= 3.0.0)
29
+ activesupport (= 3.0.0)
30
+ activesupport (3.0.0)
31
+ ansi (1.2.2)
32
+ arel (1.0.1)
33
+ activesupport (~> 3.0.0)
34
+ builder (2.1.2)
35
+ erubis (2.6.6)
36
+ abstract (>= 1.0.0)
37
+ git (1.2.5)
38
+ i18n (0.4.2)
39
+ jeweler (1.5.1)
40
+ bundler (~> 1.0.0)
41
+ git (>= 1.2.5)
42
+ rake
43
+ mail (2.2.12)
44
+ activesupport (>= 2.3.6)
45
+ i18n (>= 0.4.0)
46
+ mime-types (~> 1.16)
47
+ treetop (~> 1.4.8)
48
+ mime-types (1.16)
49
+ polyglot (0.3.1)
50
+ rack (1.2.1)
51
+ rack-mount (0.6.13)
52
+ rack (>= 1.0.0)
53
+ rack-test (0.5.6)
54
+ rack (>= 1.0)
55
+ rails (3.0.0)
56
+ actionmailer (= 3.0.0)
57
+ actionpack (= 3.0.0)
58
+ activerecord (= 3.0.0)
59
+ activeresource (= 3.0.0)
60
+ activesupport (= 3.0.0)
61
+ bundler (~> 1.0.0)
62
+ railties (= 3.0.0)
63
+ railties (3.0.0)
64
+ actionpack (= 3.0.0)
65
+ activesupport (= 3.0.0)
66
+ rake (>= 0.8.4)
67
+ thor (~> 0.14.0)
68
+ rake (0.8.7)
69
+ simplecov (0.3.5)
70
+ simplecov-html (>= 0.3.7)
71
+ simplecov-html (0.3.9)
72
+ sqlite3-ruby (1.3.2)
73
+ thor (0.14.6)
74
+ thoughtbot-shoulda (2.11.1)
75
+ treetop (1.4.9)
76
+ polyglot (>= 0.3.1)
77
+ turn (0.8.1)
78
+ ansi (>= 1.2.2)
79
+ tzinfo (0.3.23)
80
+
81
+ PLATFORMS
82
+ ruby
83
+
84
+ DEPENDENCIES
85
+ ansi
86
+ jeweler
87
+ rails (= 3.0.0)
88
+ simplecov (= 0.3.5)
89
+ sqlite3-ruby
90
+ thoughtbot-shoulda
91
+ turn
data/Rakefile CHANGED
@@ -1,27 +1,27 @@
1
1
  require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
2
10
  require 'rake'
3
11
 
4
- begin
5
- require 'jeweler'
6
- Jeweler::Tasks.new do |gem|
7
- gem.name = "migrant"
8
- gem.summary = %Q{All the fun of ActiveRecord, without writing your migrations, and a dash of mocking.}
9
- gem.description = %Q{Migrant gives you a super-clean DSL to describe your ActiveRecord models (somewhat similar to DataMapper) and generates all your migrations for you so you can spend more time coding the stuff that counts!}
10
- gem.email = "101pascal@gmail.com"
11
- gem.homepage = "http://github.com/pascalh1011/migrant"
12
- gem.authors = ["Pascal Houliston"]
13
- gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
14
- gem.add_development_dependency "ansi", "= 1.2.2"
15
- gem.add_development_dependency "turn", "= 0.8.1"
16
- gem.add_development_dependency "sqlite3-ruby", ">= 0"
17
- gem.add_development_dependency "simplecov", "= 0.3.5"
18
- gem.add_dependency "rails", ">= 3.0.0"
19
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
20
- end
21
- Jeweler::GemcutterTasks.new
22
- rescue LoadError
23
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ gem.name = "migrant"
15
+ gem.summary = %Q{All the fun of ActiveRecord, without writing your migrations, and a dash of mocking.}
16
+ gem.description = %Q{Migrant gives you a super-clean DSL to describe your ActiveRecord models (somewhat similar to DataMapper) and generates all your migrations for you so you can spend more time coding the stuff that counts!}
17
+ gem.email = "101pascal@gmail.com"
18
+ gem.homepage = "http://github.com/pascalh1011/migrant"
19
+ gem.authors = ["Pascal Houliston"]
20
+ gem.add_development_dependency "bundler"
21
+ gem.add_runtime_dependency "rails", ">= 3.0.0"
22
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
24
23
  end
24
+ Jeweler::RubygemsDotOrgTasks.new
25
25
 
26
26
  require 'rake/testtask'
27
27
  Rake::TestTask.new(:test) do |test|
@@ -30,8 +30,6 @@ Rake::TestTask.new(:test) do |test|
30
30
  test.verbose = true
31
31
  end
32
32
 
33
- task :test => :check_dependencies
34
-
35
33
  task :default => :test
36
34
 
37
35
  require 'rake/rdoctask'
@@ -43,3 +41,4 @@ Rake::RDocTask.new do |rdoc|
43
41
  rdoc.rdoc_files.include('README*')
44
42
  rdoc.rdoc_files.include('lib/**/*.rb')
45
43
  end
44
+
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.4
1
+ 0.1.5
@@ -9,19 +9,25 @@ module Migrant
9
9
  # into a schema on that model class by calling method_missing(my_field)
10
10
  # and deciding what the best schema type is for the user's requiredments
11
11
  class Schema
12
+ # Global scope resolution operators will make the Migrant DSL fucking useless
13
+ # So, I am doing this rather than inhering from SimpleObject, just live with it.
14
+ # instance_methods.each { |m| raise 'fuckoff' if m == 'system' ; undef_method unless ['__send__', 'object_id'].include?(m) }
15
+
12
16
  attr_accessor :indexes, :columns, :methods_to_alias
13
17
 
14
- def initialize
18
+ def initialize
19
+ @proxy = SchemaProxy.new(self)
15
20
  @columns = Hash.new
16
21
  @indexes = Array.new
17
22
  @methods_to_alias = Array.new
18
- end
23
+ end
19
24
 
20
- def define_structure(&block)
25
+ def define_structure(&block)
21
26
  # Runs method_missing on columns given in the model "structure" DSL
22
- self.instance_eval(&block) if block_given?
27
+ @proxy.translate_fancy_dsl(&block) if block_given?
28
+ # self.instance_eval(&block) if block_given?
23
29
  end
24
-
30
+
25
31
  def add_associations(associations)
26
32
  associations.each do |association|
27
33
  field = association.options[:foreign_key] || (association.name.to_s+'_id').to_sym
@@ -36,22 +42,21 @@ module Migrant
36
42
  end
37
43
  end
38
44
  end
39
-
45
+
40
46
  def requires_migration?
41
47
  !(@columns.blank? && @indexes.blank?)
42
48
  end
43
-
49
+
44
50
  def column_migrations
45
51
  @columns.collect {|field, data| [field, data.column] } # All that needs to be migrated
46
52
  end
47
-
53
+
48
54
  # This is where we decide what the best schema is based on the structure requirements
49
- # The output of this is essentially a formatted schema hash that is processed
55
+ # The output of this is essentially a formatted schema hash that is processed
50
56
  # on each model by Migrant::MigrationGenerator
51
- def method_missing(*args, &block)
52
- field = args.slice!(0)
53
- data_type = (args.first.nil?)? DataType::String : args.slice!(0)
54
- options = args.extract_options!
57
+
58
+ def add_field(field, data_type = nil, options = {})
59
+ data_type = DataType::String if data_type.nil?
55
60
 
56
61
  # Add index if explicitly asked
57
62
  @indexes << field if options.delete(:index) || data_type.class.to_s == 'Hash' && data_type.delete(:index)
@@ -74,18 +79,43 @@ module Migrant
74
79
  puts [":#{field}", "#{@columns[field].class}", "#{options.inspect}"].collect { |s| s.ljust(25) }.join if ENV['DEBUG']
75
80
  end
76
81
  end
77
-
82
+
78
83
  class InheritedSchema < Schema
79
84
  attr_accessor :parent_schema
80
-
85
+
81
86
  def initialize(parent_schema)
82
87
  @parent_schema = parent_schema
83
88
  @columns = Array.new
84
89
  @indexes = Array.new
85
90
  end
86
-
91
+
87
92
  def requires_migration?
88
93
  false # All added to base table
89
94
  end
90
95
  end
96
+
97
+ # Why does this class exist? Excellent question.
98
+ # Basically, Kernel gives a whole bunch of global methods, like system, puts, etc. This is bad because
99
+ # our DSL relies on being able to translate any arbitrary method into a method_missing call.
100
+ # So, we call method missing in this happy bubble where these magic methods don't exist.
101
+ # The reason we don't inherit Schema itself in this way, is that we'd lose direct access to all other classes
102
+ # derived from Object. Normally this would just mean scope resolution operators all over the class, but the real
103
+ # killer is that the DSL would need to reference classes in that manner as well, which would reduce sexy factor by at least 100.
104
+ class SchemaProxy < BasicObject
105
+ def initialize(binding)
106
+ @binding = binding
107
+ end
108
+
109
+ def translate_fancy_dsl(&block)
110
+ self.instance_eval(&block)
111
+ end
112
+
113
+ def method_missing(*args, &block)
114
+ field = args.slice!(0)
115
+ data_type = args.slice!(0) unless args.first.nil?
116
+
117
+ @binding.add_field(field, data_type, args.extract_options!)
118
+ end
119
+ end
91
120
  end
121
+
data/migrant.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{migrant}
8
- s.version = "0.1.4"
8
+ s.version = "0.1.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Pascal Houliston"]
12
- s.date = %q{2010-11-25}
12
+ s.date = %q{2010-12-14}
13
13
  s.description = %q{Migrant gives you a super-clean DSL to describe your ActiveRecord models (somewhat similar to DataMapper) and generates all your migrations for you so you can spend more time coding the stuff that counts!}
14
14
  s.email = %q{101pascal@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -17,6 +17,8 @@ Gem::Specification.new do |s|
17
17
  "README.rdoc"
18
18
  ]
19
19
  s.files = [
20
+ "Gemfile",
21
+ "Gemfile.lock",
20
22
  "LICENSE",
21
23
  "README.rdoc",
22
24
  "Rakefile",
@@ -136,26 +138,35 @@ Gem::Specification.new do |s|
136
138
  s.specification_version = 3
137
139
 
138
140
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
139
- s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
140
- s.add_development_dependency(%q<ansi>, ["= 1.2.2"])
141
- s.add_development_dependency(%q<turn>, ["= 0.8.1"])
142
- s.add_development_dependency(%q<sqlite3-ruby>, [">= 0"])
143
- s.add_development_dependency(%q<simplecov>, ["= 0.3.5"])
141
+ s.add_runtime_dependency(%q<jeweler>, [">= 0"])
142
+ s.add_runtime_dependency(%q<thoughtbot-shoulda>, [">= 0"])
143
+ s.add_runtime_dependency(%q<ansi>, [">= 0"])
144
+ s.add_runtime_dependency(%q<turn>, [">= 0"])
145
+ s.add_runtime_dependency(%q<sqlite3-ruby>, [">= 0"])
146
+ s.add_runtime_dependency(%q<simplecov>, ["= 0.3.5"])
147
+ s.add_runtime_dependency(%q<rails>, ["= 3.0.0"])
148
+ s.add_development_dependency(%q<bundler>, [">= 0"])
144
149
  s.add_runtime_dependency(%q<rails>, [">= 3.0.0"])
145
150
  else
151
+ s.add_dependency(%q<jeweler>, [">= 0"])
146
152
  s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
147
- s.add_dependency(%q<ansi>, ["= 1.2.2"])
148
- s.add_dependency(%q<turn>, ["= 0.8.1"])
153
+ s.add_dependency(%q<ansi>, [">= 0"])
154
+ s.add_dependency(%q<turn>, [">= 0"])
149
155
  s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
150
156
  s.add_dependency(%q<simplecov>, ["= 0.3.5"])
157
+ s.add_dependency(%q<rails>, ["= 3.0.0"])
158
+ s.add_dependency(%q<bundler>, [">= 0"])
151
159
  s.add_dependency(%q<rails>, [">= 3.0.0"])
152
160
  end
153
161
  else
162
+ s.add_dependency(%q<jeweler>, [">= 0"])
154
163
  s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
155
- s.add_dependency(%q<ansi>, ["= 1.2.2"])
156
- s.add_dependency(%q<turn>, ["= 0.8.1"])
164
+ s.add_dependency(%q<ansi>, [">= 0"])
165
+ s.add_dependency(%q<turn>, [">= 0"])
157
166
  s.add_dependency(%q<sqlite3-ruby>, [">= 0"])
158
167
  s.add_dependency(%q<simplecov>, ["= 0.3.5"])
168
+ s.add_dependency(%q<rails>, ["= 3.0.0"])
169
+ s.add_dependency(%q<bundler>, [">= 0"])
159
170
  s.add_dependency(%q<rails>, [">= 3.0.0"])
160
171
  end
161
172
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 4
9
- version: 0.1.4
8
+ - 5
9
+ version: 0.1.5
10
10
  platform: ruby
11
11
  authors:
12
12
  - Pascal Houliston
@@ -14,12 +14,11 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-11-25 00:00:00 +02:00
17
+ date: 2010-12-14 00:00:00 +00:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- name: thoughtbot-shoulda
22
- prerelease: false
21
+ name: jeweler
23
22
  requirement: &id001 !ruby/object:Gem::Requirement
24
23
  none: false
25
24
  requirements:
@@ -28,41 +27,37 @@ dependencies:
28
27
  segments:
29
28
  - 0
30
29
  version: "0"
31
- type: :development
30
+ type: :runtime
31
+ prerelease: false
32
32
  version_requirements: *id001
33
33
  - !ruby/object:Gem::Dependency
34
- name: ansi
35
- prerelease: false
34
+ name: thoughtbot-shoulda
36
35
  requirement: &id002 !ruby/object:Gem::Requirement
37
36
  none: false
38
37
  requirements:
39
- - - "="
38
+ - - ">="
40
39
  - !ruby/object:Gem::Version
41
40
  segments:
42
- - 1
43
- - 2
44
- - 2
45
- version: 1.2.2
46
- type: :development
41
+ - 0
42
+ version: "0"
43
+ type: :runtime
44
+ prerelease: false
47
45
  version_requirements: *id002
48
46
  - !ruby/object:Gem::Dependency
49
- name: turn
50
- prerelease: false
47
+ name: ansi
51
48
  requirement: &id003 !ruby/object:Gem::Requirement
52
49
  none: false
53
50
  requirements:
54
- - - "="
51
+ - - ">="
55
52
  - !ruby/object:Gem::Version
56
53
  segments:
57
54
  - 0
58
- - 8
59
- - 1
60
- version: 0.8.1
61
- type: :development
55
+ version: "0"
56
+ type: :runtime
57
+ prerelease: false
62
58
  version_requirements: *id003
63
59
  - !ruby/object:Gem::Dependency
64
- name: sqlite3-ruby
65
- prerelease: false
60
+ name: turn
66
61
  requirement: &id004 !ruby/object:Gem::Requirement
67
62
  none: false
68
63
  requirements:
@@ -71,12 +66,25 @@ dependencies:
71
66
  segments:
72
67
  - 0
73
68
  version: "0"
74
- type: :development
69
+ type: :runtime
70
+ prerelease: false
75
71
  version_requirements: *id004
76
72
  - !ruby/object:Gem::Dependency
77
- name: simplecov
78
- prerelease: false
73
+ name: sqlite3-ruby
79
74
  requirement: &id005 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ type: :runtime
83
+ prerelease: false
84
+ version_requirements: *id005
85
+ - !ruby/object:Gem::Dependency
86
+ name: simplecov
87
+ requirement: &id006 !ruby/object:Gem::Requirement
80
88
  none: false
81
89
  requirements:
82
90
  - - "="
@@ -86,12 +94,40 @@ dependencies:
86
94
  - 3
87
95
  - 5
88
96
  version: 0.3.5
89
- type: :development
90
- version_requirements: *id005
97
+ type: :runtime
98
+ prerelease: false
99
+ version_requirements: *id006
91
100
  - !ruby/object:Gem::Dependency
92
101
  name: rails
102
+ requirement: &id007 !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - "="
106
+ - !ruby/object:Gem::Version
107
+ segments:
108
+ - 3
109
+ - 0
110
+ - 0
111
+ version: 3.0.0
112
+ type: :runtime
93
113
  prerelease: false
94
- requirement: &id006 !ruby/object:Gem::Requirement
114
+ version_requirements: *id007
115
+ - !ruby/object:Gem::Dependency
116
+ name: bundler
117
+ requirement: &id008 !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ segments:
123
+ - 0
124
+ version: "0"
125
+ type: :development
126
+ prerelease: false
127
+ version_requirements: *id008
128
+ - !ruby/object:Gem::Dependency
129
+ name: rails
130
+ requirement: &id009 !ruby/object:Gem::Requirement
95
131
  none: false
96
132
  requirements:
97
133
  - - ">="
@@ -102,7 +138,8 @@ dependencies:
102
138
  - 0
103
139
  version: 3.0.0
104
140
  type: :runtime
105
- version_requirements: *id006
141
+ prerelease: false
142
+ version_requirements: *id009
106
143
  description: Migrant gives you a super-clean DSL to describe your ActiveRecord models (somewhat similar to DataMapper) and generates all your migrations for you so you can spend more time coding the stuff that counts!
107
144
  email: 101pascal@gmail.com
108
145
  executables: []
@@ -113,6 +150,8 @@ extra_rdoc_files:
113
150
  - LICENSE
114
151
  - README.rdoc
115
152
  files:
153
+ - Gemfile
154
+ - Gemfile.lock
116
155
  - LICENSE
117
156
  - README.rdoc
118
157
  - Rakefile
@@ -199,6 +238,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
199
238
  requirements:
200
239
  - - ">="
201
240
  - !ruby/object:Gem::Version
241
+ hash: -454091891
202
242
  segments:
203
243
  - 0
204
244
  version: "0"