trendable 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +41 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +7 -0
- data/README.md +27 -0
- data/lib/concerns/trendable.rb +22 -0
- data/lib/generators/trendable/migration_generator.rb +32 -0
- data/lib/trendable.rb +15 -0
- data/lib/trendable/engine.rb +6 -0
- data/lib/trendable/trendable.rb +2 -0
- data/lib/trendable/version.rb +5 -0
- data/lib/workers/fade_out_trend_power_worker.rb +18 -0
- data/trendable.gemspec +26 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 10f3a8827131008a4a915c22e7679e840b439ed1
|
4
|
+
data.tar.gz: f26a79b4379659e3884bbb1b99c78199bb8b9d7d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7c072d0a5d6da8d3d1f878ef1a73f3ffcb389ea068c626d2426119812ecacff16df1c6e3e0d22480f4123b18a0e816c40d37d687f03632df18029ad006cdd55d
|
7
|
+
data.tar.gz: 61c01937bb4c99fcf10851070138b41bff5527b8389f669b56c09de961797f77774adb60aed3797ebaaa0dcca9a8085e52931a07c7c6c319d1e32bf416439fb0
|
data/.gitignore
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# See https://help.github.com/articles/ignoring-files for more about ignoring files.
|
2
|
+
#
|
3
|
+
# If you find yourself ignoring temporary files generated by your text editor
|
4
|
+
# or operating system, you probably want to add a global ignore instead:
|
5
|
+
# git config --global core.excludesfile '~/.gitignore_global'
|
6
|
+
|
7
|
+
# Ignore bundler config.
|
8
|
+
/.bundle
|
9
|
+
|
10
|
+
# Ignore the default SQLite database.
|
11
|
+
/db/*.sqlite3
|
12
|
+
/db/*.sqlite3-journal
|
13
|
+
|
14
|
+
# Ignore all logfiles and tempfiles.
|
15
|
+
/log/*
|
16
|
+
!/log/.keep
|
17
|
+
/tmp
|
18
|
+
|
19
|
+
|
20
|
+
/solr/data/*
|
21
|
+
/solr/development/*
|
22
|
+
/solr/default/data/*
|
23
|
+
/solr/pids/*
|
24
|
+
sunspot-solr.pid
|
25
|
+
|
26
|
+
*.rbc
|
27
|
+
*.sassc
|
28
|
+
.sass-cache
|
29
|
+
capybara-*.html
|
30
|
+
/vendor/bundle
|
31
|
+
/public/system/*
|
32
|
+
/coverage/
|
33
|
+
/spec/tmp/*
|
34
|
+
**.orig
|
35
|
+
rerun.txt
|
36
|
+
pickle-email-*.html
|
37
|
+
.DS_Store
|
38
|
+
*.swp
|
39
|
+
|
40
|
+
# Ignore application configuration
|
41
|
+
/config/application.yml
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2015 Jeff McFadden
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# trendable
|
2
|
+
|
3
|
+
Add management for ordering your models by a trending popularity value.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
gem 'trendable'
|
8
|
+
|
9
|
+
$ bundle install
|
10
|
+
|
11
|
+
# Add a migration:
|
12
|
+
$ rails g trendable:migration widget
|
13
|
+
|
14
|
+
# Update your model to include the concern
|
15
|
+
# app/models/widget.rb
|
16
|
+
|
17
|
+
include Trendable::Concern
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Widget.first.boost_trending_power
|
22
|
+
|
23
|
+
Widget.order_by_trending
|
24
|
+
|
25
|
+
20.times{ Widget.first.fade_trending_power }
|
26
|
+
|
27
|
+
Widget.order_by_trending
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Trendable
|
2
|
+
module Concern
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
|
5
|
+
included do
|
6
|
+
scope :order_by_trending, -> { order( trending_power: :desc ) }
|
7
|
+
|
8
|
+
def self.has_trendable_concern?
|
9
|
+
true
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
def boost_trending_power!( add_value = 1000 )
|
15
|
+
self.update_attributes( trending_power: trending_power + add_value )
|
16
|
+
end
|
17
|
+
|
18
|
+
def fade_out_trending_power!( multiplier = 0.9 )
|
19
|
+
self.update_attributes( trending_power: trending_power * multiplier )
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Trendable
|
4
|
+
class MigrationGenerator < ::Rails::Generators::NamedBase
|
5
|
+
desc "Create a migration for the given class name"
|
6
|
+
source_root File.expand_path('../generators', __FILE__)
|
7
|
+
|
8
|
+
def create_migration_file
|
9
|
+
plural_name = file_name.pluralize
|
10
|
+
model_name = file_name
|
11
|
+
|
12
|
+
destination = "db/migrate/#{Time.now.utc.strftime('%Y%m%d%H%M%S')}_trendable_migration_for_#{model_name}.rb".gsub(" ", "")
|
13
|
+
migration_name = "TrendableMigrationFor#{model_name.titlecase}".gsub(" ", "")
|
14
|
+
count = nil
|
15
|
+
i = 1
|
16
|
+
while !Dir.glob("db/migrate/*_trendable_migration_for_#{model_name}#{count}.rb".gsub(" ", "")).empty?
|
17
|
+
i += 1
|
18
|
+
count = "_#{i}"
|
19
|
+
destination = "db/migrate/#{Time.now.utc.strftime('%Y%m%d%H%M%S')}_trendable_migration_for_#{model_name}#{count}.rb".gsub(" ", "")
|
20
|
+
migration_name = "TrendableMigrationFor#{model_name.titlecase}#{i}".gsub(" ", "")
|
21
|
+
end
|
22
|
+
create_file destination, <<-FILE
|
23
|
+
class #{migration_name} < ActiveRecord::Migration
|
24
|
+
def change
|
25
|
+
add_column :#{plural_name}, :trending_power, :integer, default: 1000
|
26
|
+
add_index :#{plural_name}, :trending_power
|
27
|
+
end
|
28
|
+
end
|
29
|
+
FILE
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/trendable.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'concerns/trendable'
|
3
|
+
require 'workers/fade_out_trend_power_worker'
|
4
|
+
require 'trendable/trendable'
|
5
|
+
require 'trendable/engine'
|
6
|
+
require 'trendable/version'
|
7
|
+
|
8
|
+
# ActiveSupport.on_load(:active_record) do
|
9
|
+
# include Trendable::Manager
|
10
|
+
# end
|
11
|
+
|
12
|
+
module Trendable
|
13
|
+
class Manager
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
class FadeOutTrendPowerWorker
|
2
|
+
include Sidekiq::Worker
|
3
|
+
|
4
|
+
def perform( multiplier = 0.9 )
|
5
|
+
Rails.application.eager_load! if Rails.env.development?
|
6
|
+
|
7
|
+
ActiveRecord::Base.descendants.each do |klass|
|
8
|
+
if klass.respond_to?( "has_trendable_concern?".to_sym )
|
9
|
+
klass.all.each do |inst|
|
10
|
+
# TODO: Replace with some kind of update_all
|
11
|
+
inst.fade_out_trending_power!( multiplier )
|
12
|
+
end
|
13
|
+
else
|
14
|
+
puts "#{klass.to_s} does not have trendable concern"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/trendable.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/trendable/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "trendable"
|
6
|
+
s.version = Trendable::Rails::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
|
9
|
+
s.authors = ["Jeff McFadden"]
|
10
|
+
s.date = "2015-08-27"
|
11
|
+
s.description = "Organize your models by a trending popularity value"
|
12
|
+
s.email = "jeff@forgeapps.com"
|
13
|
+
s.extra_rdoc_files = [
|
14
|
+
"LICENSE.txt"
|
15
|
+
]
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
|
18
|
+
s.homepage = "http://github.com/ForgeApps/trendable"
|
19
|
+
s.licenses = ["MIT"]
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
s.rubygems_version = Trendable::Rails::VERSION
|
22
|
+
s.summary = "Organize your models by a trending popularity value"
|
23
|
+
|
24
|
+
s.add_dependency "activesupport", ">= 4.1.0"
|
25
|
+
s.add_dependency "sidekiq"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: trendable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jeff McFadden
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sidekiq
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Organize your models by a trending popularity value
|
42
|
+
email: jeff@forgeapps.com
|
43
|
+
executables: []
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files:
|
46
|
+
- LICENSE.txt
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- lib/concerns/trendable.rb
|
53
|
+
- lib/generators/trendable/migration_generator.rb
|
54
|
+
- lib/trendable.rb
|
55
|
+
- lib/trendable/engine.rb
|
56
|
+
- lib/trendable/trendable.rb
|
57
|
+
- lib/trendable/version.rb
|
58
|
+
- lib/workers/fade_out_trend_power_worker.rb
|
59
|
+
- trendable.gemspec
|
60
|
+
homepage: http://github.com/ForgeApps/trendable
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.5.1
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Organize your models by a trending popularity value
|
84
|
+
test_files: []
|