simple-feed 2.0.2 → 3.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +5 -5
  2. data/.envrc +3 -0
  3. data/.github/workflows/rubocop.yml +33 -0
  4. data/.github/workflows/ruby.yml +34 -0
  5. data/.gitignore +2 -1
  6. data/.relaxed-rubocop-2.4.yml +174 -0
  7. data/.rspec +1 -1
  8. data/.rubocop.yml +43 -1150
  9. data/.rubocop_todo.yml +203 -0
  10. data/.travis.yml +7 -10
  11. data/CHANGELOG.md +120 -0
  12. data/Gemfile +4 -0
  13. data/Guardfile +3 -3
  14. data/README.adoc +601 -0
  15. data/Rakefile +5 -6
  16. data/bin/console +1 -0
  17. data/codecov.yml +28 -0
  18. data/examples/shared/provider_example.rb +51 -26
  19. data/lib/simple-feed.rb +2 -0
  20. data/lib/simple_feed.rb +2 -0
  21. data/lib/simplefeed/activity/base.rb +2 -0
  22. data/lib/simplefeed/activity/multi_user.rb +8 -6
  23. data/lib/simplefeed/activity/single_user.rb +7 -6
  24. data/lib/simplefeed/dsl/activities.rb +4 -3
  25. data/lib/simplefeed/dsl/formatter.rb +79 -40
  26. data/lib/simplefeed/dsl.rb +3 -1
  27. data/lib/simplefeed/event.rb +52 -13
  28. data/lib/simplefeed/feed.rb +36 -28
  29. data/lib/simplefeed/providers/base/provider.rb +7 -4
  30. data/lib/simplefeed/providers/hash.rb +2 -0
  31. data/lib/simplefeed/providers/key.rb +60 -36
  32. data/lib/simplefeed/providers/proxy.rb +28 -14
  33. data/lib/simplefeed/providers/redis/driver.rb +25 -27
  34. data/lib/simplefeed/providers/redis/provider.rb +41 -39
  35. data/lib/simplefeed/providers/redis/stats.rb +12 -13
  36. data/lib/simplefeed/providers/redis.rb +2 -0
  37. data/lib/simplefeed/providers.rb +24 -10
  38. data/lib/simplefeed/response.rb +7 -7
  39. data/lib/simplefeed/version.rb +3 -1
  40. data/lib/simplefeed.rb +27 -21
  41. data/man/running-example-redis-debug.png +0 -0
  42. data/man/running-example.png +0 -0
  43. data/man/sf-color-dump.png +0 -0
  44. data/simple-feed.gemspec +23 -16
  45. metadata +115 -44
  46. data/README.md +0 -415
  47. data/examples/hash_provider_example.rb +0 -24
  48. data/lib/simplefeed/key/template.rb +0 -52
  49. data/lib/simplefeed/key/type.rb +0 -26
  50. data/lib/simplefeed/providers/hash/paginator.rb +0 -31
  51. data/lib/simplefeed/providers/hash/provider.rb +0 -198
@@ -1,3 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
1
4
  $LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
2
5
 
3
6
  # Please set @feed in the enclosing context
@@ -5,9 +8,15 @@ $LOAD_PATH.unshift File.expand_path('../../../lib', __FILE__)
5
8
  raise ArgumentError, 'No @feed defined in the enclosing example' unless defined?(@feed)
6
9
 
7
10
  require 'simplefeed'
11
+ require 'uuid'
12
+
13
+ srand(Time.now.to_i % 100003)
14
+
15
+ @number_of_users = ARGV[0] ? ARGV[0].to_i : 2
16
+ @users = @number_of_users.times.map do |n|
17
+ n % 2 == 0 ? UUID.generate : rand(100003)
18
+ end
8
19
 
9
- @number_of_users = ARGV[0] ? ARGV[0].to_i : 1
10
- @users = Array.new(@number_of_users) { rand(200_000_000...800_000_000) }
11
20
  @activity = @feed.activity(@users)
12
21
  @uid = @users.first
13
22
 
@@ -20,48 +29,64 @@ class Object
20
29
  end
21
30
 
22
31
  def p(*args)
23
- printf "%-40s %s\n", args[0].blue, args[1].bold.red
32
+ printf "%40s %s\n", args[0].strip.blue.bold, args[1].bold.red
24
33
  end
25
34
 
26
35
  with_activity(@activity) do
27
-
28
- header "#{@activity.feed.provider_type} provider example"
36
+ header "#{@activity.feed.provider_type} provider example".upcase,
37
+ "Starting with a blank feed, no items",
38
+ align: :center
29
39
 
30
40
  wipe
31
41
 
32
- store('value one') { p 'storing new value', 'value one' }
33
- store('value two') { p 'storing new value', 'value two' }
34
- store('value three') { p 'storing new value', 'value three' }
35
-
36
- hr
42
+ store('value one') { p 'storing new value', 'value one' }
43
+ store('value two') { p 'storing new value', 'value two' }
44
+ store('value three') { p 'storing new value', 'value three' }
37
45
 
38
- total_count { |r| p 'total_count is now', "#{r[@uid]._v}" }
39
- unread_count { |r| p 'unread_count is now', "#{r[@uid]._v}" }
46
+ total_count { |r| p 'total_count is now', "#{r[@uid]._v}" }
47
+ unread_count { |r| p 'unread_count is now', "#{r[@uid]._v}" }
40
48
 
41
- header 'paginate(page: 1, per_page: 2)'
49
+ header 'activity.paginate(page: 1, per_page: 2)'
42
50
  paginate(page: 1, per_page: 2) { |r| puts r[@uid].map(&:to_color_s) }
43
- header 'paginate(page: 2, per_page: 2, reset_last_read: true)'
44
- paginate(page: 2, per_page: 2, reset_last_read: true) { |r| puts r[@uid].map(&:to_color_s) }
45
51
 
46
- hr
52
+ header 'activity.paginate(page: 2, per_page: 2, reset_last_read: true)'
53
+ paginate(page: 2, per_page: 2, reset_last_read: true) { |r| puts r[@uid].map(&:to_color_s) }
47
54
 
48
- total_count { |r| p 'total_count ', "#{r[@uid]._v}" }
49
- unread_count { |r| p 'unread_count ', "#{r[@uid]._v}" }
55
+ total_count { |r| p 'total_count ', "#{r[@uid]._v}" }
56
+ unread_count { |r| p 'unread_count ', "#{r[@uid]._v}" }
50
57
 
51
- hr
52
- store('value four') { p 'storing', 'value four' }
58
+ store('value four') { p 'storing', 'value four' }
53
59
 
54
60
  color_dump
55
61
 
56
62
  header 'deleting'
57
63
 
58
- delete('value three') { p 'deleting', 'value three' }
59
- total_count { |r| p 'total_count ', "#{r[@uid]._v}" }
60
- unread_count { |r| p 'unread_count ', "#{r[@uid]._v}" }
64
+ delete('value three') { p 'deleting', 'value three' }
65
+
66
+ total_count { |r| p 'total_count ', "#{r[@uid]._v}" }
67
+ unread_count { |r| p 'unread_count ', "#{r[@uid]._v}" }
68
+
61
69
  hr
62
- delete('value four') { p 'deleting', 'value four' }
63
- total_count { |r| p 'total_count ', "#{r[@uid]._v}" }
64
- unread_count { |r| p 'unread_count ', "#{r[@uid]._v}" }
65
70
 
71
+ delete('value four') { p 'deleting', 'value four' }
72
+ total_count { |r| p 'total_count ', "#{r[@uid]._v}" }
73
+ unread_count { |r| p 'unread_count ', "#{r[@uid]._v}" }
74
+
75
+ puts
76
+ end
77
+
78
+ notes = [
79
+ 'Thanks for trying SimpleFeed!', 'For any questions, reach out to',
80
+ 'kigster@gmail.com',
81
+ ]
82
+
83
+ unless ENV['REDIS_DEBUG']
84
+ notes << [
85
+ '———',
86
+ 'To see REDIS commands, set REDIS_DEBUG environment variable to true,',
87
+ 'and re-run the example.'
88
+ ]
66
89
  end
67
90
 
91
+ header notes.flatten,
92
+ align: :center
data/lib/simple-feed.rb CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'simplefeed'
data/lib/simple_feed.rb CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'simplefeed'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SimpleFeed
2
4
  module Activity
3
5
  class Base
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'forwardable'
2
4
  require_relative 'base'
3
5
 
4
6
  module SimpleFeed
5
7
  module Activity
6
8
  class MultiUser < Base
7
-
8
9
  attr_reader :user_ids
9
10
 
10
11
  extend Forwardable
@@ -16,7 +17,7 @@ module SimpleFeed
16
17
  # API Examples
17
18
  # ============
18
19
  #
19
- #```ruby
20
+ # ```ruby
20
21
  # @multi = SimpleFeed.get(:feed_name).activity(User.active.map(&:id))
21
22
  #
22
23
  # @multi.store(value:, at:)
@@ -54,15 +55,15 @@ module SimpleFeed
54
55
  # # => [Response] { user_id => [Time] last_read, ... }
55
56
  #
56
57
  # @multi.total_count
57
- # # => [Response] { user_id => [Integer] total_count, ... }
58
+ # # => [Response] { user_id => [Integer, String] total_count, ... }
58
59
  #
59
60
  # @multi.unread_count
60
- # # => [Response] { user_id => [Integer] unread_count, ... }
61
+ # # => [Response] { user_id => [Integer, String] unread_count, ... }
61
62
  #
62
63
  # @multi.last_read
63
64
  # # => [Response] { user_id => [Time] last_read, ... }
64
65
  #
65
- #```
66
+ # ```
66
67
 
67
68
  SimpleFeed::Providers.define_provider_methods(self) do |instance, method, *args, **opts, &block|
68
69
  opts.merge!(user_ids: instance.user_ids)
@@ -71,8 +72,9 @@ module SimpleFeed
71
72
  opts.delete(:event)
72
73
  end
73
74
  response = instance.feed.send(method, *args, **opts, &block)
74
- yield(response) if block_given?
75
+ block&.call(response)
75
76
  raise StandardError, "Nil response from provider #{instance.feed.provider&.provider&.class}, method #{method}(#{opts})" unless response
77
+
76
78
  response
77
79
  end
78
80
 
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'base'
2
4
 
3
5
  module SimpleFeed
4
6
  module Activity
5
-
6
7
  # Lazy implementation of SingleUser based on delegating an array of
7
8
  # one user_id to +MultiUser+
8
9
 
@@ -16,7 +17,7 @@ module SimpleFeed
16
17
  yield(user_id)
17
18
  end
18
19
 
19
- #```ruby
20
+ # ```ruby
20
21
  # @activity = SimpleFeed.get(:feed_name).activity(current_user.id)
21
22
  #
22
23
  # @activity.store(value:, at:)
@@ -61,20 +62,20 @@ module SimpleFeed
61
62
  # @activity.last_read
62
63
  # # => [Time] last_read
63
64
 
64
-
65
65
  SimpleFeed::Providers.define_provider_methods(self) do |instance, method, *args, **opts, &block|
66
66
  response = instance.user_activity.send(method, *args, **opts, &block)
67
67
  unless response.has_user?(instance.user_id)
68
68
  raise StandardError, "Nil response from provider #{instance.feed.provider&.provider&.class}, method #{method}(#{opts}) — user_id #{instance.user_id}"
69
69
  end
70
+
70
71
  response = response[instance.user_id]
71
- yield(response) if block_given?
72
+ block&.call(response)
72
73
  response
73
74
  end
74
75
 
75
76
  def initialize(user_id:, feed:)
76
- @feed = feed
77
- @user_id = user_id
77
+ @feed = feed
78
+ @user_id = user_id
78
79
  self.user_activity = MultiUser.new(feed: feed, user_ids: [user_id])
79
80
  end
80
81
  end
@@ -1,8 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'formatter'
2
4
  module SimpleFeed
3
5
  module DSL
4
6
  class Activities
5
-
6
7
  include SimpleFeed::DSL::Formatter
7
8
 
8
9
  attr_accessor :activity, :feed
@@ -14,7 +15,7 @@ module SimpleFeed
14
15
  self.class.instance_eval do
15
16
  attr_accessor key
16
17
  end
17
- self.send("#{key}=".to_sym, value)
18
+ send("#{key}=".to_sym, value)
18
19
  end
19
20
  end
20
21
 
@@ -60,7 +61,7 @@ module SimpleFeed
60
61
 
61
62
  def print_debug_info(method, **opts)
62
63
  brackets = opts.empty? ? ['', ''] : %w{( )}
63
- printf "\n#{self.feed.name.to_s.blue}.#{method.to_s.cyan.bold}#{brackets[0]}#{opts.to_s.gsub(/[{}]/, '').blue}#{brackets[1]} \n" if SimpleFeed::DSL.debug?
64
+ printf "\n#{feed.name.to_s.blue}.#{method.to_s.cyan.bold}#{brackets[0]}#{opts.to_s.gsub(/[{}]/, '').blue}#{brackets[1]} \n" if SimpleFeed::DSL.debug?
64
65
  response = yield if block_given?
65
66
  puts response.inspect.yellow if SimpleFeed::DSL.debug?
66
67
  response
@@ -1,6 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tty-box'
4
+ require 'tty-screen'
1
5
  require 'simplefeed/dsl'
2
6
  require 'simplefeed/activity/single_user'
3
7
  require 'simplefeed/activity/multi_user'
8
+ require 'awesome_print'
9
+
4
10
  module SimpleFeed
5
11
  module DSL
6
12
  # This module exports method #color_dump which receives an activity and
@@ -13,45 +19,46 @@ module SimpleFeed
13
19
 
14
20
  def color_dump(this_activity = activity)
15
21
  this_activity = if this_activity.is_a?(SimpleFeed::Activity::SingleUser)
16
- this_activity.feed.activity([this_activity.user_id])
17
- else
18
- this_activity
19
- end
22
+ this_activity.feed.activity([this_activity.user_id])
23
+ else
24
+ this_activity
25
+ end
20
26
  _puts
21
27
 
22
- header do
23
- field('Feed Name', feed.name, "\n")
24
- field('Provider', feed.provider.provider.class, "\n")
25
- field('Max Size', feed.max_size, "\n")
28
+ feed_header(feed) do
29
+ [
30
+ field('Feed Name', feed.name, "\n"),
31
+ field('Provider', feed.provider.provider.class, "\n"),
32
+ field('Max Size', feed.max_size, "\n")
33
+ ]
26
34
  end
27
35
 
28
36
  with_activity(this_activity) do
29
- this_activity.each do |user_id|
37
+ this_activity.each_with_index do |user_id, index|
30
38
  this_last_event_at = nil
31
39
  this_last_read = (last_read[user_id] || 0.0).to_f
32
40
 
41
+ fields = []
33
42
  [['User ID', user_id, "\n"],
34
43
  ['Activities', sprintf('%d total, %d unread', total_count[user_id], unread_count[user_id]), "\n"],
35
- ['Last Read', this_last_read ? Time.at(this_last_read) : 'N/A'],
36
- ].each do |field, value, *args|
37
- field(field, value, *args)
44
+ ['Last Read', this_last_read ? Time.at(this_last_read) : 'N/A'],].each do |field, value, *args|
45
+ fields << field(field, value, *args)
38
46
  end
39
47
 
40
- _puts; hr '¨'
48
+ header(title: { top_center: " « User Activity #{index + 1} » " }, style: { fg: :green }) { fields }
41
49
 
42
50
  this_events = fetch[user_id]
43
51
  this_events_count = this_events.size
44
- this_events.each_with_index do |_event, _index|
45
-
46
- if this_last_event_at.nil? && _event.at < this_last_read
52
+ this_events.each_with_index do |evt, idx|
53
+ if this_last_event_at.nil? && evt.at < this_last_read
47
54
  print_last_read_separator(this_last_read)
48
- elsif this_last_event_at && this_last_read < this_last_event_at && this_last_read > _event.at
55
+ elsif this_last_event_at && this_last_read < this_last_event_at && this_last_read > evt.at
49
56
  print_last_read_separator(this_last_read)
50
57
  end
51
58
 
52
- this_last_event_at = _event.at # float
53
- _print "[%2d] %16s %s\n", _index, _event.time.strftime(TIME_FORMAT).blue.bold, _event.value
54
- if _index == this_events_count - 1 && this_last_read < _event.at
59
+ this_last_event_at = evt.at # float
60
+ output "[%2d] %16s %s\n", idx, evt.time.strftime(TIME_FORMAT).blue.bold, evt.value
61
+ if idx == this_events_count - 1 && this_last_read < evt.at
55
62
  print_last_read_separator(this_last_read)
56
63
  end
57
64
  end
@@ -60,17 +67,18 @@ module SimpleFeed
60
67
  end
61
68
 
62
69
  def print_last_read_separator(lr)
63
- _print ">>>> %16s <<<< last read\n", Time.at(lr).strftime(TIME_FORMAT).red.bold
70
+ output "———— %16s [last read] ———————————— \n", Time.at(lr).strftime(TIME_FORMAT).red.bold
64
71
  end
65
72
  end
66
73
 
74
+ # This allows redirecting output in tests.
67
75
  @print_method = :printf
68
76
 
69
77
  class << self
70
78
  attr_accessor :print_method
71
79
  end
72
80
 
73
- def _print(*args, **opts, &block)
81
+ def output(*args, **opts, &block)
74
82
  send(SimpleFeed::DSL.print_method, *args, **opts, &block)
75
83
  end
76
84
 
@@ -82,35 +90,66 @@ module SimpleFeed
82
90
  sprintf ' %20s ', text
83
91
  end
84
92
 
85
- TIME_FORMAT = '%Y-%m-%d %H:%M:%S.%L'
86
-
87
93
  def field_value(value)
88
94
  case value
89
- when Numeric
90
- sprintf '%-20d', value
91
- when Time
92
- sprintf '%-30s', value.strftime(TIME_FORMAT)
93
- else
94
- sprintf '%-20s', value.to_s
95
+ when Numeric
96
+ sprintf '%-20d', value
97
+ when Time
98
+ sprintf '%-30s', value.strftime(TIME_FORMAT)
99
+ else
100
+ sprintf '%-20s', value.to_s
95
101
  end
96
102
  end
97
103
 
98
- def field(label, value, sep = '')
99
- _print field_label(label).italic + field_value(value).cyan.bold + sep
104
+ def field(label, value, _sep = '')
105
+ field_label(label) + ' ❯ ' + field_value(value)
106
+ end
107
+
108
+ def hr
109
+ output hr_string.magenta
110
+ end
111
+
112
+ def hr_string
113
+ '―' * width + "\n"
114
+ end
115
+
116
+ def width
117
+ @width ||= [[TTY::Screen.width - 5, 60].max, 75].min
100
118
  end
101
119
 
102
- def hr(char = '—')
103
- _print(_hr(char).magenta)
120
+ def feed_header(feed, &block)
121
+ header title: { top_left: " « #{feed.name.capitalize} Feed » " },
122
+ border: :thick,
123
+ style: {
124
+ fg: :black,
125
+ bg: :green,
126
+ border: { fg: :bright_black, bg: :green }
127
+ }, &block
104
128
  end
105
129
 
106
- def _hr(char = '—')
107
- char * 75 + "\n"
130
+ def header(*args, **opts)
131
+ message = args.join("\n")
132
+ msg = block_given? ? (yield || message) : message + "\n"
133
+ config = box_config(**opts)
134
+ lines = Array(msg).flatten
135
+ box = TTY::Box.frame(*lines, **config)
136
+ output "\n#{box}"
108
137
  end
109
138
 
110
- def header(message = nil)
111
- _print(_hr.green.bold)
112
- block_given? ? yield : _print(message.green.italic + "\n")
113
- _print(_hr.green.bold)
139
+ private
140
+
141
+ def box_config(**opts)
142
+ {
143
+ width: width,
144
+ align: :left,
145
+ padding: [1, 3],
146
+ style: {
147
+ fg: :bright_yellow,
148
+ border: {
149
+ fg: :bright_magenta,
150
+ }
151
+ }
152
+ }.merge(opts)
114
153
  end
115
154
  end
116
155
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'providers'
2
4
  require 'simplefeed'
3
5
  require_relative 'dsl/activities'
@@ -22,7 +24,7 @@ module SimpleFeed
22
24
  attr_accessor :debug
23
25
 
24
26
  def debug?
25
- self.debug
27
+ debug
26
28
  end
27
29
  end
28
30
 
@@ -1,12 +1,30 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
 
3
5
  module SimpleFeed
4
6
  class Event
5
7
  attr_accessor :value, :at
8
+
6
9
  include Comparable
7
10
 
11
+ class << self
12
+ attr_accessor :is_time
13
+ end
14
+
15
+ # This proc can be overridden in a configuration if needed.
16
+ # @example To always assume this is time, set it like so,
17
+ # before defining your feeds.
18
+ #
19
+ # SimpleFeed::Event.is_time = ->(*) { true }
20
+ #
21
+ self.is_time = ->(float) {
22
+ # assume it's time if epoch is > June 1974 and < December 2040.
23
+ float < 2_237_932_800.0 && float > 139_276_800.0
24
+ }
25
+
8
26
  def initialize(*args, value: nil, at: Time.now)
9
- if args && args.size > 0
27
+ if args && !args.empty?
10
28
  self.value = args[0]
11
29
  self.at = args[1]
12
30
  end
@@ -20,7 +38,11 @@ module SimpleFeed
20
38
  end
21
39
 
22
40
  def time
41
+ return nil unless Event.is_time[at]
42
+
23
43
  Time.at(at)
44
+ rescue ArgumentError
45
+ nil
24
46
  end
25
47
 
26
48
  def <=>(other)
@@ -36,15 +58,11 @@ module SimpleFeed
36
58
  self.value == other.value
37
59
  end
38
60
 
39
- def to_h
40
- { value: value, at: at, time: time }
41
- end
42
-
43
61
  def hash
44
62
  self.value.hash
45
63
  end
46
64
 
47
- def to_json
65
+ def to_json(*_args)
48
66
  to_h.to_json
49
67
  end
50
68
 
@@ -52,16 +70,38 @@ module SimpleFeed
52
70
  YAML.dump(to_h)
53
71
  end
54
72
 
73
+ def to_h
74
+ return @to_h if @to_h
75
+
76
+ @to_h ||= { value: value, at: at }
77
+ @to_h.merge!(time: time) if time
78
+ @to_h
79
+ end
80
+
55
81
  def to_s
56
- "<SimpleFeed::Event: value='#{value}', at='#{at}', time='#{time}'>"
82
+ return @to_s if @to_s
83
+
84
+ output = StringIO.new
85
+ output.print "<SimpleFeed::Event: "
86
+ output.print(time.nil? ? "[#{at}]" : "[#{time&.strftime(::SimpleFeed::TIME_FORMAT)}]")
87
+ output.print ", [\"#{value}\"]"
88
+ @to_s = output.string
57
89
  end
58
90
 
91
+ COLOR_MAP = {
92
+ 1 => ->(word) { word.green.bold },
93
+ 3 => ->(word) { word.yellow.bold },
94
+ }.freeze
95
+
59
96
  def to_color_s
60
- counter = 0
61
- to_s.split(/[']/).map do |word|
62
- counter += 1
63
- counter.even? ? word.yellow.bold : word.blue
64
- end.join('')
97
+ return @to_color_s if @to_color_s
98
+
99
+ output = StringIO.new
100
+ to_s.split(/[\[\]]/).each_with_index do |word, index|
101
+ output.print(COLOR_MAP[index]&.call(word) || word.cyan)
102
+ end
103
+ output.print '>'
104
+ @to_color_s = output.string
65
105
  end
66
106
 
67
107
  def inspect
@@ -75,6 +115,5 @@ module SimpleFeed
75
115
  raise ArgumentError, "Required arguments missing, value=[#{value}], at=[#{at}]"
76
116
  end
77
117
  end
78
-
79
118
  end
80
119
  end
@@ -1,11 +1,18 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative 'providers'
2
4
  require_relative 'activity/base'
3
- require 'simplefeed/key/template'
5
+ require_relative 'providers/key'
4
6
 
5
7
  module SimpleFeed
6
8
  class Feed
9
+ attr_accessor :per_page,
10
+ :max_size,
11
+ :batch_size,
12
+ :namespace,
13
+ :data_key_transformer,
14
+ :meta_key_transformer
7
15
 
8
- attr_accessor :per_page, :max_size, :batch_size, :meta, :namespace
9
16
  attr_reader :name
10
17
 
11
18
  SimpleFeed::Providers.define_provider_methods(self) do |feed, method, opts, &block|
@@ -13,23 +20,21 @@ module SimpleFeed
13
20
  end
14
21
 
15
22
  def initialize(name)
16
- @name = name
17
- @name = name.underscore.to_sym unless name.is_a?(Symbol)
23
+ @name = name
24
+ @name = name.underscore.to_sym unless name.is_a?(Symbol)
18
25
  # set the defaults if not passed in
19
- @meta = {}
20
- @namespace = nil
21
- @per_page ||= 50
22
- @max_size ||= 1000
23
- @batch_size ||= 10
24
- @proxy = nil
25
- end
26
-
27
- def key_template
28
- SimpleFeed::Key::Template.new(namespace)
26
+ @meta = {}
27
+ @namespace = nil
28
+ @per_page ||= 50
29
+ @max_size ||= 1000
30
+ @batch_size ||= 10
31
+ @meta_key_transformer = nil
32
+ @data_key_transformer = nil
33
+ @proxy = nil
29
34
  end
30
35
 
31
36
  def provider=(definition)
32
- @proxy = Providers::Proxy.from(definition)
37
+ @proxy = Providers::Proxy.from(definition)
33
38
  @proxy.feed = self
34
39
  @proxy
35
40
  end
@@ -38,10 +43,6 @@ module SimpleFeed
38
43
  @proxy
39
44
  end
40
45
 
41
- def key(user_id)
42
- SimpleFeed::Providers::Key.new(user_id, key_template)
43
- end
44
-
45
46
  def provider_type
46
47
  SimpleFeed::Providers::Base::Provider.class_to_registry(@proxy.provider.class)
47
48
  end
@@ -61,28 +62,35 @@ module SimpleFeed
61
62
  user_activity(one_or_more_users)
62
63
  end
63
64
 
64
- # @deprecated Please use {#activity} instead
65
- def for(*args)
66
- STDERR.puts 'WARNING: method #for is deprecated, please use #activity'
67
- activity(*args)
68
- end
69
-
70
65
  def configure(hash = {})
71
66
  SimpleFeed.symbolize!(hash)
72
67
  class_attrs.each do |attr|
73
- self.send("#{attr}=", hash[attr]) if hash.key?(attr)
68
+ send("#{attr}=", hash[attr]) if hash.key?(attr)
74
69
  end
75
70
  yield self if block_given?
76
71
  end
77
72
 
73
+ def key(user_id)
74
+ SimpleFeed::Providers::Key.new(user_id,
75
+ namespace: namespace,
76
+ data_key_transformer: data_key_transformer,
77
+ meta_key_transformer: meta_key_transformer)
78
+ end
79
+
78
80
  def eql?(other)
79
81
  other.class == self.class &&
80
- %i(per_page max_size name).all? { |m| self.send(m).equal?(other.send(m)) } &&
81
- self.provider.provider.class == other.provider.provider.class
82
+ %i(per_page max_size name namespace data_key_transformer meta_key_transformer).all? { |m| send(m).equal?(other.send(m)) } &&
83
+ provider.provider.class == other.provider.provider.class
82
84
  end
83
85
 
84
86
  def class_attrs
85
87
  SimpleFeed.class_attributes(self.class)
86
88
  end
89
+
90
+ private
91
+
92
+ def key_template
93
+ SimpleFeed::Key::Template.new(namespace)
94
+ end
87
95
  end
88
96
  end