Permalink
Browse files

[#211] Update top-level namespace to Twitter::TwitterText::

The popular Twitter gem (https://github.com/sferik/twitter) uses the
Twitter::Configuration namespace and users are reporting that our new
Twitter::Configuration class is conflicting with that namespace.

This patch changes our top-level namespace from Twitter to
Twitter::TwitterText:: to resolve this conflict and prevent further
conflicts in the future. Because this is a breaking change for clients
written against older versions of the library, the version has been
bumped to 2.1.

There's also a new CHANGELOG.md file that details important changes in
this revision and will be updated going forward.
  • Loading branch information...
dlamacchia committed Dec 21, 2017
1 parent 36e245b commit d0d802dc6101248040f7649971b454bb757486e5
View
@@ -0,0 +1,25 @@
# Changelog
All notable changes to this project will be documented in this file.
## [Unreleased]
## [2.1] - 2017-12-20
### Added
- This CHANGELOG.md file
### Changed
- Top-level namespace changed from `Twitter` to `Twitter::TwitterText`. This
resolves a namespace collision with the popular
[twitter gem](https://github.com/sferik/twitter). This is considered
a breaking change, so the version has been bumped to 2.1. This fixes
issue [#221](https://github.com/twitter/twitter-text/issues/221),
"NoMethodError Exception: undefined method `[]' for nil:NilClasswhen
using gem in rails app"
## [2.0.2] - 2017-12-18
### Changed
- Resolved issue
[#211](https://github.com/twitter/twitter-text/issues/211), "gem
breaks, asset file is a dangling symlink"
- config files, tld_lib.yml files now copied into the right place
- Rakefile now included `prebuild`, `clean` tasks
View
@@ -50,7 +50,7 @@ def parse_tweet(text, options = {}) { ... }
This method takes a string as input and returns a results object that
contains information about the
string. `Twitter::Validation::ParseResults` object includes:
string. `Twitter::TwitterText::Validation::ParseResults` object includes:
* `:weighted_length`: the overall length of the tweet with code points
weighted per the ranges defined in the configuration file.
@@ -78,7 +78,7 @@ payload see [Tweet updates](https://developer.twitter.com/en/docs/tweets/tweet-u
# Extraction
```ruby
class MyClass
include Twitter::Extractor
include Twitter::TwitterText::Extractor
usernames = extract_mentioned_screen_names("Mentioning @twitter and @jack")
# usernames = ["twitter", "jack"]
end
@@ -88,7 +88,7 @@ end
```ruby
class MyClass
include Twitter::Extractor
include Twitter::TwitterText::Extractor
extract_reply_screen_name("@twitter are you hiring?").do |username|
# username = "twitter"
end
@@ -101,7 +101,7 @@ end
```ruby
class MyClass
include Twitter::Autolink
include Twitter::TwitterText::Autolink
html = auto_link("link @user, please #request")
end
@@ -110,7 +110,7 @@ end
### For Ruby on Rails you want to add this to app/helpers/application_helper.rb
```ruby
module ApplicationHelper
include Twitter::Autolink
include Twitter::TwitterText::Autolink
end
```

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,53 +1,54 @@
# encoding: UTF-8
module Twitter
class Configuration
require 'json'
PARSER_VERSION_CLASSIC = "v1"
PARSER_VERSION_DEFAULT = "v2"
class << self
attr_accessor :default_configuration
end
attr_reader :version, :max_weighted_tweet_length, :scale
attr_reader :default_weight, :transformed_url_length, :ranges
CONFIG_V1 = File.join(
File.expand_path('../../../config', __FILE__), # project root
"#{PARSER_VERSION_CLASSIC}.json"
)
CONFIG_V2 = File.join(
File.expand_path('../../../config', __FILE__), # project root
"#{PARSER_VERSION_DEFAULT}.json"
)
def self.parse_string(string, options = {})
JSON.parse(string, options.merge(symbolize_names: true))
module TwitterText
class Configuration
require 'json'
PARSER_VERSION_CLASSIC = "v1"
PARSER_VERSION_DEFAULT = "v2"
class << self
attr_accessor :default_configuration
end
attr_reader :version, :max_weighted_tweet_length, :scale
attr_reader :default_weight, :transformed_url_length, :ranges
CONFIG_V1 = File.join(
File.expand_path('../../../config', __FILE__), # project root
"#{PARSER_VERSION_CLASSIC}.json"
)
CONFIG_V2 = File.join(
File.expand_path('../../../config', __FILE__), # project root
"#{PARSER_VERSION_DEFAULT}.json"
)
def self.parse_string(string, options = {})
JSON.parse(string, options.merge(symbolize_names: true))
end
def self.parse_file(filename)
string = File.open(filename, 'rb') { |f| f.read }
parse_string(string)
end
def self.configuration_from_file(filename)
config = parse_file(filename)
config ? self.new(config) : nil
end
def initialize(config = {})
@version = config[:version]
@max_weighted_tweet_length = config[:maxWeightedTweetLength]
@scale = config[:scale]
@default_weight = config[:defaultWeight]
@transformed_url_length = config[:transformedURLLength]
@ranges = config[:ranges].map { |range| Twitter::TwitterText::WeightedRange.new(range) } if config.key?(:ranges) && config[:ranges].is_a?(Array)
end
self.default_configuration = self.configuration_from_file(CONFIG_V2)
end
def self.parse_file(filename)
string = File.open(filename, 'rb') { |f| f.read }
parse_string(string)
end
def self.configuration_from_file(filename)
config = parse_file(filename)
config ? Twitter::Configuration.new(config) : nil
end
def initialize(config = {})
@version = config[:version]
@max_weighted_tweet_length = config[:maxWeightedTweetLength]
@scale = config[:scale]
@default_weight = config[:defaultWeight]
@transformed_url_length = config[:transformedURLLength]
@ranges = config[:ranges].map { |range| Twitter::WeightedRange.new(range) } if config.key?(:ranges) && config[:ranges].is_a?(Array)
end
self.default_configuration = Twitter::Configuration.configuration_from_file(Twitter::Configuration::CONFIG_V2)
end
end
@@ -1,14 +1,16 @@
module Twitter
module Deprecation
def deprecate(method, new_method = nil)
deprecated_method = :"deprecated_#{method}"
message = "Deprecation: `#{method}` is deprecated."
message << " Please use `#{new_method}` instead." if new_method
module TwitterText
module Deprecation
def deprecate(method, new_method = nil)
deprecated_method = :"deprecated_#{method}"
message = "Deprecation: `#{method}` is deprecated."
message << " Please use `#{new_method}` instead." if new_method
alias_method(deprecated_method, method)
define_method method do |*args, &block|
warn message unless $TESTING
send(deprecated_method, *args, &block)
alias_method(deprecated_method, method)
define_method method do |*args, &block|
warn message unless $TESTING
send(deprecated_method, *args, &block)
end
end
end
end
Oops, something went wrong.

0 comments on commit d0d802d

Please sign in to comment.