Sha256: 3a6e5f6cff2a44e2c7372baf4bfe9b358b952b2738b1237247f39b2809249302

Contents?: true

Size: 595 Bytes

Versions: 3

Compression:

Stored size: 595 Bytes

Contents

module Redistat
  class Label
    include Database
    
    attr_reader :raw
    
    def initialize(str, options = {})
      @options = options
      @raw = str.to_s
    end
    
    def name
      @options[:hashed_label] ? hash : @raw
    end
    
    def hash
      @hash ||= Digest::SHA1.hexdigest(@raw)
    end
    
    def save
      @saved = (db.set("#{KEY_LEBELS}#{hash}", @raw) == "OK") if @options[:hashed_label]
      self
    end
    
    def saved?
      @saved ||= false
    end
    
    def self.create(name, options = {})
      self.new(name, options).save
    end
    
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
redistat-0.0.4 lib/redistat/label.rb
redistat-0.0.3 lib/redistat/label.rb
redistat-0.0.2 lib/redistat/label.rb