class ESA::Configuration
Attributes
base_classes[RW]
context_checkers[RW]
context_freshness_threshold[RW]
context_providers[RW]
context_tree[RW]
context_walk_ignore[RW]
extension_namespace[RW]
processor[RW]
Public Class Methods
new()
click to toggle source
# File lib/esa/configuration.rb, line 21 def initialize @base_classes = [ESA::Ruleset, ESA::Event, ESA::Flag, ESA::Transaction].freeze @extension_namespace = "Accounting" @processor = ESA::BlockingProcessor @context_checkers = Set.new @context_checkers << ESA::BalanceChecker @context_checkers << ESA::SubcontextChecker @context_freshness_threshold = 15.minutes @context_providers = { 'account' => ESA::ContextProviders::AccountContextProvider, 'accountable' => ESA::ContextProviders::AccountableContextProvider, 'accountable_type' => ESA::ContextProviders::AccountableTypeContextProvider, 'month' => [ESA::ContextProviders::DateContextProvider, {all: true, period: :month}], 'date' => [ESA::ContextProviders::DateContextProvider, {all: true, period: :date}], } @context_tree = { 'account' => { 'month' => { 'date' => {}, }, }, 'period' => { 'account' => { 'date' => {}, }, }, 'year' => { 'account' => { 'date' => {}, }, }, 'month' => { 'account' => { 'date' => {}, }, }, 'date' => { 'account' => {}, }, } @context_walk_ignore = ['filter'] end
Public Instance Methods
context_providers_for_path(path=[])
click to toggle source
# File lib/esa/configuration.rb, line 98 def context_providers_for_path(path=[]) clean_path = path - context_walk_ignore @context_providers.slice(*self.walk_context_tree(clean_path).keys) end
extension_class(extension_type, extension_name)
click to toggle source
# File lib/esa/configuration.rb, line 80 def extension_class(extension_type, extension_name) [ @extension_namespace.presence, "#{extension_type}s", "#{extension_name}#{extension_type}" ].compact.join('::') end
register(accountable, short_name=nil)
click to toggle source
# File lib/esa/configuration.rb, line 71 def register(accountable, short_name=nil) accountable_name = accountable.to_s extension_name = short_name || accountable_name.demodulize @base_classes.each do |klass| klass.register_extension(accountable_name, self.extension_class(klass.name.demodulize, extension_name)) end end
walk_context_tree(path=[], tree=@context_tree)
click to toggle source
# File lib/esa/configuration.rb, line 88 def walk_context_tree(path=[], tree=@context_tree) if path.respond_to? :count and path.count == 0 tree || {} elsif path.respond_to? :first and tree.is_a? Hash and path.first.in? tree self.walk_context_tree(path.drop(1), tree[path.first]) else {} end end