Sha256: a2d0f41494ec5b656c1c50f0259e79fa548b5b395a68b8df5cd959d4d63c0a0a

Contents?: true

Size: 987 Bytes

Versions: 6

Compression:

Stored size: 987 Bytes

Contents

require 'rails/generators'
require 'rails/generators/migration'

module Settings
  class InstallGenerator < Rails::Generators::NamedBase
    desc "Generate RailsSettings files."
    include Rails::Generators::Migration

    argument :name, type: :string, default: 'setting'

    source_root File.expand_path('../templates', __FILE__)

    @@migrations = false

    def self.next_migration_number(dirname) #:nodoc:
      if ActiveRecord::Base.timestamped_migrations
        if @@migrations
          (current_migration_number(dirname) + 1)
        else
          @@migrations = true
          Time.now.utc.strftime('%Y%m%d%H%M%S')
        end
      else
        format '%.3d', current_migration_number(dirname) + 1
      end
    end

    def install_setting
      template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
      template 'app.yml', File.join('config', "app.yml")
      migration_template 'migration.rb', 'db/migrate/create_settings.rb'
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rails-settings-cached-0.6.5 lib/generators/settings/install_generator.rb
rails-settings-cached-0.6.4 lib/generators/settings/install_generator.rb
rails-settings-cached-0.6.3 lib/generators/settings/install_generator.rb
rails-settings-cached-0.6.2 lib/generators/settings/install_generator.rb
rails-settings-cached-0.6.1 lib/generators/settings/install_generator.rb
rails-settings-cached-0.6.0 lib/generators/settings/install_generator.rb