Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add model and repository generators

  • Loading branch information...
commit 57c64b9d4140d4c7044794c842aae2a3647fd795 1 parent 0b177ad
@AquaGeek AquaGeek authored
View
19 lib/rails/generators/curator/model/model_generator.rb
@@ -0,0 +1,19 @@
+require 'rails/generators/named_base'
+
+module Curator
+ module Generators
+ class ModelGenerator < Rails::Generators::NamedBase
+ desc 'Creates a Curator model in app/models'
+ argument :attributes, :type => :array, :default => [], :banner => "field field"
+ check_class_collision
+
+ source_root File.expand_path("../templates", __FILE__)
+
+ def create_model_file
+ template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
+ end
+
+ hook_for :test_framework
+ end
+ end
+end
View
8 lib/rails/generators/curator/model/templates/model.rb
@@ -0,0 +1,8 @@
+<% module_namespacing do -%>
+class <%= class_name %>
+ include Curator::Model
+<% unless attributes.empty? -%>
+ attr_accessor <%= attributes.map {|a| ":#{a.name}" }.join(', ') %>
+<% end -%>
+end
+<% end -%>
View
19 lib/rails/generators/curator/repository/repository_generator.rb
@@ -0,0 +1,19 @@
+require 'rails/generators/named_base'
+
+module Curator
+ module Generators
+ class RepositoryGenerator < Rails::Generators::NamedBase
+ desc 'Creates a Curator repository in app/repositories'
+ argument :attributes, :type => :array, :default => [], :banner => "field field"
+ check_class_collision :suffix => 'Repository'
+
+ source_root File.expand_path("../templates", __FILE__)
+
+ def create_model_file
+ template 'repository.rb', File.join('app/repositories', class_path, "#{file_name}.rb")
+ end
+
+ hook_for :test_framework
+ end
+ end
+end
View
8 lib/rails/generators/curator/repository/templates/repository.rb
@@ -0,0 +1,8 @@
+<% module_namespacing do -%>
+class <%= class_name %>Repository
+ include Curator::Repository
+<% unless attributes.empty? -%>
+ indexed_fields <%= attributes.map {|a| ":#{a.name}" }.join(', ') %>
+<% end -%>
+end
+<% end -%>
Please sign in to comment.
Something went wrong with that request. Please try again.