Sha256: 5e4f14102043d3edae7966aff41e365089ce003d39dfa21eb4a5ee7321feb681

Contents?: true

Size: 1.06 KB

Versions: 7

Compression:

Stored size: 1.06 KB

Contents

require 'flexite/engine'
require 'hashie'
require 'hashdiff'
require 'net/http'

module Flexite
  extend ActiveSupport::Autoload

  autoload :Configuration
  autoload :Flexy
  autoload :NodesHash
  autoload :CachedNode
  autoload :Config
  autoload :Entry

  mattr_reader :config
  @@config = Configuration.new

  Object.const_set(:Flexy, Flexy)

  class << self
    def configure
      yield(@@config)
    end

    def cache
      @@config.cache
    end

    def reload_root_cache
      cache.clear
      cached_nodes
    end

    def state_digest
      Digest::MD5.hexdigest("#{Config.maximum(:updated_at)}#{Entry.maximum(:updated_at)}#{Config.count}#{Entry.count}")
    end

    def match_key(pattern)
      @@config.cache_matcher.call(pattern)
    end

    def cached_nodes
      return unless Config.table_exists?

      cache.fetch(@@config.root_cache_key) do
        Config.where(config_id: nil).each_with_object(NodesHash.new) do |root, memo|
          memo[root.name] = cache.fetch(root) do
            CachedNode.new(root)
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
flexite-0.0.25 lib/flexite.rb
flexite-0.0.24 lib/flexite.rb
flexite-0.0.23 lib/flexite.rb
flexite-0.0.22 lib/flexite.rb
flexite-0.0.21 lib/flexite.rb
flexite-0.0.20 lib/flexite.rb
flexite-0.0.19 lib/flexite.rb