lib/rhosync.rb in rhosync-2.0.0.beta2 vs lib/rhosync.rb in rhosync-2.0.0.beta3

- old
+ new

@@ -1,6 +1,7 @@ require 'redis' +require 'redis/distributed' require 'json' require 'base64' require 'zip/zip' require 'yaml' require 'rhosync/license' @@ -27,16 +28,20 @@ module Rhosync APP_NAME = 'application' unless defined? APP_NAME class InvalidArgumentError < RuntimeError; end class RhosyncServerError < RuntimeError; end + + # Used by application authenticate to indicate login failure + class LoginException < RuntimeError; end + extend self class << self attr_accessor :base_directory, :app_directory, :data_directory, :vendor_directory, :blackberry_bulk_sync, :redis, :environment, - :log_disabled, :license + :log_disabled, :license, :bulk_sync_poll_interval end ### Begin Rhosync setup methods # Server hook to initialize Rhosync def bootstrap(basedir) @@ -47,10 +52,11 @@ Rhosync.base_directory = basedir Rhosync.app_directory = get_setting(config,environment,:app_directory) Rhosync.data_directory = get_setting(config,environment,:data_directory) Rhosync.vendor_directory = get_setting(config,environment,:vendor_directory) Rhosync.blackberry_bulk_sync = get_setting(config,environment,:blackberry_bulk_sync,false) + Rhosync.bulk_sync_poll_interval = get_setting(config,environment,:bulk_sync_poll_interval,3600) Rhosync.redis = get_setting(config,environment,:redis,false) Rhosync.log_disabled = get_setting(config,environment,:log_disabled,false) Rhosync.environment = environment yield self if block_given? Store.create(Rhosync.redis) @@ -58,10 +64,11 @@ Rhosync.base_directory ||= File.join(File.dirname(__FILE__),'..') Rhosync.app_directory ||= Rhosync.base_directory Rhosync.data_directory ||= File.join(Rhosync.base_directory,'data') Rhosync.vendor_directory ||= File.join(Rhosync.base_directory,'vendor') Rhosync.blackberry_bulk_sync ||= false + Rhosync.bulk_sync_poll_interval ||= 3600 Rhosync.log_disabled ||= false Rhosync.license = License.new check_and_add(File.join(Rhosync.app_directory,'sources')) start_app(config) @@ -111,11 +118,11 @@ end def get_config(basedir) # Load settings settings_file = File.join(basedir,'settings','settings.yml') if basedir - config = YAML.load_file(settings_file) if settings_file and File.exist?(settings_file) + YAML.load_file(settings_file) if settings_file and File.exist?(settings_file) end ### End Rhosync setup methods def check_default_secret!(secret) @@ -127,17 +134,19 @@ end end # Serializes oav to set element def setelement(obj,attrib,value) - "#{obj}:#{attrib}:#{Base64.encode64(value.to_s)}" + #"#{obj}:#{attrib}:#{Base64.encode64(value.to_s)}" + "#{obj}:#{attrib}:#{value.to_s}" end # De-serializes oav from set element def getelement(element) - res = element.split(':') - [res[0], res[1], Base64.decode64(res[2].to_s)] + res = element.split(':',3) + #[res[0], res[1], Base64.decode64(res[2].to_s)] + [res[0], res[1], res[2]] end # Get random UUID string def get_random_uuid UUIDTools::UUID.random_create.to_s.gsub(/\-/,'') @@ -222,10 +231,10 @@ now = Time.now.strftime('%I:%M:%S %p %Y-%m-%d') puts "[#{now}] #{args.join}" unless Rhosync.log_disabled end # Base rhosync application class - class Base + class Base # Add everything in vendor to load path # TODO: Integrate with 3rd party dependency management def self.initializer(path=nil) Dir["vendor/*"].each do |dir| $:.unshift File.join(dir,'lib') \ No newline at end of file