Kouhei Sutou
null+****@clear*****
Thu Jan 26 15:23:44 JST 2017
Kouhei Sutou 2017-01-26 15:23:44 +0900 (Thu, 26 Jan 2017) New Revision: 2972ae39b54b835ee8b4ae7aeef5d444b93a9fb4 https://github.com/ranguba/groonga-client-model/commit/2972ae39b54b835ee8b4ae7aeef5d444b93a9fb4 Message: Add groonga_client_model:model generator Added files: lib/rails/generators/groonga_client_model/model/model_generator.rb lib/rails/generators/groonga_client_model/model/templates/application_groonga_record.rb lib/rails/generators/groonga_client_model/model/templates/model.rb test/apps/rails5/app/models/application_groonga_record.rb test/apps/rails5/test/models/post_test.rb Modified files: test/apps/rails5/app/models/post.rb Added: lib/rails/generators/groonga_client_model/model/model_generator.rb (+68 -0) 100644 =================================================================== --- /dev/null +++ lib/rails/generators/groonga_client_model/model/model_generator.rb 2017-01-26 15:23:44 +0900 (8fecf35) @@ -0,0 +1,68 @@ +# Copyright (C) 2017 Kouhei Sutou <kou �� clear-code.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +require "rails/generators/named_base" +require "rails/generators/active_model" +require "groonga-client-model" + +module GroongaClientModel + module Generators + class ModelGenerator < Rails::Generators::NamedBase + source_root File.join(__dir__, "templates") + + argument :attributes, + type: :array, + default: [], + banner: "field[:type][:index] field[:type][:index]" + + check_class_collision + + class_option :parent, + type: :string, + desc: "The parent class for the generated model" + + hook_for :test_framework + + def create_model_file + generate_application_groonga_record + template("model.rb", + File.join("app/models", class_path, "#{file_name}.rb")) + end + + private + def generate_application_groonga_record + if behavior == :invoke and !application_groonga_record_exist? + template("application_groonga_record.rb", + application_groonga_record_file_name) + end + end + + def parent_class_name + options[:parent] || "ApplicationGroongaRecord" + end + + def application_groonga_record_exist? + in_root do + File.exist?(application_groonga_record_file_name) + end + end + + def application_groonga_record_file_name + "app/models/application_groonga_record.rb" + end + end + end +end Added: lib/rails/generators/groonga_client_model/model/templates/application_groonga_record.rb (+2 -0) 100644 =================================================================== --- /dev/null +++ lib/rails/generators/groonga_client_model/model/templates/application_groonga_record.rb 2017-01-26 15:23:44 +0900 (f860df4) @@ -0,0 +1,2 @@ +class ApplicationGroongaRecord < GroongaClientModel::Record +end Added: lib/rails/generators/groonga_client_model/model/templates/model.rb (+2 -0) 100644 =================================================================== --- /dev/null +++ lib/rails/generators/groonga_client_model/model/templates/model.rb 2017-01-26 15:23:44 +0900 (9fe368b) @@ -0,0 +1,2 @@ +class <%= class_name %> < <%= parent_class_name.classify %> +end Added: test/apps/rails5/app/models/application_groonga_record.rb (+2 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails5/app/models/application_groonga_record.rb 2017-01-26 15:23:44 +0900 (f860df4) @@ -0,0 +1,2 @@ +class ApplicationGroongaRecord < GroongaClientModel::Record +end Modified: test/apps/rails5/app/models/post.rb (+1 -1) =================================================================== --- test/apps/rails5/app/models/post.rb 2017-01-26 14:23:10 +0900 (90666d2) +++ test/apps/rails5/app/models/post.rb 2017-01-26 15:23:44 +0900 (3c918b4) @@ -1,2 +1,2 @@ -class Post < GroongaClientModel::Record +class Post < ApplicationGroongaRecord end Added: test/apps/rails5/test/models/post_test.rb (+7 -0) 100644 =================================================================== --- /dev/null +++ test/apps/rails5/test/models/post_test.rb 2017-01-26 15:23:44 +0900 (6d9d463) @@ -0,0 +1,7 @@ +require 'test_helper' + +class PostTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end -------------- next part -------------- HTML����������������������������... Télécharger