Skip to content

Commit

Permalink
adding generators for the models and migration
Browse files Browse the repository at this point in the history
  • Loading branch information
joho committed Oct 6, 2009
1 parent 0336c42 commit 7f489a9
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -5,4 +5,4 @@ I need a decent plugin that can do the following things
* generate a standard db migration
* pull down the required geonames files from the web
* load those geonames files in the db (assuming a schema from the migration)
* give me my models for free
* generate me my models for free (but leave them in models so i can hack them up later)
@@ -0,0 +1,7 @@
class GeonamesMigrationGenerator < Rails::Generator::Base
def manifest
record do |m|
m.migration_template 'geonames_tables.rb',"db/migrate", :migration_file_name => "create_geonames_tables"
end
end
end
14 changes: 14 additions & 0 deletions lib/generators/geonames_migration/templates/geonames_tables.rb
@@ -0,0 +1,14 @@
class CreateGeonamesTables < ActiveRecord::Migration
def self.up
# blah

# create countries
# create regions
# create cities
end

def self.down
# drop all the tables
# %w(countries regions cities) { |t| drop_table t }
end
end
7 changes: 7 additions & 0 deletions lib/generators/geonames_models/geonames_models_generator.rb
@@ -0,0 +1,7 @@
class GeonamesMigrationGenerator < Rails::Generator::Base
def manifest
record do |m|
# Do something
end
end
end
4 changes: 4 additions & 0 deletions lib/generators/geonames_models/templates/models/city.rb
@@ -0,0 +1,4 @@
class City < ActiveRecord::Base
belongs_to :region
has_one :country, :through => :region
end
4 changes: 4 additions & 0 deletions lib/generators/geonames_models/templates/models/country.rb
@@ -0,0 +1,4 @@
class Country < ActiveRecord::Base
has_many :regions
has_many :cities, :through => :regions
end
4 changes: 4 additions & 0 deletions lib/generators/geonames_models/templates/models/region.rb
@@ -0,0 +1,4 @@
class Region
belongs_to :country
has_many :cities
end

0 comments on commit 7f489a9

Please sign in to comment.