Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
126 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
require "filtered/version" | ||
require "filtered/field_definition" | ||
require "filtered/base" | ||
|
||
module Filtered | ||
|
||
require "filtered/version" | ||
require "filtered/field_definition" | ||
require "filtered/base" | ||
|
||
if defined?(Rails) | ||
require "filtered/engine" | ||
end | ||
|
||
class Error < StandardError; end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Filtered | ||
class Engine < ::Rails::Engine | ||
config.autoload_paths += Dir["#{config.root}/app/filters/**/"] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Description: | ||
Stubs out a new filter. Pass the filter name, either CamelCased or | ||
under_scored, and an optional list of fields as arguments. | ||
|
||
You don't have to think up every field up front, but it helps to | ||
sketch out a few so you can start working with the filter immediately. | ||
|
||
To create a filter within a module, specify the filter name as a | ||
path like 'parent_module/filter_name'. | ||
|
||
Example: | ||
`rails generate filter users group persmission` | ||
|
||
Users filter. | ||
Filter: app/filters/users_filter.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
class FilterGenerator < Rails::Generators::NamedBase | ||
check_class_collision suffix: "Filter" | ||
|
||
source_root File.expand_path("templates", __dir__) | ||
|
||
argument :fields, type: :array, default: [], banner: "field field" | ||
|
||
def create_filter_file | ||
template "filter.rb", File.join("app/filters", class_path, "#{file_name}_filter.rb") | ||
end | ||
|
||
private | ||
|
||
def file_name | ||
@_file_name ||= super.sub(/_filter\z/i, "") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class <%= class_name %>Filter < ApplicationFilter | ||
<% for field in fields -%> | ||
field :<%= field %> | ||
<% end -%> | ||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Filtered | ||
module Generators | ||
class InstallGenerator < Rails::Generators::Base | ||
|
||
source_root File.expand_path("templates", __dir__) | ||
|
||
def generate_install | ||
copy_file "application_filter.rb", "app/filters/application_filter.rb" | ||
end | ||
end | ||
end | ||
end |
3 changes: 3 additions & 0 deletions
3
lib/generators/filtered/install/templates/application_filter.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class ApplicationFilter < Filtered::Base | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
require "spec_helper" | ||
require "generator_spec" | ||
require "generators/filter/filter_generator" | ||
|
||
RSpec.describe FilterGenerator, type: :generator do | ||
destination File.expand_path("../../tmp", __FILE__) | ||
arguments %w(users group persmission) | ||
|
||
before(:all) do | ||
prepare_destination | ||
run_generator | ||
end | ||
|
||
it "creates a filter file" do | ||
assert_file "app/filters/users_filter.rb", /class UsersFilter < ApplicationFilter/ | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require "spec_helper" | ||
require "generator_spec" | ||
require "generators/filtered/install/install_generator" | ||
|
||
RSpec.describe Filtered::Generators::InstallGenerator, type: :generator do | ||
destination File.expand_path("../../tmp", __FILE__) | ||
|
||
before(:all) do | ||
prepare_destination | ||
run_generator | ||
end | ||
|
||
it "creates a base file" do | ||
assert_file "app/filters/application_filter.rb" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class ApplicationFilter < Filtered::Base | ||
|
||
end |