Sha256: 0120fb196f9543750fcb6ea8f195f648851b5e8cfdafbc2e00f8b4f78102dcbb

Contents?: true

Size: 1.01 KB

Versions: 10

Compression:

Stored size: 1.01 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.delete(@@config.root_cache_key)
      cached_nodes
    end

    def state_digest
      Digest::MD5.hexdigest("#{Config.maximum(:updated_at)}#{Entry.maximum(:updated_at)}#{Config.count}#{Entry.count}")
    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

10 entries across 10 versions & 1 rubygems

Version Path
flexite-0.0.17 lib/flexite.rb
flexite-0.0.16 lib/flexite.rb
flexite-0.0.15 lib/flexite.rb
flexite-0.0.14 lib/flexite.rb
flexite-0.0.13 lib/flexite.rb
flexite-0.0.12 lib/flexite.rb
flexite-0.0.11 lib/flexite.rb
flexite-0.0.10 lib/flexite.rb
flexite-0.0.9 lib/flexite.rb
flexite-0.0.8 lib/flexite.rb