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.1.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.registryHash<Symbol, Feed> (readonly)

Returns the registry of the defined feeds.

Returns:

  • (Hash<Symbol, Feed>)

    the registry of the defined feeds



23
24
25
# File 'lib/simplefeed.rb', line 23

def registry
  @registry
end

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.



66
67
68
# File 'lib/simplefeed.rb', line 66

def self.class_attributes(klass)
  klass.instance_methods.grep(/[^=!]=$/).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



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

def define(name, **options, &block)
  name = name.to_sym unless name.is_a?(Symbol)
  feed = registry[name] || SimpleFeed::Feed.new(name)
  feed.configure(options) do
    block&.call(feed)
  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



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

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

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

Forward all other method calls to the Provider



59
60
61
# File 'lib/simplefeed.rb', line 59

def method_missing(name, *args, **opts, &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)


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

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

.symbolize!(hash) ⇒ Object

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



71
72
73
# File 'lib/simplefeed.rb', line 71

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