Sha256: 76e3fc37783c4ca5f5d1684790058247f9b2664205a8fd9edd149928c4f007af

Contents?: true

Size: 1.73 KB

Versions: 13

Compression:

Stored size: 1.73 KB

Contents

# Copyright (C) 2010  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 version 2.1 as published by the Free Software Foundation.
#
# 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

require 'rails/generators/active_groonga'
require 'rails/generators/active_groonga/migration/column'

module ActiveGroonga
  module Generators
    class MigrationGenerator < Base #:nodoc:
      argument(:columns, :type => :array, :default => [],
               :banner => "name:type[:option:option] name:type[:option:option]")

      def initialize(args, *options)
        super
        parse_columns!
      end

      def create_migration_file
        set_local_assigns!
        migration_template "migration.rb", "db/groonga/migrate/#{file_name}.rb"
      end

      protected
      attr_reader :migration_action
      def set_local_assigns!
        if file_name =~ /^(add|remove)_.*_(?:to|from)_(.*)/
          @migration_action = $1
          @table_name       = $2.pluralize
        end
      end

      private
      def parse_columns! #:nodoc:
        self.columns = (columns || []).collect do |key_value|
          name, type, *options = key_value.split(':')
          Column.new(name, type, options)
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
activegroonga-4.2.1 lib/rails/generators/active_groonga/migration/migration_generator.rb
activegroonga-4.2.0 lib/rails/generators/active_groonga/migration/migration_generator.rb
activegroonga-4.0.0 lib/rails/generators/active_groonga/migration/migration_generator.rb
activegroonga-2.1.4 lib/rails/generators/active_groonga/migration/migration_generator.rb
activegroonga-2.1.3 lib/rails/generators/active_groonga/migration/migration_generator.rb
activegroonga-2.1.2 lib/rails/generators/active_groonga/migration/migration_generator.rb
activegroonga-2.1.1 lib/rails/generators/active_groonga/migration/migration_generator.rb
activegroonga-1.0.7 lib/rails/generators/active_groonga/migration/migration_generator.rb
activegroonga-1.0.6 lib/rails/generators/active_groonga/migration/migration_generator.rb
activegroonga-1.0.5 lib/rails/generators/active_groonga/migration/migration_generator.rb
activegroonga-1.0.4 lib/rails/generators/active_groonga/migration/migration_generator.rb
activegroonga-1.0.3 lib/rails/generators/active_groonga/migration/migration_generator.rb
activegroonga-1.0.1 lib/rails/generators/active_groonga/migration/migration_generator.rb