Sha256: 32d42e905893d99e302cd38bc1f41f7a54920222adf02f4b65a9774decadc738

Contents?: true

Size: 791 Bytes

Versions: 3

Compression:

Stored size: 791 Bytes

Contents

module Scales
  module Helper
    module PartialResolver
      
      PARTIAL_REGEX = /(Scales\.partial ["|'](.*)["|'])/
      
      class << self
        
        def resolve(redis, key)
          value = redis.get(key)
          
          i = 0
          
          while includes_partial?(value) do
            value = resolve_partial(redis, value)
          end
          value
        end
        
        def includes_partial?(value)
          value =~ PARTIAL_REGEX
        end
        
        def resolve_partial(redis, value)
          matched = value.match(PARTIAL_REGEX)
          tag, key = matched[1], matched[2]
          partial = redis.get(Storage::PARTIAL_PREFIX + key)
          
          value.gsub(tag, partial)
        end
        
      end
      
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
scales-core-0.0.4 lib/scales-core/helper/partial_resolver.rb
scales-core-0.0.1.beta.2 lib/scales-core/helper/partial_resolver.rb
scales-core-0.0.1.beta.1 lib/scales-core/helper/partial_resolver.rb