lib/sinclair/options.rb in sinclair-1.6.2 vs lib/sinclair/options.rb in sinclair-1.6.3
- old
+ new
@@ -1,7 +1,9 @@
# frozen_string_literal: true
+require 'set'
+
class Sinclair
# @api public
# @author Darthjee
#
# Base options class
@@ -20,29 +22,57 @@
class Options
autoload :Builder, 'sinclair/options/builder'
class << self
# @api private
+ #
+ # returns invalid options
+ #
+ # @return [Array<Symbol>]
+ def invalid_options_in(names)
+ names.map(&:to_sym) - allowed_options.to_a
+ end
+
+ # @api private
+ #
+ # Allow new option
+ #
+ # This does not create the method
+ #
+ # @param name [String,Symbol] options to be allowed
+ #
+ # @return [Set<Symbol>]
+ def allow(name)
+ allowed_options << name.to_sym
+ end
+
+ private
+
+ # @api private
# @private
#
# Options allowed when initializing options
#
- # @return [Array<Symbol>]
+ # @return [Set<Symbol>]
def allowed_options
- @allowed_options ||= (superclass.try(:allowed_options).dup || [])
+ @allowed_options ||= build_allowed_options
end
# @api private
# @private
#
- # returns invalid options
+ # Build set of allowed options
#
- # @return [Array<Symbol>]
- def invalid_options_in(names)
- names.map(&:to_sym) - allowed_options
+ # When class is descendent of {Options}
+ # a duplication of it's parents allowed_options is
+ # returned
+ #
+ # @return (see allowed_options)
+ def build_allowed_options
+ superclass.send(:allowed_options).dup
+ rescue NoMethodError
+ Set.new
end
-
- private
# @api public
# @!visibility public
#
# Add available options