Sha256: 466dd91b5299b285c55da573022f5938ade64cf9b6e7e182b22a78a72d41a30e

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

require 'simple_marshal.rb'

class AppConfiguration
  
  class ConfigElement
    def initialize(conf,element,name)
      @element=element
      @name=name
      @conf=conf
    end
    def [](name)
      checkHash
      ConfigElement.new(@conf,@element[@name],name)
    end
    def []=(name,value)
      checkHash
      @element[@name][name]=value
      @conf.save
    end
    
    def content
      @element[@name]
    end
    
    private
    def checkHash
      if @element.key?(@name)
        assert{@element[@name].is_a?(Hash)}
      else
        @element[@name]={}
      end
      
    end
  end
  
  attr_reader :elements
  
  def self.config(app)
    store=app.getApp(:localFileStore)
    store.config(app)
  end
  
  def initialize(store,appKey)
    
    @elements={}
    @store=store
    @appClass,@appName=appKey
    
    data=@store.api(@appClass,@appName)["config"]
    if data && data.length>0
      @elements=Simple::Marshal::load(data)
    end
  end
  
  def reset
    @elements={}
    save
  end
  
  def flush
    save
  end
  
  def []=(name,value)
    @elements[name]=value
    save
  end
    
  def [](name)
    ConfigElement.new(self,@elements,name)
  end
  
  
  def save
    data=Simple::Marshal::dump(@elements)
    @store.api(@appClass,@appName)["config"]=data
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
appswarm-0.0.1 apps/local_file_store/app_configuration.rb