Skip to content

Commit

Permalink
Simplify gem configuration reusing Doorkeeper configuration option DSL
Browse files Browse the repository at this point in the history
  • Loading branch information
nbulaj committed Feb 1, 2023
1 parent c71a41c commit b3caf91
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 67 deletions.
9 changes: 5 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
## Unreleased

- [#PR ID] Add your changelog entry here.
- [#186] Simplify gem configuration reusing Doorkeeper configuration option DSL (thanks to @nbulaj).

## v1.8.4 (2023-02-01)

- [#185] Don't call active_record_options for Doorkeeper >= 5.6.3.
- [#183] stop render consent screen when user is not logged-in.
- [#185] Don't call active_record_options for Doorkeeper >= 5.6.3 (thanks to @zavan).
- [#183] Stop render consent screen when user is not logged-in (thanks to @nov).

## v1.8.3 (2022-12-02)

- [#180] Add PKCE support to OpenID discovery endpoint.
- [#180] Add PKCE support to OpenID discovery endpoint (thanks to @stanhu).

## Unreleased next

- [#177] Replace `json-jwt` with `ruby-jwt` to align with doorkeeper-jwt.
- [#177] Replace `json-jwt` with `ruby-jwt` to align with doorkeeper-jwt (thanks to @kristof-mattei).

## v1.8.2 (2022-07-13)

Expand Down
4 changes: 2 additions & 2 deletions doorkeeper-openid_connect.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ require 'doorkeeper/openid_connect/version'
Gem::Specification.new do |spec|
spec.name = 'doorkeeper-openid_connect'
spec.version = Doorkeeper::OpenidConnect::VERSION
spec.authors = ['Sam Dengler', 'Markus Koller']
spec.email = ['sam.dengler@playonsports.com', 'markus-koller@gmx.ch']
spec.authors = ['Sam Dengler', 'Markus Koller', 'Nikita Bulai']
spec.email = ['sam.dengler@playonsports.com', 'markus-koller@gmx.ch', 'bulajnikita@gmail.com']
spec.homepage = 'https://github.com/doorkeeper-gem/doorkeeper-openid_connect'
spec.summary = 'OpenID Connect extension for Doorkeeper.'
spec.description = 'OpenID Connect extension for Doorkeeper.'
Expand Down
63 changes: 2 additions & 61 deletions lib/doorkeeper/openid_connect/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,68 +35,9 @@ def jws_private_key(*args)
end
end

module Option
# Defines configuration option
#
# When you call option, it defines two methods. One method will take place
# in the +Config+ class and the other method will take place in the
# +Builder+ class.
#
# The +name+ parameter will set both builder method and config attribute.
# If the +:as+ option is defined, the builder method will be the specified
# option while the config attribute will be the +name+ parameter.
#
# If you want to introduce another level of config DSL you can
# define +builder_class+ parameter.
# Builder should take a block as the initializer parameter and respond to function +build+
# that returns the value of the config attribute.
#
# ==== Options
#
# * [:+as+] Set the builder method that goes inside +configure+ block
# * [+:default+] The default value in case no option was set
#
# ==== Examples
#
# option :name
# option :name, as: :set_name
# option :name, default: 'My Name'
# option :scopes builder_class: ScopesBuilder
#
def option(name, options = {})
attribute = options[:as] || name
attribute_builder = options[:builder_class]

Builder.instance_eval do
define_method name do |*args, &block|
# TODO: is builder_class option being used?
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 |*_|
if instance_variable_defined?(:"@#{attribute}")
instance_variable_get(:"@#{attribute}")
else
options[:default]
end
end

public attribute
end

def extended(base)
base.send(:private, :option)
end
end
mattr_reader(:builder_class) { Config::Builder }

extend Option
extend ::Doorkeeper::Config::Option

option :issuer
option :signing_key
Expand Down

0 comments on commit b3caf91

Please sign in to comment.