Skip to content

Commit

Permalink
Drop support for Ruby 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Apr 30, 2024
1 parent 44b3d71 commit 562b8ac
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.0', '3.1', '3.2']
ruby-version: ['3.1', '3.2', '3.3']

steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require:
- rubocop-rspec

AllCops:
TargetRubyVersion: 3.0
TargetRubyVersion: 3.1
NewCops: enable

Layout/AccessModifierIndentation:
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,9 @@ the original code.
This library aims to support and is [tested against][travis] the following Ruby
implementations:

* Ruby 2.4
* Ruby 2.5
* Ruby 2.6
* Ruby 2.7
* Ruby 3.1
* Ruby 3.2
* Ruby 3.3

If something doesn't work on one of these Ruby versions, it's a bug.

Expand Down
3 changes: 1 addition & 2 deletions lib/t/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,6 @@ def open(user)
desc "reach TWEET_ID", "Shows the maximum number of people who may have seen the specified tweet in their timeline."
def reach(tweet_id)
require "t/core_ext/string"
require "set"
status_thread = Thread.new { client.status(tweet_id.to_i, include_my_retweet: false) }
threads = client.retweeters_ids(tweet_id.to_i).collect do |retweeter_id|
Thread.new(retweeter_id) do |user_id|
Expand Down Expand Up @@ -990,7 +989,7 @@ def add_location!(options, opts)
return nil unless options["location"]

lat, lng = options["location"] == "location" ? [location.lat, location.lng] : options["location"].split(",").collect(&:to_f)
opts.merge!(lat: lat, long: lng)
opts.merge!(lat:, long: lng)
end

def location
Expand Down
9 changes: 4 additions & 5 deletions lib/t/collectable.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
require "twitter"
require "retryable"
require "set"

module T
module Collectable
MAX_NUM_RESULTS = 200
MAX_PAGE = 51

def collect_with_max_id(collection = [], max_id = nil, &block)
def collect_with_max_id(collection = [], max_id = nil, &)
tweets = Retryable.retryable(tries: 3, on: Twitter::Error, sleep: 0) do
yield(max_id)
end
return collection if tweets.nil?

collection += tweets
tweets.empty? ? collection.flatten : collect_with_max_id(collection, tweets.last.id - 1, &block)
tweets.empty? ? collection.flatten : collect_with_max_id(collection, tweets.last.id - 1, &)
end

def collect_with_count(count)
Expand All @@ -31,14 +30,14 @@ def collect_with_count(count)
end.flatten.compact
end

def collect_with_page(collection = ::Set.new, page = 1, previous = nil, &block)
def collect_with_page(collection = ::Set.new, page = 1, previous = nil, &)
tweets = Retryable.retryable(tries: 3, on: Twitter::Error, sleep: 0) do
yield page
end
return collection if tweets.nil? || tweets == previous || page >= MAX_PAGE

collection += tweets
tweets.empty? ? collection.flatten : collect_with_page(collection, page + 1, tweets, &block)
tweets.empty? ? collection.flatten : collect_with_page(collection, page + 1, tweets, &)
end
end
end
2 changes: 1 addition & 1 deletion lib/t/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def add(list_name, user, *users)
desc "create LIST [DESCRIPTION]", "Create a new list."
method_option "private", aliases: "-p", type: :boolean
def create(list_name, description = nil)
opts = description ? {description: description} : {}
opts = description ? {description:} : {}
opts[:mode] = "private" if options["private"]
client.create_list(list_name, opts)
say "@#{@rcfile.active_profile[0]} created the list \"#{list_name}\"."
Expand Down
2 changes: 1 addition & 1 deletion lib/t/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def timeline(*args)
method_option "unsorted", aliases: "-u", type: :boolean, desc: "Output is not sorted."
def users(query)
users = collect_with_page do |page|
client.user_search(query, page: page)
client.user_search(query, page:)
end
print_users(users)
end
Expand Down
4 changes: 2 additions & 2 deletions lib/t/set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def active(screen_name, consumer_key = nil)

desc "bio DESCRIPTION", "Edits your Bio information on your Twitter profile."
def bio(description)
client.update_profile(description: description)
client.update_profile(description:)
say "@#{@rcfile.active_profile[0]}'s bio has been updated."
end

Expand All @@ -44,7 +44,7 @@ def location(place_name)

desc "name NAME", "Sets the name field on your Twitter profile."
def name(name)
client.update_profile(name: name)
client.update_profile(name:)
say "@#{@rcfile.active_profile[0]}'s name has been updated."
end

Expand Down
4 changes: 2 additions & 2 deletions lib/t/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ def distance_of_time_in_words(from_time, to_time = Time.now) # rubocop:disable M
when 1...2
"a second"
when 2...60
format("%<seconds>d seconds", seconds: seconds)
format("%<seconds>d seconds", seconds:)
end
when 1...2
"a minute"
when 2...60
format("%<minutes>d minutes", minutes: minutes)
format("%<minutes>d minutes", minutes:)
when 60...120
"an hour"
# 120 minutes up to 23.5 hours
Expand Down
4 changes: 2 additions & 2 deletions spec/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3440,7 +3440,7 @@
stub_get("/1.1/statuses/retweets_of_me.json").with(query: {count: "1", include_entities: "false"}).to_return(body: fixture("statuses.json"), headers: {content_type: "application/json; charset=utf-8"})
stub_get("/1.1/statuses/retweets_of_me.json").with(query: {count: "200", include_entities: "false"}).to_return(body: fixture("statuses.json"), headers: {content_type: "application/json; charset=utf-8"})
(1..181).step(20) do |count|
stub_get("/1.1/statuses/retweets_of_me.json").with(query: {count: count, max_id: "244099460672679937", include_entities: "false"}).to_return(body: fixture("statuses.json"), headers: {content_type: "application/json; charset=utf-8"})
stub_get("/1.1/statuses/retweets_of_me.json").with(query: {count:, max_id: "244099460672679937", include_entities: "false"}).to_return(body: fixture("statuses.json"), headers: {content_type: "application/json; charset=utf-8"})
end
end

Expand All @@ -3455,7 +3455,7 @@
@cli.retweets_of_me
expect(a_get("/1.1/statuses/retweets_of_me.json").with(query: {count: "200", include_entities: "false"})).to have_been_made
(1..181).step(20) do |count|
expect(a_get("/1.1/statuses/retweets_of_me.json").with(query: {count: count, max_id: "244099460672679937", include_entities: "false"})).to have_been_made
expect(a_get("/1.1/statuses/retweets_of_me.json").with(query: {count:, max_id: "244099460672679937", include_entities: "false"})).to have_been_made
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion t.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
spec.metadata["rubygems_mfa_required"] = "true"
spec.name = "t"
spec.require_paths = %w[lib]
spec.required_ruby_version = ">= 3.0"
spec.required_ruby_version = ">= 3.1.4"
spec.summary = "CLI for Twitter"
spec.version = T::Version
end

0 comments on commit 562b8ac

Please sign in to comment.