Sha256: 34cc35e4d50379c5947a5d58406c8b0398c9e847e2b959199452959d3ed8f74d

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

require 'generators/happy_seed/omniauth/omniauth_generator'

module HappySeed
  module Generators
    class TwitterGenerator < HappySeedGenerator
      include Rails::Generators::Migration

      source_root File.expand_path('../templates', __FILE__)

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

      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"
        insert_into_file "app/models/identity.rb", "\n    identity.secrettoken = auth.credentials.secret", after: "identity.accesstoken = auth.credentials.token"
        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

      protected

      def self.next_migration_number(dir)
        Time.now.utc.strftime("%Y%m%d%H%M%S")
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
happy_seed-0.0.19 lib/generators/happy_seed/twitter/twitter_generator.rb
happy_seed-0.0.18 lib/generators/happy_seed/twitter/twitter_generator.rb
happy_seed-0.0.17 lib/generators/happy_seed/twitter/twitter_generator.rb