Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor. #240

Merged
merged 2 commits into from
Jul 16, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions lib/wice/grid_output_buffer.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# encoding: utf-8
module Wice
class GridOutputBuffer < String #:nodoc:
attr_accessor :return_empty_strings_for_nonexistent_filters

def initialize(*attrs)
super(*attrs)
@filters = HashWithIndifferentAccess.new
Expand All @@ -17,17 +15,19 @@ def add_filter(detach_with_id, filter_code)
@filters[detach_with_id] = filter_code
end

def filter_for(detach_with_id)
def filter_for(detach_with_id, return_empty_strings_for_nonexistent_filters = false)
unless @filters.key? detach_with_id
if @return_empty_strings_for_nonexistent_filters
if return_empty_strings_for_nonexistent_filters
return ''
else
fail WiceGridException.new("No filter with Detached ID '#{detach_with_id}'!")
end
end
if @filters[detach_with_id] == false

unless @filters[detach_with_id]
fail WiceGridException.new("Filter with Detached ID '#{detach_with_id}' has already been requested once! There cannot be two instances of the same filter on one page")
end

res = @filters[detach_with_id]
@filters[detach_with_id] = false
res
Expand Down
4 changes: 1 addition & 3 deletions lib/wice/helpers/wice_grid_view_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,7 @@ def generate_blank_slate(grid, rendering) #:nodoc:
rendering.blank_slate_handler
end

if rendering.find_one_for(:in_html) { |column| column.detach_with_id }
grid.output_buffer.return_empty_strings_for_nonexistent_filters = true
end
rendering.find_one_for(:in_html, true) { |column| column.detach_with_id }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will cause an error. Wice::GridRenderer#find_one_for has the arity of 1.
I think you want to pass true to the output_buffer, but rendering is a different object, it is not GridOutputBuffer where #filter_for is.

end

def call_block(block, ar, extra_argument = nil) #:nodoc:
Expand Down
6 changes: 6 additions & 0 deletions spec/wice/lib/grid_output_buffer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,11 @@ module Wice

expect { grid.filter_for('key') }.to raise_error
end

it 'should filter_for return empty string' do
grid = GridOutputBuffer.new

expect(grid.filter_for('key', true)).to eq('')
end
end
end