bolter 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 388ad37ede862d5892971b1ba805ee03bf93ddb6
4
- data.tar.gz: 33e039682406dfb86420287c258e553d4984330d
3
+ metadata.gz: ec99ab0f4a566eef9a9aaba790dd683cf37cb95b
4
+ data.tar.gz: e6de1200f625cd5a8427158cca89ed5556a0aab4
5
5
  SHA512:
6
- metadata.gz: d1a2ddf0dd73f69f9faeb1d47caf7c9cd35a7b7623bfac1c450b533509ae7bd3a5a4e859ad9f4c135b0b349dee328b5134ed71ef691f1f8887fc33498d0a1106
7
- data.tar.gz: 2895c37fbef6c5379166e5f4494debeed3482ef96d76448f937d45df562cde2654353616b6e92afb3a6beef976157d3878126530d09c7a486719b1911179dc8e
6
+ metadata.gz: b2c784b730edb31276812828518889f92eda958ad58027e4b15f83689ca3dd1eae36bf68db48d56c3e70893fc00dbe84c1141f297a80b4ba507bb25d67dba65d
7
+ data.tar.gz: 815bdc59eadb6cc3fac23f8061d425914c2b60f772e4406e7fbdb2aec521a6c5191210c0fd64fb36c87b405ecc87f5f48618173f67c81872aebe0dc25c3bd52b
data/README.md CHANGED
@@ -36,8 +36,8 @@ View:
36
36
  .search
37
37
  = form_tag books_path, method: :get, id: :search do
38
38
  = fields_for :filters, OpenStruct.new(params[:filters]) do |f|
39
- = f.label :with_name, EventTarget.human_attribute_name(:name)
40
- = f.text_field :with_name, :class => 'form-control'
39
+ = f.label :with_name, Book.human_attribute_name(:name)
40
+ = f.text_field :with_name
41
41
  .index
42
42
  %table
43
43
  %tr
@@ -3,37 +3,32 @@ module Bolter
3
3
  extend ActiveSupport::Concern
4
4
  included do
5
5
  cattr_reader :filters
6
- def self.filter(name, value, &block)
6
+ end
7
+ class_methods do
8
+ def filter(name, value, &block)
7
9
  @@filters ||= []
8
10
  @@filters << name.to_s
9
11
  scope name.to_sym, value, &block
10
12
  end
11
- # options[:filters] - used filters, default for all
12
- def self.search(params = {}, options = {})
13
+ def search(params = {}, options = {})
13
14
  # Prepare filters
14
- filters = Array(options[:filters] || self.filters).map(&:to_s)
15
+ enabled_filters = Array(options[:filters] || self.filters).map(&:to_s)
15
16
 
16
17
  # Prepare default result
17
- result = self.scoped
18
+ result = self
18
19
 
19
20
  # Prepare params to search
20
21
  search = (params || {}).clone.reject{|_,value| value.to_s.empty? }
21
22
 
22
23
  # Apply filters
23
24
  search.each do |name, value|
24
- if self.scopes.include? name.to_sym
25
- if filters.include? name.to_s
26
- result = self.scopes[name.to_sym][:scope].arity == 0 ? result.send(name) : result.send(name, *value)
27
- else
28
- logger.warn "Skip filter #{self}.#{name}(#{value.inspect})"
29
- end
25
+ if enabled_filters.include?(name.to_s)
26
+ result = result.send(name.to_s, value)
30
27
  else
31
28
  logger.warn "Unknown filter #{self}.#{name}(#{value.inspect})"
32
29
  end
33
30
  end
34
-
35
- # return scope with applied filters
36
- return result
31
+ result
37
32
  end
38
33
  end
39
34
  end
@@ -2,15 +2,15 @@ module Bolter
2
2
  module Sortable
3
3
  extend ActiveSupport::Concern
4
4
  included do
5
- def self.sorting(sorting)
6
- return self.scoped unless sorting
5
+ def self.sorting(sorting = nil)
6
+ return self unless sorting
7
7
  field, direction = sorting.split(':',2)
8
8
  if self.attribute_names.include? field.to_s
9
9
  if %W[asc desc].include? direction
10
- self.scoped.order(Hash[field, direction])
10
+ return self.order(Hash[field, direction])
11
11
  end
12
12
  else
13
- self.scoped
13
+ self
14
14
  end
15
15
  end
16
16
  end
@@ -1,3 +1,3 @@
1
1
  module Bolter
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bolter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evgeniy Shurmin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2015-04-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -93,8 +93,6 @@ files:
93
93
  - LICENSE.txt
94
94
  - README.md
95
95
  - Rakefile
96
- - bin/console
97
- - bin/setup
98
96
  - bolter.gemspec
99
97
  - lib/bolter.rb
100
98
  - lib/bolter/helpers.rb
@@ -127,3 +125,4 @@ signing_key:
127
125
  specification_version: 4
128
126
  summary: This gem include sorting and filtering methods
129
127
  test_files: []
128
+ has_rdoc:
data/bin/console DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "bolter"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start
data/bin/setup DELETED
@@ -1,7 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
-
5
- bundle install
6
-
7
- # Do any other automated setup that you need to do here