lib/doorkeeper-jwt/config.rb in doorkeeper-jwt-0.2.1 vs lib/doorkeeper-jwt/config.rb in doorkeeper-jwt-0.3.0
- old
+ new
@@ -1,5 +1,7 @@
+# frozen_string_literal: true
+
module Doorkeeper
module JWT
class MissingConfiguration < StandardError
def initialize
super('Configuration for doorkeeper-jwt missing.')
@@ -9,11 +11,11 @@
def self.configure(&block)
@config = Config::Builder.new(&block).build
end
def self.configuration
- @config || (fail MissingConfiguration.new)
+ @config || (raise MissingConfiguration)
end
class Config
class Builder
def initialize(&block)
@@ -25,11 +27,11 @@
@config
end
def use_application_secret(use_application_secret)
@config.instance_variable_set(
- "@use_application_secret",
+ '@use_application_secret',
use_application_secret
)
end
def secret_key(secret_key)
@@ -40,11 +42,12 @@
@config.instance_variable_set('@secret_key_path', secret_key_path)
end
def encryption_method(encryption_method)
@config.instance_variable_set(
- '@encryption_method', encryption_method)
+ '@encryption_method', encryption_method
+ )
end
end
module Option
# Defines configuration option
@@ -79,21 +82,21 @@
attribute_builder = options[:builder_class]
Builder.instance_eval do
define_method name do |*args, &block|
# TODO: is builder_class option being used?
- value = unless attribute_builder
- block ? block : args.first
- else
+ value = if attribute_builder
attribute_builder.new(&block).build
+ else
+ block || args.first
end
@config.instance_variable_set(:"@#{attribute}", value)
end
end
- define_method attribute do |*args|
+ define_method attribute do |*|
if instance_variable_defined?(:"@#{attribute}")
instance_variable_get(:"@#{attribute}")
else
options[:default]
end
@@ -108,10 +111,10 @@
end
extend Option
option :token_payload,
- default: proc{ { token: SecureRandom.method(:hex) } }
+ default: proc { { token: SecureRandom.method(:hex) } }
option :token_headers, default: proc { {} }
option :use_application_secret, default: false
option :secret_key, default: nil
option :secret_key_path, default: nil
option :encryption_method, default: nil