Class: HappySeed::Generators::TwitterGenerator

Inherits:
HappySeedGenerator
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/happy_seed/twitter/twitter_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fingerprintObject



10
11
12
# File 'lib/generators/happy_seed/twitter/twitter_generator.rb', line 10

def self.fingerprint
  gem_available?( 'omniauth-twitter' )
end

Instance Method Details

#install_twitterObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/generators/happy_seed/twitter/twitter_generator.rb', line 14

def install_twitter
  return if already_installed

  require_generator OmniauthGenerator

  gem 'omniauth-twitter'
  gem 'twitter'

  Bundler.with_clean_env do
    run "bundle install --without production"
  end

  add_omniauth :twitter

  directory "docs"
  directory "spec"
  insert_into_file "app/models/identity.rb", "      identity.secrettoken = auth.credentials.secret\n", after: "identity.accesstoken = auth.credentials.token\n"
  migration_template("add_secret_token_to_identity.rb", "db/migrate/add_secret_token_to_identity.rb" )

  gsub_file( "app/models/user.rb", "Twitter.client( access_token: twitter.accesstoken )",
    "Twitter::REST::Client.new do |config|
config.consumer_key        = ENV['TWITTER_APP_ID']
config.consumer_secret     = ENV['TWITTER_APP_SECRET']
config.access_token        = twitter.accesstoken
config.access_token_secret = twitter.secrettoken
    end")
end