toqua 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 745d7d0ec268a8a7509179982abbfeef4f4e98cd6e6390e57c77616e87f8c10c
4
- data.tar.gz: 45aa239ad2062c5818de689d1d84008ae2042ad38e97f20727ee2d8ea5859faa
3
+ metadata.gz: 0c7dc34b6e76e654884ef282dbe23f1c0b709767229c3008361db8a45770a479
4
+ data.tar.gz: 935dbc12c97df5ec215b9d966a5a43ea079eff93c727d533467cc377c697bb7c
5
5
  SHA512:
6
- metadata.gz: 7e9aded04af084691a599cd770656d709567705165687aa29103365e68b670d967331b277c851bc97217ff9cbd397e2ed41b14c627c1501b5b0622e13b82f754
7
- data.tar.gz: 5a10920bea8413c152a9bb322b8940ba9faf7d731a8ad0532ec4955d5a22580d337dd7196c0a09a0e069680fc660023bbafa852da9debc58a7aa247488e11fff
6
+ metadata.gz: 52964e9d094691ec2717179cc517017edce77dd2a2ab55165a644896388521ea02795cff76c1055e6a9016807ba3f73641389a7225f8be5505fb3e5c1265caf9
7
+ data.tar.gz: 43cc8e524fd9c0db64c9d1f8853f41576636c488e08a04ad7d8733b61de41f605cb4335929ef670c4971467e083b141d99f649f5fe9a1d77b5ec15a2f7c48041
@@ -26,8 +26,8 @@ module Toqua
26
26
  scope(scope_opts) do |scope|
27
27
  @paginated = true
28
28
 
29
- @page = params.fetch(page_key, opts.fetch(:page, DEFAULT_PAGE))
30
- per = params.fetch(per_page_key, opts.fetch(:per, DEFAULT_PER_PAGE))
29
+ @page = params.to_unsafe_h.fetch(page_key, opts.fetch(:page, DEFAULT_PAGE))
30
+ per = params.to_unsafe_h.fetch(per_page_key, opts.fetch(:per, DEFAULT_PER_PAGE))
31
31
 
32
32
  if opts[:headers]
33
33
  scope_count = scope.count
data/lib/toqua/scoping.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Toqua
2
4
  module Scoping
3
5
  extend ActiveSupport::Concern
@@ -10,23 +12,41 @@ module Toqua
10
12
  s
11
13
  end
12
14
 
15
+ class ScopeApplicable
16
+ def self.accept?(opts, context)
17
+ if_condition(context, opts) && action_condition(context, opts)
18
+ end
19
+
20
+ def self.action_condition(context, opts)
21
+ if opts[:only]
22
+ [opts[:only]].flatten.include?(context.action_name.to_sym)
23
+ else
24
+ true
25
+ end
26
+ end
27
+
28
+ def self.if_condition(context, opts)
29
+ if opts[:if]
30
+ !!evaluate(context, opts[:if])
31
+ elsif opts[:unless]
32
+ !evaluate(context, opts[:unless])
33
+ else
34
+ true
35
+ end
36
+ end
37
+
38
+ def self.evaluate(context, object)
39
+ if object.respond_to?(:call)
40
+ context.instance_exec(&object)
41
+ else
42
+ context.send(object)
43
+ end
44
+ end
45
+ end
46
+
13
47
  def __run_scope(relation, scope, opts)
14
- if_condition = if opts[:if]
15
- opts[:if].respond_to?(:call) ? !!instance_exec(&opts[:if]) : send(opts[:if])
16
- elsif opts[:unless]
17
- opts[:unless].respond_to?(:call) ? !instance_exec(&opts[:unless]) : !send(opts[:unless])
18
- else
19
- true
20
- end
21
-
22
- action_condition = if opts[:only]
23
- [opts[:only]].flatten.include?(action_name.to_sym)
24
- else
25
- true
26
- end
27
-
28
- if if_condition && action_condition
29
- self.instance_exec(relation, &scope)
48
+ if ScopeApplicable.accept?(opts, self)
49
+ instance_exec(relation, &scope)
30
50
  else
31
51
  relation
32
52
  end
@@ -43,4 +63,4 @@ module Toqua
43
63
  end
44
64
  end
45
65
  end
46
- end
66
+ end
data/lib/toqua/search.rb CHANGED
@@ -38,7 +38,7 @@ module Toqua
38
38
 
39
39
  class_methods do
40
40
  def searchable
41
- scope { |s| s.filter(search_params) }
41
+ scope { |s| s.doure_filter(search_params) }
42
42
  end
43
43
  end
44
44
  end
data/lib/toqua/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Toqua
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toqua
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Campos
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-28 00:00:00.000000000 Z
11
+ date: 2021-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -205,8 +205,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
205
205
  - !ruby/object:Gem::Version
206
206
  version: '0'
207
207
  requirements: []
208
- rubyforge_project:
209
- rubygems_version: 2.7.3
208
+ rubygems_version: 3.0.3
210
209
  signing_key:
211
210
  specification_version: 4
212
211
  summary: Collection of small utilities for controllers in rails applications