terrarum 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ class <%= class_name %> < <%= parent_class_name.classify %>
2
+
3
+ scope :code, lambda { |code| where(:code => code.to_s) }
4
+
5
+ validates :code, :presence => true, :length => { :maximum => 5 }, :uniqueness => true
6
+ validates :name, :presence => true, :lenght => { :maximum => 100 }
7
+
8
+ end
@@ -0,0 +1,45 @@
1
+ require 'rails/generators/active_record/model/model_generator'
2
+
3
+ module Terrarum
4
+ module Generators
5
+ class LanguagesGenerator < ActiveRecord::Generators::Base
6
+ argument :name, :type => :string, :default => "Language"
7
+
8
+ check_class_collision
9
+
10
+ def self.desc
11
+ "Description:\n Creates languages 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