flexible_feeds 0.1.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 38f307f3b75cd9a484848e2268b3cbf08c99dac3
4
- data.tar.gz: 8bd9504bf1642e5e597e1f3a8ecd371f35e1da2f
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NTc4OTkwOWJiOTc3N2RlMTMwNGMyOWY0Y2YwN2U2N2Q5ZWQ2MGI1Yw==
5
+ data.tar.gz: !binary |-
6
+ ZDI5NTYxYWM3NGY4MGVjMzljOWNmZDJjNzdlOGExY2M5MzUyOWRjMg==
5
7
  SHA512:
6
- metadata.gz: f7ae27f7602d9fb8af8e59a78baa6f536b4227444f6e50ed2b678075b4c5084546f1553517fc0a01ab3e90081f041fa6823323eab1e8b6e759495097386f46e7
7
- data.tar.gz: c8d6a4393750c7eaa9a08c37048706f6aa621f3e8a89ca51ea794ff41198957461d6f6a40e3cf42e3c5f79d40eb2c50c85afbe370db5ae12a463c22036114e4b
8
+ metadata.gz: !binary |-
9
+ OGUzNmQzZDQ5Mjk1NTNjNDgzMzlkM2JiMjI0Y2M5NzZhMGRlYWNkOGE3MWIx
10
+ MGU4YTZlOTBhNzA4NGUxODQ2MDcwM2ZkMWE2NjUxNWFkNjFhNDk1ZmFmZjNl
11
+ OGNjNmQ2MjJhYjQ1MTkyN2ZhNmRlM2I0ZjdiYTc0NWMyMGQ4ZTg=
12
+ data.tar.gz: !binary |-
13
+ MWYxMjU1NGRmMWY1MDgzYmEzYjgyMWFkMjMxN2IyZGVmODJkYmY1ZDVmNWMy
14
+ ZjRmMzI4NWE4MTM5OGEwZjc1M2Q0NzczOGExODBhYTYxNmZlNDAxNmY4OTYz
15
+ NWYwNDFiYjMxOGNmZDE3MWRhYmZjNzI3Y2U4ZmFlYTNkYjBjOGI=
@@ -50,10 +50,7 @@ module FlexibleFeeds
50
50
  # Thanks to Evan Miller
51
51
  # http://www.evanmiller.org/how-not-to-sort-by-average-rating.html
52
52
  def calculate_popularity(pos, n)
53
- return 0 if n == 0
54
- z = 1.96
55
- phat = 1.0*pos/n
56
- (phat + z*z/(2*n) - z * Math.sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n)
53
+ PopularityCalculator.new(pos, n).get_popularity
57
54
  end
58
55
  end
59
56
  end
@@ -1,11 +1,12 @@
1
1
  require "flexible_feeds/engine"
2
- require "flexible_feeds/acts_as_feedable"
2
+ require "flexible_feeds/flexible_feeds"
3
3
  require "flexible_feeds/acts_as_eventable"
4
4
  require "flexible_feeds/acts_as_moderator"
5
5
  require "flexible_feeds/acts_as_follower"
6
6
  require "flexible_feeds/acts_as_parent"
7
7
  require "flexible_feeds/acts_as_child"
8
8
  require "flexible_feeds/polymorphic_join"
9
+ require "flexible_feeds/popularity_calculator"
9
10
 
10
11
  module FlexibleFeeds
11
12
  end
@@ -18,6 +18,18 @@ module FlexibleFeeds
18
18
 
19
19
  cattr_accessor :created_by
20
20
  self.created_by = options[:created_by]
21
+
22
+ if options[:is_parent] === true
23
+ acts_as_parent
24
+ elsif options[:is_parent].present?
25
+ acts_as_parent options[:is_parent]
26
+ end
27
+
28
+ if options[:is_child] === true
29
+ acts_as_child
30
+ elsif options[:is_child].present?
31
+ acts_as_child options[:is_child]
32
+ end
21
33
  end
22
34
  end
23
35
 
@@ -1,9 +1,9 @@
1
1
  module FlexibleFeeds
2
- module ActsAsFeedable
2
+ module HasFlexibleFeed
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  module ClassMethods
6
- def acts_as_feedable(options = {})
6
+ def flexible_feeds(options = {})
7
7
 
8
8
  cattr_accessor :has_many_feeds
9
9
  self.has_many_feeds = options[:has_many] || false
@@ -29,4 +29,4 @@ module FlexibleFeeds
29
29
  end
30
30
  end
31
31
 
32
- ActiveRecord::Base.send :include, FlexibleFeeds::ActsAsFeedable
32
+ ActiveRecord::Base.send :include, FlexibleFeeds::HasFlexibleFeed
@@ -6,21 +6,33 @@ module FlexibleFeeds
6
6
  def polymorphically_joined_through(join_table, params)
7
7
  association = params[:association_name]
8
8
  singular_association = params[:singular_association_name]
9
-
9
+ define_association(join_table, association, singular_association)
10
+ define_include(join_table, association, singular_association)
11
+ define_add(join_table, association, singular_association)
12
+ define_remove(join_table, association, singular_association)
13
+ end
14
+
15
+ def define_association(join_table, association, singular_association)
10
16
  define_method association do
11
17
  send(join_table).collect { |join| join.send(singular_association) }
12
18
  end
13
-
19
+ end
20
+
21
+ def define_include(join_table, association, singular_association)
14
22
  define_method "#{association}_include?".to_sym do |instance|
15
23
  send(join_table).where(singular_association => instance).exists?
16
24
  end
17
-
25
+ end
26
+
27
+ def define_add(join_table, association, singular_association)
18
28
  define_method "add_#{singular_association}".to_sym do |instance|
19
29
  result = send(join_table).create(singular_association => instance)
20
30
  self.reload()
21
31
  result
22
32
  end
23
-
33
+ end
34
+
35
+ def define_remove(join_table, association, singular_association)
24
36
  define_method "remove_#{singular_association}".to_sym do |instance|
25
37
  return false unless send("#{association}_include?", instance)
26
38
  result = send(join_table).
@@ -0,0 +1,37 @@
1
+ module FlexibleFeeds
2
+ class PopularityCalculator
3
+
4
+ attr_accessor :pos, :n
5
+ def initialize(pos, n)
6
+ @pos = pos
7
+ @n = n
8
+ end
9
+
10
+ def get_popularity
11
+ return 0 if n == 0
12
+ dividend / divisor
13
+ end
14
+
15
+ private
16
+ def z
17
+ 1.96
18
+ end
19
+
20
+ def phat
21
+ 1.0 * pos / n
22
+ end
23
+
24
+ def dividend
25
+ phat + z*z/(2*n) - z * sqrt
26
+ end
27
+
28
+ def sqrt
29
+ Math.sqrt((phat*(1-phat)+z*z/(4*n))/n)
30
+ end
31
+
32
+ def divisor
33
+ 1+z*z/n
34
+ end
35
+
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module FlexibleFeeds
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexible_feeds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - timothycommoner
@@ -28,112 +28,112 @@ dependencies:
28
28
  name: pg
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: debugger
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec-rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '>='
73
+ - - ! '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '>='
80
+ - - ! '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: guard-spork
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '>='
87
+ - - ! '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '>='
94
+ - - ! '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: factory_girl_rails
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - '>='
101
+ - - ! '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - '>='
108
+ - - ! '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: database_cleaner
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - '>='
115
+ - - ! '>='
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - '>='
122
+ - - ! '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: shoulda
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - '>='
129
+ - - ! '>='
130
130
  - !ruby/object:Gem::Version
131
131
  version: '0'
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - '>='
136
+ - - ! '>='
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  description: A flexible feed system, allowing for everything from automated events
@@ -144,39 +144,40 @@ executables: []
144
144
  extensions: []
145
145
  extra_rdoc_files: []
146
146
  files:
147
+ - MIT-LICENSE
148
+ - README.rdoc
149
+ - Rakefile
150
+ - app/assets/javascripts/flexible_feeds/application.js
151
+ - app/assets/stylesheets/flexible_feeds/application.css
152
+ - app/controllers/flexible_feeds/application_controller.rb
147
153
  - app/helpers/flexible_feeds/application_helper.rb
148
- - app/models/flexible_feeds/moderator_join.rb
149
- - app/models/flexible_feeds/vote.rb
150
154
  - app/models/flexible_feeds/event.rb
151
155
  - app/models/flexible_feeds/event_join.rb
152
156
  - app/models/flexible_feeds/feed.rb
153
157
  - app/models/flexible_feeds/follow.rb
154
- - app/controllers/flexible_feeds/application_controller.rb
155
- - app/assets/javascripts/flexible_feeds/application.js
156
- - app/assets/stylesheets/flexible_feeds/application.css
158
+ - app/models/flexible_feeds/moderator_join.rb
159
+ - app/models/flexible_feeds/vote.rb
157
160
  - app/views/layouts/flexible_feeds/application.html.erb
158
- - config/routes.rb
159
161
  - config/locales/en.yml
160
- - db/migrate/20140227195107_create_flexible_feeds_follows.rb
162
+ - config/routes.rb
163
+ - db/migrate/20140227194731_create_flexible_feeds_feeds.rb
161
164
  - db/migrate/20140227194816_create_flexible_feeds_events.rb
162
- - db/migrate/20140227195044_create_flexible_feeds_moderator_joins.rb
163
165
  - db/migrate/20140227194904_create_flexible_feeds_event_joins.rb
166
+ - db/migrate/20140227195044_create_flexible_feeds_moderator_joins.rb
167
+ - db/migrate/20140227195107_create_flexible_feeds_follows.rb
164
168
  - db/migrate/20140227195140_create_flexible_feeds_votes.rb
165
- - db/migrate/20140227194731_create_flexible_feeds_feeds.rb
166
- - lib/tasks/flexible_feeds_tasks.rake
169
+ - lib/flexible_feeds.rb
170
+ - lib/flexible_feeds/acts_as_child.rb
167
171
  - lib/flexible_feeds/acts_as_eventable.rb
168
- - lib/flexible_feeds/acts_as_moderator.rb
169
172
  - lib/flexible_feeds/acts_as_follower.rb
170
- - lib/flexible_feeds/polymorphic_join.rb
171
- - lib/flexible_feeds/acts_as_feedable.rb
172
- - lib/flexible_feeds/version.rb
173
+ - lib/flexible_feeds/acts_as_moderator.rb
173
174
  - lib/flexible_feeds/acts_as_parent.rb
174
- - lib/flexible_feeds/acts_as_child.rb
175
175
  - lib/flexible_feeds/engine.rb
176
- - lib/flexible_feeds.rb
177
- - MIT-LICENSE
178
- - Rakefile
179
- - README.rdoc
176
+ - lib/flexible_feeds/flexible_feeds.rb
177
+ - lib/flexible_feeds/polymorphic_join.rb
178
+ - lib/flexible_feeds/popularity_calculator.rb
179
+ - lib/flexible_feeds/version.rb
180
+ - lib/tasks/flexible_feeds_tasks.rake
180
181
  homepage: https://github.com/timothycommoner/flexible_feeds
181
182
  licenses: []
182
183
  metadata: {}
@@ -186,17 +187,17 @@ require_paths:
186
187
  - lib
187
188
  required_ruby_version: !ruby/object:Gem::Requirement
188
189
  requirements:
189
- - - '>='
190
+ - - ! '>='
190
191
  - !ruby/object:Gem::Version
191
192
  version: '0'
192
193
  required_rubygems_version: !ruby/object:Gem::Requirement
193
194
  requirements:
194
- - - '>='
195
+ - - ! '>='
195
196
  - !ruby/object:Gem::Version
196
197
  version: '0'
197
198
  requirements: []
198
199
  rubyforge_project:
199
- rubygems_version: 2.0.5
200
+ rubygems_version: 2.2.2
200
201
  signing_key:
201
202
  specification_version: 4
202
203
  summary: A flexible feed system.