lib/swagger/serializer/store.rb in swagger-serializer-0.2.1 vs lib/swagger/serializer/store.rb in swagger-serializer-0.3.0

- old
+ new

@@ -5,22 +5,39 @@ def current @current ||= new end end - attr_accessor :inject_key + def initialize(options = nil) + @options = options || {} + @options[:inject_key] ||= "title" + @options[:injectors] ||= Injectors.new(cache: @options[:cache]) + end - def initialize(inject_key = "title") - @inject_key = inject_key + def [](name) + @options[name] end + def []=(name, value) + @options[name] = value + end + def serializer_options - { inject_key: inject_key, injectors: Injectors.new } + @options end class Injectors + def initialize(injectors: {}, cache: false) + @injectors = injectors + @cache = cache + end + def [](name) - "#{name}Serializer".safe_constantize + if @cache + @injectors[name] ||= "#{name}Serializer".safe_constantize + else + "#{name}Serializer".safe_constantize + end end end end end end