Skip to content

Commit

Permalink
Create rails generator for initial config.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunny Juneja committed Jan 12, 2015
1 parent d422d26 commit b060865
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,21 @@ When upgrading from a previous version, see [UPGRADING](UPGRADING.md). You might
## Usage
WineBouncer is a custom Grape Middleware used for Authentication and Authorization. We assume you have a Grape API mounted in your Rails application together with Doorkeeper.

To get started with WineBouncer, create a rails initializer in your Rails app at `config/initializers/wine_bouncer.rb` with the following configuration.
To get started with WineBouncer, run the configuration initializer:

```shell
$ rails g wine_bouncer:initializer
```

This creates a rails initializer in your Rails app at `config/initializers/wine_bouncer.rb` with the following configuration:

``` ruby
WineBouncer.configure do |config|
config.auth_strategy = :default
config.auth_strategy = :default

config.define_resource_owner do
User.find(doorkeeper_access_token.resource_owner_id) if doorkeeper_access_token
end
config.define_resource_owner do
User.find(doorkeeper_access_token.resource_owner_id) if doorkeeper_access_token
end
end
```

Expand Down
7 changes: 7 additions & 0 deletions lib/generators/templates/wine_bouncer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
WineBouncer.configure do |config|
config.auth_strategy = :default

config.define_resource_owner do
User.find(doorkeeper_access_token.resource_owner_id) if doorkeeper_access_token
end
end
12 changes: 12 additions & 0 deletions lib/generators/wine_bouncer/initializer_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module WineBouncer
module Generators
class InitializerGenerator < ::Rails::Generators::Base
source_root File.expand_path('../../templates', __FILE__)

desc 'Creates a sample WineBouncer initializer.'
def copy_initializer
copy_file 'wine_bouncer.rb', 'config/initializers/wine_bouncer.rb'
end
end
end
end
18 changes: 18 additions & 0 deletions spec/lib/generators/wine_bouncer/initializer_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'generator_spec'
require 'rails_helper'
require 'spec_helper'
require 'generators/wine_bouncer/initializer_generator'

describe WineBouncer::Generators::InitializerGenerator, type: :generator do
destination '/tmp'

before do
prepare_destination
run_generator
end

it 'creates a test initializer' do
assert_file 'config/initializers/wine_bouncer.rb', /WineBouncer\.configure/
end
end

2 changes: 1 addition & 1 deletion wine_bouncer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec-rails", "~> 3.1.0"
spec.add_development_dependency 'factory_girl', '~> 4.4.0'
spec.add_development_dependency "generator_spec", "~> 0.9.0"
spec.add_development_dependency "sqlite3"
spec.add_development_dependency "database_cleaner", "~> 1.3.0"

end

0 comments on commit b060865

Please sign in to comment.