terrarum 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown ADDED
@@ -0,0 +1,37 @@
1
+ # Terrarum
2
+
3
+ Need a full list of all of the countries of the world? Complete with ISO codes, numeric codes and short codes?
4
+ What about all of the languages of the world? If thats the case then this gem solves your problems.
5
+
6
+ Terrarum is a Rails 3 generator, providing you files (model + migration) for countries and languages of the world.
7
+ The list is put together based on Wikipedia.
8
+
9
+ ## Usage
10
+
11
+ # add this to your gemfile
12
+ gem "terrarum"
13
+ # and run
14
+ bundle install
15
+
16
+ # or just run
17
+ sudo gem install terrarum
18
+
19
+ To generate both Country and Language data:
20
+ rails g terrarum:all
21
+
22
+ To generate only Country data:
23
+ rails g terrarum:countries
24
+
25
+ To generate noly Language data
26
+ rails g terrarum:languages
27
+
28
+ You can also override the default model names for both generators:
29
+ rails g terrarum:countries pony
30
+
31
+ ## Authors
32
+
33
+ **Tanel Suurhans** (<http://twitter.com/tanelsuurhans>)
34
+ **Tarmo Lehtpuu** (<http://twitter.com/tarmolehtpuu>)
35
+
36
+ ## License
37
+ Copyright 2010 by PerfectLine LLC (<http://www.perfectline.co.uk>) and is released under the MIT license.
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ puts IO.read(File.join(File.dirname(__FILE__), 'README.markdown'))
@@ -0,0 +1,20 @@
1
+ module Terrarum
2
+ module Generators
3
+ class AllGenerator < Rails::Generators::Base
4
+
5
+ def self.desc
6
+ "Description:\n Creates migrations and models for all bundled data (counries and languages)"
7
+ end
8
+
9
+ def self.banner
10
+ "rails generate terrarum:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
11
+ end
12
+
13
+ def create_files
14
+ generate "terrarum:countries", "Country"
15
+ generate "terrarum:languages", "Language"
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,45 @@
1
+ require 'rails/generators/active_record/model/model_generator'
2
+
3
+ module Terrarum
4
+ module Generators
5
+ class CountriesGenerator < ActiveRecord::Generators::Base
6
+ argument :name, :type => :string, :default => "Country"
7
+
8
+ check_class_collision
9
+
10
+ def self.desc
11
+ "Description:\n Creates countries data and files"
12
+ end
13
+
14
+ def self.banner
15
+ "rails generate terrarum:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
16
+ end
17
+
18
+ def self.source_root
19
+ @source_root ||= File.expand_path("../templates", __FILE__)
20
+ end
21
+
22
+ class_option :migration, :type => :boolean, :default => true
23
+ class_option :timestamps, :type => :boolean, :default => true
24
+ class_option :parent, :type => :string, :desc => "The parent class for the generated model"
25
+
26
+ def create_model_file
27
+ template "model.rb", File.join("app/models", class_path, "#{file_name}.rb")
28
+ end
29
+
30
+ def create_migration_file
31
+ return unless options[:migration] && options[:parent].nil?
32
+ migration_template "migration.rb", "db/migrate/create_#{table_name}.rb"
33
+ end
34
+
35
+ hook_for :test_framework, :as => :model, :in => :rails
36
+
37
+ protected
38
+
39
+ def parent_class_name
40
+ options[:parent] || "ActiveRecord::Base"
41
+ end
42
+
43
+ end
44
+ end
45
+ end