Sha256: 83b3d3f052c4c6359cdcffe53216183077303a6f08136a46ebc97c1c9da300e3
Contents?: true
Size: 1.78 KB
Versions: 2
Compression:
Stored size: 1.78 KB
Contents
require 'date' require 'locabulary/item' require 'locabulary/utility' module Locabulary # :nodoc: module Services # @api private # # Responsible for extracting a non-hierarchical sorted array of active Locabulary::Item for the given predicate_name # # @see Locabulary::Item class ActiveItemsForService def self.cache @cache ||= {} end private_class_method :cache # @api private # @since 0.5.0 def self.reset_cache! @cache = {} end # @api private # @since 0.5.0 # # @param options [Hash] # @option options [String] :predicate_name # @option options [Date] :as_of (Date.today) # # @note A concession about the as_of; This is not a live Utility. The data has a # low churn rate. And while the date is important, I'm not as concerned # about the local controlled vocabulary exposing a date that has expired. # When we next deploy the server changes, the deactivated will go away. def self.call(options = {}) predicate_name = options.fetch(:predicate_name) cache[predicate_name] ||= new(options).call end private_class_method :new def initialize(options = {}) @predicate_name = options.fetch(:predicate_name) @as_of = options.fetch(:as_of) { Date.today } @builder = Item.builder_for(predicate_name: predicate_name) end def call collector = [] Utility.with_active_extraction_for(predicate_name, as_of) do |data| collector << builder.call(data.merge('predicate_name' => predicate_name)) end collector.sort end private attr_reader :predicate_name, :as_of, :builder end private_constant :ActiveItemsForService end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
locabulary-0.8.1 | lib/locabulary/services/active_items_for_service.rb |
locabulary-0.7.1 | lib/locabulary/services/active_items_for_service.rb |