Sha256: 380891d55aba9c56b2bc1ec6536e5a946aa4bbdb555ddfba4684d19c7a142e57

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 KB

Contents

require 'active_support/core_ext/module/attribute_accessors'
require 'active_support/core_ext/object'
require 'active_support/core_ext/string'

module ShareChecker
  autoload :Provider, 'share_checker/provider'
  autoload :Config, 'share_checker/config'
  
  module Providers
    autoload :Facebook, 'share_checker/providers/facebook'
    autoload :Twitter, 'share_checker/providers/twitter'
    autoload :Vkontakte, 'share_checker/providers/vkontakte'
    autoload :Odnoklassniki, 'share_checker/providers/odnoklassniki'
    autoload :Tweetracker, 'share_checker/providers/tweetracker'
    
    def self.get(provider)
      "ShareChecker::Providers::#{provider.to_s.classify}".constantize
    end
    
    def self.avariable
      constants.select {|c| Class === const_get(c)}.sort.map(&:downcase).map(&:to_sym)
    end
  end
  
  mattr_accessor :config
  @@config = Config.new
  
  # Class methods
  
  def self.setup(&block)
    yield config
  end
  
  def self.check(*args)
    provider(*args).check
  end
  
  def self.provider(provider, url, options = {})
    options = (config.send(provider) || {}).merge(options)
    Providers.get(provider).new(url, provider, options)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
share_checker-0.1.6 lib/share_checker.rb
share_checker-0.1.5 lib/share_checker.rb
share_checker-0.1.4 lib/share_checker.rb
share_checker-0.1.3 lib/share_checker.rb
share_checker-0.1.2 lib/share_checker.rb