Module: Turl

Defined in:
lib/turl.rb,
lib/turl/web.rb,
lib/turl/link.rb,
lib/turl/tweet.rb,
lib/turl/collect.rb,
lib/turl/version.rb,
lib/turl/normalizer.rb,
lib/turl/tweet_link.rb,
lib/turl/twitter_user.rb,
lib/turl/url_normalization.rb,
lib/turl/application_record.rb

Defined Under Namespace

Modules: Normalizer Classes: ApplicationRecord, Collect, Link, Tweet, TweetLink, TwitterUser, UrlNormalization, Web

Constant Summary collapse

CACHE_PATH =
Pathname('~/.cache/turl').expand_path
DATABASE_PATH =
CACHE_PATH / 'db.sqlite3'
VERSION =
"0.2.1"

Class Method Summary collapse

Class Method Details

.loggerObject



93
94
95
# File 'lib/turl.rb', line 93

def self.logger
  @logger ||= Logger.new(STDOUT)
end

.prepare_database!Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/turl.rb', line 23

def self.prepare_database!
  CACHE_PATH.mkpath
  ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: DATABASE_PATH.to_s)
  unless DATABASE_PATH.exist?
    <<~SQL.split(';').select(&:present?).each { |sql| ActiveRecord::Base.connection.execute(sql) }
      create table links (
        id integer primary key,

        normalized_url text not null,
        title text,

        created_at datetime not null,
        updated_at datetime not null
      );

      create unique index uniq_links_url_tweet on links(normalized_url);

      create table tweets (
        id integer primary key,
        twitter_id text not null,

        twitter_user_id integer not null,
        content text not null,
        tweeted_at datetime not null,

        created_at datetime not null,
        updated_at datetime not null
      );

      create unique index uniq_tweets_twitter_id on tweets(twitter_id);

      create table tweet_links (
        id integer primary key,

        tweet_id integer not null,
        link_id integer not null,

        created_at datetime not null,
        updated_at datetime not null
      );

      create unique index uniq_tweet_links_tweet_link on tweet_links(tweet_id, link_id);

      create table twitter_users (
        id integer primary key,
        twitter_id text not null,

        screen_name text not null,

        created_at datetime not null,
        updated_at datetime not null
      );

      create unique index uniq_twitter_users_twitter_id on twitter_users(twitter_id);

      create table url_normalizations (
        id integer primary key,

        original_url text not null,
        normalized_url text not null,

        created_at datetime not null,
        updated_at datetime not null
      );

      create unique index uniq_url_normalizations_original_url on url_normalizations(original_url);
    SQL
  end
end