Sha256: 4b1137dcb4d68fc7e7d015b77213baacea5b302b7eb28ce28f1a2e9ef5fdfb39

Contents?: true

Size: 1.25 KB

Versions: 22

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

require "rails/generators"
require "rails/generators/migration"

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

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

    source_root File.expand_path("templates", __dir__)

    @@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")
      migration_template "migration.rb", "db/migrate/create_settings.rb", migration_version: migration_version
    end

    def rails_version_major
      Rails::VERSION::MAJOR
    end

    def rails_version_minor
      Rails::VERSION::MINOR
    end

    def migration_version
      "[#{rails_version_major}.#{rails_version_minor}]" if rails_version_major >= 5
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
rails-settings-cached-2.9.2 lib/generators/settings/install_generator.rb
rails-settings-cached-2.9.1 lib/generators/settings/install_generator.rb
rails-settings-cached-2.9.0 lib/generators/settings/install_generator.rb
rails-settings-cached-2.8.3 lib/generators/settings/install_generator.rb
rails-settings-cached-2.8.2 lib/generators/settings/install_generator.rb
rails-settings-cached-2.8.1 lib/generators/settings/install_generator.rb
rails-settings-cached-2.8.0 lib/generators/settings/install_generator.rb
rails-settings-cached-2.7.1 lib/generators/settings/install_generator.rb
rails-settings-cached-2.7.0 lib/generators/settings/install_generator.rb
rails-settings-cached-2.6.0 lib/generators/settings/install_generator.rb
rails-settings-cached-2.5.3 lib/generators/settings/install_generator.rb
rails-settings-cached-2.5.2 lib/generators/settings/install_generator.rb
rails-settings-cached-2.5.1 lib/generators/settings/install_generator.rb
rails-settings-cached-2.5.0 lib/generators/settings/install_generator.rb
rails-settings-cached-2.4.1 lib/generators/settings/install_generator.rb
rails-settings-cached-2.4.0 lib/generators/settings/install_generator.rb
rails-settings-cached-2.3.5 lib/generators/settings/install_generator.rb
rails-settings-cached-2.3.4 lib/generators/settings/install_generator.rb
rails-settings-cached-2.3.3 lib/generators/settings/install_generator.rb
rails-settings-cached-2.3.2 lib/generators/settings/install_generator.rb