Fixes for Ruby 2.4 support

This commit is contained in:
Kyle Drake 2017-03-22 11:39:06 -07:00
parent d03df1c490
commit 9f73ec61bd
7 changed files with 232 additions and 88 deletions

48
Gemfile
View file

@ -3,7 +3,7 @@ source 'https://rubygems.org'
gem 'sinatra' gem 'sinatra'
gem 'redis' gem 'redis'
gem 'redis-namespace' gem 'redis-namespace'
gem 'sequel', '4.8.0' gem 'sequel'
gem 'bcrypt' gem 'bcrypt'
gem 'sinatra-flash', require: 'sinatra/flash' gem 'sinatra-flash', require: 'sinatra/flash'
gem 'sinatra-xsendfile', require: 'sinatra/xsendfile' gem 'sinatra-xsendfile', require: 'sinatra/xsendfile'
@ -11,12 +11,10 @@ gem 'puma', require: nil
gem 'rack-recaptcha', require: 'rack/recaptcha' gem 'rack-recaptcha', require: 'rack/recaptcha'
gem 'rmagick', require: nil gem 'rmagick', require: nil
gem 'sidekiq', '~> 4.1.2' gem 'sidekiq', '~> 4.1.2'
gem 'ago'
gem 'mail' gem 'mail'
gem 'tilt' gem 'tilt'
gem 'erubis' gem 'erubis'
gem 'stripe', '1.15.0' #, source: 'https://code.stripe.com/' gem 'stripe', '1.15.0' #, source: 'https://code.stripe.com/'
#gem 'screencap', '~> 0.1.4'
gem 'cocaine' gem 'cocaine'
gem 'zipruby' gem 'zipruby'
gem 'sass', require: nil gem 'sass', require: nil
@ -48,33 +46,16 @@ gem 'image_optim_pack'
gem 'ipaddress' gem 'ipaddress'
gem 'feedjira' gem 'feedjira'
gem 'monetize' gem 'monetize'
gem 'xmlrpc'
gem 'magic'
gem 'pg'
gem 'sequel_pg', require: nil
gem 'hiredis'
gem 'activesupport'
platform :mri, :rbx do group :development, :test do
gem 'magic' # sudo apt-get install file, For OSX: brew install libmagic gem 'pry'
gem 'pg' gem 'pry-byebug'
gem 'sequel_pg', require: nil
gem 'hiredis'
gem 'posix-spawn'
group :development, :test do
gem 'pry'
end
end
platform :mri do
group :development, :test do
gem 'pry-byebug', platform: 'mri'
end
end
platform :jruby do
gem 'jruby-openssl'
gem 'json'
gem 'jdbc-postgres'
group :development do
gem 'ruby-debug', require: nil
end
end end
group :development do group :development do
@ -92,15 +73,12 @@ group :test do
gem 'rake', require: nil gem 'rake', require: nil
gem 'poltergeist' gem 'poltergeist'
gem 'capybara_minitest_spec' gem 'capybara_minitest_spec'
gem 'capybara', '2.10.1', require: nil gem 'capybara', require: nil #, '2.10.1', require: nil
gem 'rack_session_access', require: nil gem 'rack_session_access', require: nil
gem 'webmock', require: nil gem 'webmock', require: nil
gem 'stripe-ruby-mock', '2.0.1', require: 'stripe_mock' gem 'stripe-ruby-mock', '2.0.1', require: 'stripe_mock'
gem 'timecop' gem 'timecop'
gem 'mock_redis' gem 'mock_redis'
gem 'simplecov', require: nil
platform :mri, :rbx do gem 'm'
gem 'simplecov', require: nil
gem 'm'
end
end end

View file

@ -14,24 +14,22 @@ GEM
specs: specs:
acme-client (0.4.0) acme-client (0.4.0)
faraday (~> 0.9, >= 0.9.1) faraday (~> 0.9, >= 0.9.1)
activesupport (4.2.6) activesupport (5.0.2)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (~> 0.7) i18n (~> 0.7)
json (~> 1.7, >= 1.7.7)
minitest (~> 5.1) minitest (~> 5.1)
thread_safe (~> 0.3, >= 0.3.4)
tzinfo (~> 1.1) tzinfo (~> 1.1)
addressable (2.5.0) addressable (2.5.0)
public_suffix (~> 2.0, >= 2.0.2) public_suffix (~> 2.0, >= 2.0.2)
ago (0.1.5)
annoy (0.5.6) annoy (0.5.6)
highline (>= 1.5.0) highline (>= 1.5.0)
ansi (1.5.0) ansi (1.5.0)
base32 (0.3.2) base32 (0.3.2)
bcrypt (3.1.11) bcrypt (3.1.11)
blankslate (3.1.3) blankslate (3.1.3)
builder (3.2.2) builder (3.2.3)
byebug (8.2.4) byebug (8.2.4)
capybara (2.10.1) capybara (2.13.0)
addressable addressable
mime-types (>= 1.16) mime-types (>= 1.16)
nokogiri (>= 1.3.3) nokogiri (>= 1.3.3)
@ -48,14 +46,14 @@ GEM
cocaine (0.5.8) cocaine (0.5.8)
climate_control (>= 0.0.3, < 1.0) climate_control (>= 0.0.3, < 1.0)
coderay (1.1.1) coderay (1.1.1)
concurrent-ruby (1.0.2) concurrent-ruby (1.0.5)
connection_pool (2.2.0) connection_pool (2.2.0)
coveralls (0.8.13) coveralls (0.8.19)
json (~> 1.8) json (>= 1.8, < 3)
simplecov (~> 0.11.0) simplecov (~> 0.12.0)
term-ansicolor (~> 1.3) term-ansicolor (~> 1.3)
thor (~> 0.19.1) thor (~> 0.19.1)
tins (~> 1.6.0) tins (~> 1.6)
crack (0.4.3) crack (0.4.3)
safe_yaml (~> 1.0.0) safe_yaml (~> 1.0.0)
crass (1.0.2) crass (1.0.2)
@ -83,12 +81,12 @@ GEM
ffi (>= 1.0.0) ffi (>= 1.0.0)
rake rake
filesize (0.1.1) filesize (0.1.1)
fspath (3.0.1) fspath (3.0.3)
gandi (2.1.3) gandi (3.3.27)
hashie hashie
geoip (1.6.1) geoip (1.6.1)
hashdiff (0.3.0) hashdiff (0.3.2)
hashie (3.4.3) hashie (3.5.5)
highline (1.7.8) highline (1.7.8)
hiredis (0.6.1) hiredis (0.6.1)
hoe (3.14.2) hoe (3.14.2)
@ -122,7 +120,7 @@ GEM
multi_json (~> 1.0) multi_json (~> 1.0)
rack (~> 1.4) rack (~> 1.4)
rest-client (~> 1.0) rest-client (~> 1.0)
json (1.8.3) json (1.8.6)
loofah (2.0.3) loofah (2.0.3)
nokogiri (>= 1.5.9) nokogiri (>= 1.5.9)
m (1.4.2) m (1.4.2)
@ -136,7 +134,7 @@ GEM
method_source (0.8.2) method_source (0.8.2)
mime-types (2.99.3) mime-types (2.99.3)
mini_portile2 (2.1.0) mini_portile2 (2.1.0)
minitest (5.8.4) minitest (5.10.1)
minitest-reporters (1.1.8) minitest-reporters (1.1.8)
ansi ansi
builder builder
@ -150,25 +148,24 @@ GEM
money (6.8.1) money (6.8.1)
i18n (>= 0.6.4, <= 0.7.0) i18n (>= 0.6.4, <= 0.7.0)
sixarm_ruby_unaccent (>= 1.1.1, < 2) sixarm_ruby_unaccent (>= 1.1.1, < 2)
msgpack (0.7.5) msgpack (1.1.0)
multi_json (1.12.1) multi_json (1.12.1)
multipart-post (2.0.0) multipart-post (2.0.0)
net-scp (1.2.1) net-scp (1.2.1)
net-ssh (>= 2.6.5) net-ssh (>= 2.6.5)
net-ssh (3.1.1) net-ssh (3.1.1)
netrc (0.11.0) netrc (0.11.0)
nokogiri (1.6.8.1) nokogiri (1.7.0.1)
mini_portile2 (~> 2.1.0) mini_portile2 (~> 2.1.0)
nokogumbo (1.4.7) nokogumbo (1.4.7)
nokogiri nokogiri
ox (2.4.6) ox (2.4.6)
paypal-recurring (1.1.0) paypal-recurring (1.1.0)
pg (0.18.4) pg (0.20.0)
poltergeist (1.11.0) poltergeist (1.11.0)
capybara (~> 2.1) capybara (~> 2.1)
cliver (~> 0.3.1) cliver (~> 0.3.1)
websocket-driver (>= 0.2.0) websocket-driver (>= 0.2.0)
posix-spawn (0.3.11)
progress (3.2.2) progress (3.2.2)
pry (0.10.3) pry (0.10.3)
coderay (~> 1.1.0) coderay (~> 1.1.0)
@ -177,7 +174,7 @@ GEM
pry-byebug (3.3.0) pry-byebug (3.3.0)
byebug (~> 8.0) byebug (~> 8.0)
pry (~> 0.10) pry (~> 0.10)
public_suffix (2.0.4) public_suffix (2.0.5)
puma (3.4.0) puma (3.4.0)
rack (1.6.5) rack (1.6.5)
rack-cache (1.6.1) rack-cache (1.6.1)
@ -192,7 +189,7 @@ GEM
builder (>= 2.0.0) builder (>= 2.0.0)
rack (>= 1.0.0) rack (>= 1.0.0)
rake (10.5.0) rake (10.5.0)
redis (3.2.2) redis (3.3.3)
redis-namespace (1.5.2) redis-namespace (1.5.2)
redis (~> 3.0, >= 3.0.4) redis (~> 3.0, >= 3.0.4)
rest-client (1.8.0) rest-client (1.8.0)
@ -219,8 +216,8 @@ GEM
scrypt (2.1.1) scrypt (2.1.1)
ffi-compiler (>= 0.0.2) ffi-compiler (>= 0.0.2)
rake rake
sequel (4.8.0) sequel (4.44.0)
sequel_pg (1.6.16) sequel_pg (1.6.17)
pg (>= 0.8.0) pg (>= 0.8.0)
sequel (>= 4.0.0) sequel (>= 4.0.0)
shotgun (0.9.1) shotgun (0.9.1)
@ -229,13 +226,13 @@ GEM
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
connection_pool (~> 2.2, >= 2.2.0) connection_pool (~> 2.2, >= 2.2.0)
redis (~> 3.2, >= 3.2.1) redis (~> 3.2, >= 3.2.1)
simplecov (0.11.2) simplecov (0.12.0)
docile (~> 1.1.0) docile (~> 1.1.0)
json (~> 1.8) json (>= 1.8, < 3)
simplecov-html (~> 0.10.0) simplecov-html (~> 0.10.0)
simplecov-html (0.10.0) simplecov-html (0.10.0)
simpleidn (0.0.6) simpleidn (0.0.6)
sinatra (1.4.7) sinatra (1.4.8)
rack (~> 1.5) rack (~> 1.5)
rack-protection (~> 1.4) rack-protection (~> 1.4)
tilt (>= 1.3, < 3) tilt (>= 1.3, < 3)
@ -257,21 +254,21 @@ GEM
sysinfo (0.8.1) sysinfo (0.8.1)
drydock drydock
storable storable
term-ansicolor (1.3.2) term-ansicolor (1.4.0)
tins (~> 1.0) tins (~> 1.0)
thor (0.19.1) thor (0.19.4)
thread (0.2.2) thread (0.2.2)
thread_safe (0.3.5) thread_safe (0.3.6)
tilt (2.0.2) tilt (2.0.6)
timecop (0.8.1) timecop (0.8.1)
tins (1.6.0) tins (1.13.2)
tzinfo (1.2.2) tzinfo (1.2.2)
thread_safe (~> 0.1) thread_safe (~> 0.1)
unf (0.1.4) unf (0.1.4)
unf_ext unf_ext
unf_ext (0.0.7.2) unf_ext (0.0.7.2)
uuidtools (2.1.5) uuidtools (2.1.5)
webmock (2.1.0) webmock (2.3.2)
addressable (>= 2.3.6) addressable (>= 2.3.6)
crack (>= 0.3.2) crack (>= 0.3.2)
hashdiff hashdiff
@ -279,6 +276,7 @@ GEM
websocket-extensions (>= 0.1.0) websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.2) websocket-extensions (0.1.2)
will_paginate (3.1.0) will_paginate (3.1.0)
xmlrpc (0.3.0)
xpath (2.0.0) xpath (2.0.0)
nokogiri (~> 1.3) nokogiri (~> 1.3)
zipruby (0.3.6) zipruby (0.3.6)
@ -288,11 +286,11 @@ PLATFORMS
DEPENDENCIES DEPENDENCIES
acme-client acme-client
activesupport
addressable addressable
ago
base32 base32
bcrypt bcrypt
capybara (= 2.10.1) capybara
capybara_minitest_spec capybara_minitest_spec
certified certified
cocaine cocaine
@ -313,9 +311,6 @@ DEPENDENCIES
image_optim_pack image_optim_pack
io-extra io-extra
ipaddress ipaddress
jdbc-postgres
jruby-openssl
json
m m
magic magic
mail mail
@ -328,7 +323,6 @@ DEPENDENCIES
paypal-recurring paypal-recurring
pg pg
poltergeist poltergeist
posix-spawn
pry pry
pry-byebug pry-byebug
puma puma
@ -342,12 +336,11 @@ DEPENDENCIES
rest-client rest-client
rinku rinku
rmagick rmagick
ruby-debug
rye rye
sanitize sanitize
sass sass
scrypt scrypt
sequel (= 4.8.0) sequel
sequel_pg sequel_pg
shotgun shotgun
sidekiq (~> 4.1.2) sidekiq (~> 4.1.2)
@ -363,7 +356,8 @@ DEPENDENCIES
timecop timecop
webmock webmock
will_paginate will_paginate
xmlrpc
zipruby zipruby
BUNDLED WITH BUNDLED WITH
1.13.7 1.14.6

View file

@ -12,6 +12,7 @@ Bundler.require
Bundler.require :development if ENV['RACK_ENV'] == 'development' Bundler.require :development if ENV['RACK_ENV'] == 'development'
require 'tilt/erubis' require 'tilt/erubis'
require 'active_support/core_ext/integer/time'
Dir['./ext/**/*.rb'].each {|f| require f} Dir['./ext/**/*.rb'].each {|f| require f}

169
ext/ago.rb Normal file
View file

@ -0,0 +1,169 @@
module Ago
module VERSION
MAJOR = 0
MINOR = 1
TINY = 5
class << self
def pretty
"#{MAJOR}.#{MINOR}.#{TINY}"
end
alias_method :print, :pretty
end
end
Ago::Order = [:year, :month, :week, :day, :hour, :minute, :second]
Ago::Units = {
:year => {
:basic => 60 * 60 * 24 * 365,
:gregorian => 86400 * 365.2425,
},
:month => {
:basic => 60 * 60 * 24 * 30,
:gregorian => 86400 * 30.436875,
},
:week => {
:basic => 60 * 60 * 24 * 7,
:gregorian => 86400 * 7.02389423076923,
},
:day => {
:basic => 60 * 60 * 24
},
:hour => {
:basic => 60 * 60
},
:minute => {
:basic => 60
},
:second => {
:basic => 1
}
}
def Ago.calendar_check(calendar)
error = ":calendar => value must be either :basic or :gregorian."
unless calendar == :basic || calendar == :gregorian
raise ArgumentError, error
end
end
module Ago::TimeAgo
# Generate List of valid unit :symbols
valids = ""
Ago::Order.each do |u|
unless u == :second
valids += ":#{u.to_s}, "
else
valids += "and :#{u.to_s}."
end
end
Valids = valids
def ago_in_words(opts={})
# Process options {hash}
focus = opts[:focus] ? opts[:focus] : 0
start_at = opts[:start_at] ? opts[:start_at] : :year
now = opts[:now] ? opts[:now] : Time.now
in_time = opts[:in_time] ? opts[:in_time] : :past
calendar = opts[:calendar] ? opts[:calendar] : :basic
# Filter out invalid arguments for :in_time
in_time_error = ":in_time => value must be either :past or :future, " \
+ "depending on whether the Time object is before or after Time.now."
unless in_time == :past || in_time == :future
raise ArgumentError, in_time_error
end
# Filter out invalid arguments for :calendar
Ago.calendar_check(calendar)
# Filter out invalid arguments for :start_at and :focus
base_error = " => value must either be a number " +
"between 0 and 6 (inclusive),\nor one of the following " +
"symbols: " + Valids
{:focus => focus, :start_at => start_at}.each do |key, opt|
opt_error = ":" + key.to_s + base_error
if opt.class == Integer
raise ArgumentError, opt_error unless opt >= 0 && opt <= 6
elsif opt.class == Symbol
raise ArgumentError, opt_error unless Ago::Units[opt]
else
raise ArgumentError, opt_error
end
end
# Create Variables necessary for processing.
frags = []
output = ""
count = 0
now = calendar == :basic ? now.to_i : now.to_f
my_time = calendar == :basic ? self.to_i : self.to_f
if now > my_time
diff = now - my_time
tail = " ago"
elsif my_time > now
diff = my_time - now
tail = " from now"
else
diff = 0
tail = "just now"
end
# Begin Ago.ago processing
Ago::Order.each do |u|
if calendar == :gregorian && Ago::Units[u][:gregorian]
value = Ago::Units[u][:gregorian]
else
value = Ago::Units[u][:basic]
end
count += 1
# Move further ahead in the Ago::Units array if start_at is farther back than
# the current point in the array.
if start_at.class == Integer
next if count <= start_at
elsif start_at.class == Symbol
next if Ago::Order.index(u) < Ago::Order.index(start_at)
end
n = (diff/value).floor
if n > 0
plural = n > 1 ? "s" : ""
frags << "#{n} #{u.to_s + plural}"
# If the argument passed into ago() is a symbol, focus the ago statement
# down to the level specified in the symbol
if focus.class == Symbol
break if u == focus || u == :second
elsif focus.class == Fixnum
if focus == 0 || u == :second
break
else
focus -= 1
end
end
diff -= n * value
end
end
# Der Kommissar
frags.size.times do |n|
output += frags[n]
output += ", " unless n == frags.size - 1
end
return output + "#{tail}"
end
def from_now_in_words(opts={})
ago_in_words(opts)
end
end
end
class Time
include Ago::TimeAgo
end

View file

@ -1,7 +1,9 @@
class Time class Time
alias_method :ago_original, :ago
def ago def ago
ago_original.downcase.gsub('right now, this very moment.', 'just now') self.ago_in_words
end end
end
def from_now
self.from_now_in_words
end
end

View file

@ -1,8 +1,8 @@
Sequel.migration do Sequel.migration do
up { up {
alter_table(:stats) do alter_table(:stats) do
set_column_type :hits, Bignum set_column_type :hits, :bigint
set_column_type :views, Bignum set_column_type :views, :bigint
end end
} }

View file

@ -1,10 +1,10 @@
Sequel.migration do Sequel.migration do
up { up {
alter_table(:daily_site_stats) do alter_table(:daily_site_stats) do
set_column_type :hits, Bignum set_column_type :hits, :bigint
set_column_type :views, Bignum set_column_type :views, :bigint
set_column_type :bandwidth, Bignum set_column_type :bandwidth, :bigint
set_column_type :site_updates, Bignum set_column_type :site_updates, :bigint
end end
} }