Sha256: 8d1665b378dee67105a4f9341c1e8920a03512d1540fc57334174d574d93df8b

Contents?: true

Size: 1.86 KB

Versions: 16

Compression:

Stored size: 1.86 KB

Contents

require 'writefully/storage'
require 'erb'

module Writefully
  SCOPES  = %w(repo public_repo user write:repo_hook)

  class << self
    QUEUE = { 
      top:    -> (c, job) { c.lpush "jobs", job },
      bottom: -> (c, job) { c.rpush "jobs", job }
    }

    def options=(config)
      @_options = config
    end

    def options
      @_options ||= config_from(config_yml)
    end

    def redis
      r = Redis.new(host: 'localhost', port: 6379)
      @_redis ||= ConnectionPool.new(size: 5, timeout: 5) do 
        Redis::Namespace.new(:"#{env}:writefully", redis: r)
      end
    end

    def add_job worker, message, position = nil
      position_selector = position || :bottom
      Writefully.redis.with { |c| QUEUE[position_selector].call(c, convert_job(worker, message)) }
    end

    def convert_job worker, message
       Marshal.dump({worker: worker, message: message})
    end

    def env
      ENV["RACK_ENV"] || ENV["RAILS_ENV"] || 'development'
    end

    def github_app
      @_github_app ||= Github.new(client_id:     options[:github_client], 
                                  client_secret: options[:github_secret])
    end

    def logger
      @logger ||= Logger.new(log_location)
    end

    def log_location
      env == 'development' ? STDOUT : Writefully.options[:logfile]
    end

    def db_config
      YAML::load(ERB.new(IO.read(File.join(options[:app_directory], 'config', 'database.yml'))).result)[env]
    end

    def config_from(path = nil)
      YAML::load(ERB.new(IO.read(path)).result)[env]
    rescue Errno::ENOENT
      $stdout.puts "config/writefully.yml does not exist"
    end


    def config_yml
      Rails.root.join('config', 'writefully.yml') if defined?(Rails)
    end

  end
end

require 'writefully/taxon'
require 'writefully/asset'
require 'writefully/source'
require 'writefully/postable'
require 'writefully/indices'
require 'writefully/content'

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
writefully-0.8.2 lib/writefully/loader.rb
writefully-0.8.1 lib/writefully/loader.rb
writefully-0.8.0 lib/writefully/loader.rb
writefully-0.7.1 lib/writefully/loader.rb
writefully-0.6.12 lib/writefully/loader.rb
writefully-0.6.11 lib/writefully/loader.rb
writefully-0.6.10 lib/writefully/loader.rb
writefully-0.6.9 lib/writefully/loader.rb
writefully-0.6.7 lib/writefully/loader.rb
writefully-0.6.6 lib/writefully/loader.rb
writefully-0.6.5 lib/writefully/loader.rb
writefully-0.6.4 lib/writefully/loader.rb
writefully-0.6.3 lib/writefully/loader.rb
writefully-0.6.2 lib/writefully/loader.rb
writefully-0.5.1 lib/writefully/loader.rb
writefully-0.5.0 lib/writefully/loader.rb