Skip to content
This repository has been archived by the owner on Jun 26, 2019. It is now read-only.

PrintReleaf/treehouse-rails

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

treehouse-rails

treehouse-rails is a Rails engine with middleware for Treehouse authentication

Installation

Add this line to your application's Gemfile:

$ gem 'treehouse-rails', git: '[email protected]:printreleaf/treehouse-rails'

And then execute:

$ bundle

Configuration

Create config/initializers/treehouse.rb:

Treehouse.configure do |config|
  config.url    = "http://yourtreehouse.com"
  config.key    = "your-treehouse-key"
  config.cookie = "_treehouse_session"
end

Usage

Treehouse adds its session to the Rack environment hash so Rails and other Rack applications can interact with it:

session = request.env[:treehouse] #=> #<Treehouse::Session:0x007f8610411a48>
session.logged_in? #=> true
login = session.current_login #=> #<Treehouse::Login:0x007f860efc3208>
login.id #=> 123
login.email #=> "[email protected]"

Dummy mode

When Treehouse is in dummy mode, #current_login will always return a dummy instance of Treehouse::Login:

Treehouse.configure do |config|
  config.dummy = true
end

request.env[:treehouse].current_login #=> #<Treehouse::Login:0x007f860efc3208 @id=123, @email="[email protected]">

It can be helpful to enable dummy mode in development:

Treehouse.configure do |config|
  config.dummy = Rails.env.development?
end

Testing

$ rspec spec

Contributing

  1. Fork it ( https://github.com/printreleaf/treehouse-rails/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

License

MIT

Releases

No releases published

Packages

 
 
 

Languages