Sha256: 880933fe0689ea18fe030b0eb5dd6b411ba603ca86208e0639aaba39f34c98de

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

require 'json'
require 'action_controller'
require 'active_record'
require 'md5'

unless defined?(SEAMLESS_VERSION)

	SEAMLESS_VERSION = '1.0.RC4.127'
	SEAMLESS_SERVICES = Array.new
 
    def model_name(name)
      name.to_s.gsub(/[::]{2}/,'.').split('.').collect {|token| token.underscore }.join('.')
    end
  
  	def silence_warnings
    	old_verbose, $VERBOSE = $VERBOSE, nil
    	yield
  	ensure
    	$VERBOSE = old_verbose
  	end	

    #
    # OK, I realize this might be a little bad, but we include a few dependencies 
    # which print out stupid warnings on boot - we're going to suppress that
    #
    silence_warnings do 
	    #
  		# require dependencies
  		#
		  Dir[File.dirname(__FILE__)+'/seamless/*.rb'].sort.each do |file|
			  require file[0..-4]
		  end
	  end
	  
    #
    # trick to allow changing ActiveRecord logging stream
    #
    def log_to(stream)
      ActiveRecord::Base.logger = Logger.new(stream)
      ActiveRecord::Base.clear_active_connections!
    end

    #
    # shortcut to turn on logging to stdout
    #
    def log_to_stdout
       log_to STDOUT
    end	
    
  	#
  	# load any services
  	#
  	Dir[RAILS_ROOT + '/app/services/*_service.rb'].each do |file|
  		require file[0..-4]
  		name = Inflector.camelize(File.basename(file).chomp('_service.rb')) 
  		klass = eval(name + 'Service')
  		mh = klass.instance
  	end
  	
    #
    # register a message broker listener for admin seamless models
    #
    sam_proc = Proc.new do |req,type,obj|
   	    resp = {'success'=>true, 'models'=> SEAMLESS_SERVICES}
    	Seamless::Dispatcher.instance.outgoing(req,'seamless.admin.models.response',resp)
    end
    Seamless::MessageBroker.register_listener('seamless.admin.models.request',sam_proc)

  	puts "=> Seam(less) on Rails #{SEAMLESS_VERSION}"
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
seamless-1.0.0 lib/seamless.rb