Module: SimpleFeed

Defined in:
lib/simplefeed.rb,
lib/simplefeed/dsl.rb,
lib/simplefeed/feed.rb,
lib/simplefeed/event.rb,
lib/simplefeed/version.rb,
lib/simplefeed/key/type.rb,
lib/simplefeed/response.rb,
lib/simplefeed/providers.rb,
lib/simplefeed/key/template.rb,
lib/simplefeed/activity/base.rb,
lib/simplefeed/dsl/formatter.rb,
lib/simplefeed/providers/key.rb,
lib/simplefeed/dsl/activities.rb,
lib/simplefeed/providers/hash.rb,
lib/simplefeed/providers/proxy.rb,
lib/simplefeed/providers/redis.rb,
lib/simplefeed/activity/multi_user.rb,
lib/simplefeed/activity/single_user.rb,
lib/simplefeed/providers/redis/stats.rb,
lib/simplefeed/providers/redis/driver.rb,
lib/simplefeed/providers/base/provider.rb,
lib/simplefeed/providers/hash/provider.rb,
lib/simplefeed/providers/hash/paginator.rb,
lib/simplefeed/providers/redis/provider.rb

Overview

Main namespace module for the SimpleFeed gem. It provides several shortcuts and entry points into the library, such as ability to define and fetch new feeds via define, and so on.

Defined Under Namespace

Modules: Activity, DSL, Key, Providers Classes: Event, Feed, Response

Constant Summary collapse

VERSION =
'2.0.2'

Class Method Summary collapse

Class Method Details

.class_attributes(klass) ⇒ Object

Returns list of class attributes based on the setter methods. Not fool-proof, but works in this context.



64
65
66
# File 'lib/simplefeed.rb', line 64

def self.class_attributes(klass)
  klass.instance_methods.grep(%r{[^=!]=$}).map { |m| m.to_s.gsub(/=/, '').to_sym }
end

.define(name, **options, &block) ⇒ Feed

Returns the feed with the given name, and defined via options and a block.

Parameters:

  • name (Symbol)

    feed name

  • options (Hash)

    any key-value pairs to set on the feed

Returns:

  • (Feed)

    the feed with the given name, and defined via options and a block



28
29
30
31
32
33
34
35
36
# File 'lib/simplefeed.rb', line 28

def define(name, **options, &block)
  name = name.to_sym unless name.is_a?(Symbol)
  feed = registry[name] ? registry[name] : SimpleFeed::Feed.new(name)
  feed.configure(options) do
    block.call(feed) if block
  end
  registry[name] = feed
  feed
end

.get(name) ⇒ Feed

Returns the pre-defined feed with the given name.

Returns:

  • (Feed)

    the pre-defined feed with the given name



39
40
41
# File 'lib/simplefeed.rb', line 39

def get(name)
  registry[name.to_sym]
end

.method_missing(name, *args, &block) ⇒ Object

Forward all other method calls to the Provider



57
58
59
# File 'lib/simplefeed.rb', line 57

def method_missing(name, *args, &block)
  registry[name] || super
end

.provider(provider_name, *args, **opts, &block) ⇒ Provider

A factory method that constructs an instance of a provider based on the provider name and arguments.

Parameters:

  • provider_name (Symbol)

    short name of the provider, eg, :redis, :hash, etc.

Returns:

  • (Provider)

Raises:

  • (ArgumentError)


50
51
52
53
54
# File 'lib/simplefeed.rb', line 50

def provider(provider_name, *args, **opts, &block)
  provider_class = SimpleFeed::Providers.registry[provider_name]
  raise ArgumentError, "No provider named #{provider_name} was found, #{SimpleFeed::Providers.registry.inspect}" unless provider_class
  provider_class.new(*args, **opts, &block)
end

.registryHash<Symbol, Feed>

Returns the registry of the defined feeds.

Returns:

  • (Hash<Symbol, Feed>)

    the registry of the defined feeds



20
21
22
# File 'lib/simplefeed.rb', line 20

def registry
  @registry
end

.symbolize!(hash) ⇒ Object

Shortcut method to symbolize hash keys, using Hashie::Extensions



69
70
71
# File 'lib/simplefeed.rb', line 69

def self.symbolize!(hash)
  Hashie::Extensions::SymbolizeKeys.symbolize_keys!(hash)
end