Sha256: d65f5a23ba6db30d1e95092e3f37389a56ab495357e6c62873109bbdcb8566fa

Contents?: true

Size: 1.31 KB

Versions: 7

Compression:

Stored size: 1.31 KB

Contents

begin
require 'rails/railtie'
rescue LoadError
else
require 'global_id'
require 'active_support'
require 'active_support/core_ext/string/inflections'

class GlobalID
  # = GlobalID Railtie
  # Set up the signed GlobalID verifier and include Active Record support.
  class Railtie < Rails::Railtie # :nodoc:
    config.global_id = ActiveSupport::OrderedOptions.new
    config.eager_load_namespaces << GlobalID

    initializer 'global_id' do |app|
      default_expires_in = 1.month
      default_app_name = app.railtie_name.remove('_application').dasherize

      GlobalID.app = app.config.global_id.app ||= default_app_name
      SignedGlobalID.expires_in = app.config.global_id.expires_in ||= default_expires_in

      config.after_initialize do
        GlobalID.app = app.config.global_id.app ||= default_app_name
        SignedGlobalID.expires_in = app.config.global_id.expires_in ||= default_expires_in

        app.config.global_id.verifier ||= begin
          GlobalID::Verifier.new(app.key_generator.generate_key('signed_global_ids'))
        rescue ArgumentError
          nil
        end
        SignedGlobalID.verifier = app.config.global_id.verifier
      end

      ActiveSupport.on_load(:active_record) do
        require 'global_id/identification'
        send :include, GlobalID::Identification
      end
    end
  end
end

end

Version data entries

7 entries across 7 versions & 5 rubygems

Version Path
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/globalid-0.4.2/lib/global_id/railtie.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/globalid-0.4.2/lib/global_id/railtie.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/globalid-0.4.2/lib/global_id/railtie.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/globalid-0.4.2/lib/global_id/railtie.rb
spiral_form-0.1.1 vendor/bundle/gems/globalid-0.4.2/lib/global_id/railtie.rb
spiral_form-0.1.0 vendor/bundle/gems/globalid-0.4.2/lib/global_id/railtie.rb
globalid-0.4.2 lib/global_id/railtie.rb