Skip to content

Commit

Permalink
Merge pull request #1 from beerlington/generators
Browse files Browse the repository at this point in the history
Adds generator for Filterer classes and tests
  • Loading branch information
ajb committed Nov 17, 2013
2 parents abdcccf + 05f2b1e commit d3ca7eb
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 1 deletion.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ Another answer could be in your models. But passing a bunch of query parameters

First, add `gem 'filterer'` to your `Gemfile`.


Then generate the Filterer class:

```
rails generate filterer PersonFilterer
```

And then instead of throwing all of this logic into a controller or model, you create a `Filterer` that looks like this:

```ruby
Expand Down Expand Up @@ -128,4 +135,4 @@ end
Note that if you define an `order_results` method, it will get called automatically.

#### License
MIT
MIT
13 changes: 13 additions & 0 deletions lib/generators/filterer/filterer_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class FiltererGenerator < Rails::Generators::NamedBase
desc "Generate a Filterer in app/filterers/"

argument :name, :type => :string, :required => true, :banner => 'FiltererName'

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

def copy_files # :nodoc:
template "filter.rb", "app/filterers/#{file_name}.rb"
end

hook_for :test_framework
end
2 changes: 2 additions & 0 deletions lib/generators/filterer/templates/filter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class <%= class_name %> < Filterer::Base
end
15 changes: 15 additions & 0 deletions lib/generators/rspec/filterer_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Rspec
module Generators
class FiltererGenerator < Rails::Generators::NamedBase
desc "Generate a Filterer spec in spec/filterers/"

argument :name, :type => :string, :required => true, :banner => 'FiltererName'

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

def copy_files # :nodoc:
template "filter_spec.rb", "spec/filterers/#{file_name}_spec.rb"
end
end
end
end
5 changes: 5 additions & 0 deletions lib/generators/rspec/templates/filter_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require 'spec_helper'

describe <%= class_name %> do
pending "add some examples to (or delete) #{__FILE__}"
end
15 changes: 15 additions & 0 deletions lib/generators/test_unit/filterer_generator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module TestUnit
module Generators
class FiltererGenerator < Rails::Generators::NamedBase
desc "Generate a Filterer test in test/filterers/"

argument :name, :type => :string, :required => true, :banner => 'FiltererName'

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

def copy_files # :nodoc:
template "filter_test.rb", "test/filterers/#{file_name}_test.rb"
end
end
end
end
7 changes: 7 additions & 0 deletions lib/generators/test_unit/templates/filter_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'test_helper'

class <%= class_name %> < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

0 comments on commit d3ca7eb

Please sign in to comment.