Class: SimpleFeed::Feed

Inherits:
Object
  • Object
show all
Defined in:
lib/simplefeed/feed.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Feed

Returns a new instance of Feed.



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/simplefeed/feed.rb', line 22

def initialize(name)
  @name = name
  @name = name.underscore.to_sym unless name.is_a?(Symbol)
  # set the defaults if not passed in
  @meta = {}
  @namespace = nil
  @per_page ||= 50
  @max_size ||= 1000
  @batch_size ||= 10
  @meta_key_transformer = nil
  @data_key_transformer = nil
  @proxy = nil
end

Instance Attribute Details

#batch_sizeObject

Returns the value of attribute batch_size.



9
10
11
# File 'lib/simplefeed/feed.rb', line 9

def batch_size
  @batch_size
end

#data_key_transformerObject

Returns the value of attribute data_key_transformer.



9
10
11
# File 'lib/simplefeed/feed.rb', line 9

def data_key_transformer
  @data_key_transformer
end

#max_sizeObject

Returns the value of attribute max_size.



9
10
11
# File 'lib/simplefeed/feed.rb', line 9

def max_size
  @max_size
end

#meta_key_transformerObject

Returns the value of attribute meta_key_transformer.



9
10
11
# File 'lib/simplefeed/feed.rb', line 9

def meta_key_transformer
  @meta_key_transformer
end

#nameObject (readonly)

Returns the value of attribute name.



16
17
18
# File 'lib/simplefeed/feed.rb', line 16

def name
  @name
end

#namespaceObject

Returns the value of attribute namespace.



9
10
11
# File 'lib/simplefeed/feed.rb', line 9

def namespace
  @namespace
end

#per_pageObject

Returns the value of attribute per_page.



9
10
11
# File 'lib/simplefeed/feed.rb', line 9

def per_page
  @per_page
end

Instance Method Details

#activity(one_or_more_users) ⇒ Object

Depending on the argument returns either SingleUserActivity or MultiUserActivity



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

def activity(one_or_more_users)
  one_or_more_users.is_a?(Array) ?
    users_activity(one_or_more_users) :
    user_activity(one_or_more_users)
end

#class_attrsObject



86
87
88
# File 'lib/simplefeed/feed.rb', line 86

def class_attrs
  SimpleFeed.class_attributes(self.class)
end

#configure(hash = {}) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



65
66
67
68
69
70
71
# File 'lib/simplefeed/feed.rb', line 65

def configure(hash = {})
  SimpleFeed.symbolize!(hash)
  class_attrs.each do |attr|
    send("#{attr}=", hash[attr]) if hash.key?(attr)
  end
  yield self if block_given?
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
83
84
# File 'lib/simplefeed/feed.rb', line 80

def eql?(other)
  other.class == self.class &&
    %i(per_page max_size name namespace data_key_transformer meta_key_transformer).all? { |m| send(m).equal?(other.send(m)) } &&
    provider.provider.class == other.provider.provider.class
end

#key(user_id) ⇒ Object



73
74
75
76
77
78
# File 'lib/simplefeed/feed.rb', line 73

def key(user_id)
  SimpleFeed::Providers::Key.new(user_id,
                                 namespace:            namespace,
                                 data_key_transformer: data_key_transformer,
                                 meta_key_transformer: meta_key_transformer)
end

#providerObject



42
43
44
# File 'lib/simplefeed/feed.rb', line 42

def provider
  @proxy
end

#provider=(definition) ⇒ Object



36
37
38
39
40
# File 'lib/simplefeed/feed.rb', line 36

def provider=(definition)
  @proxy = Providers::Proxy.from(definition)
  @proxy.feed = self
  @proxy
end

#provider_typeObject



46
47
48
# File 'lib/simplefeed/feed.rb', line 46

def provider_type
  SimpleFeed::Providers::Base::Provider.class_to_registry(@proxy.provider.class)
end

#user_activity(user_id) ⇒ Object



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

def user_activity(user_id)
  Activity::SingleUser.new(user_id: user_id, feed: self)
end

#users_activity(user_ids) ⇒ Object



54
55
56
# File 'lib/simplefeed/feed.rb', line 54

def users_activity(user_ids)
  Activity::MultiUser.new(user_ids: user_ids, feed: self)
end