irie 1.0.5 → 1.1.0
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 +4 -4
- data/README.md +6 -0
- data/lib/irie/class_methods.rb +1 -1
- data/lib/irie/config.rb +7 -1
- data/lib/irie/extensions/autorender_count.rb +4 -2
- data/lib/irie/extensions/conversion/nil_params.rb +5 -3
- data/lib/irie/extensions/count.rb +7 -2
- data/lib/irie/extensions/index_query.rb +5 -2
- data/lib/irie/extensions/limit.rb +7 -3
- data/lib/irie/extensions/offset.rb +7 -3
- data/lib/irie/extensions/order.rb +11 -3
- data/lib/irie/extensions/paging.rb +13 -5
- data/lib/irie/extensions/paging/autorender_page_count.rb +4 -2
- data/lib/irie/extensions/param_filters.rb +22 -5
- data/lib/irie/extensions/params_to_joins.rb +3 -1
- data/lib/irie/extensions/query_filter.rb +7 -3
- data/lib/irie/extensions/query_includes.rb +10 -3
- data/lib/irie/extensions/smart_layout.rb +6 -2
- data/lib/irie/param_aliases.rb +3 -3
- data/lib/irie/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c6c9a801e9a8f04df53747c167d6d3728a01036
|
4
|
+
data.tar.gz: ba8c401ad9d9f93307174aa57b266962a6d5fd86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 60706798105e74ef9ece7cee97190088034cf9fb2da66f6db0fb18ad29baa2d95b12a86a8d4444d2aa58729fa97616808220fa5ec8d4fbc64238f23bd3729cfa
|
7
|
+
data.tar.gz: acfafe39ace9dad293ce8b7572420217213b1fc7da0351df1013f5f88c06ab423f3c37e2e6b1b994cc51e207d8525d8995231790c307b68632532f34a5691cf5
|
data/README.md
CHANGED
@@ -581,6 +581,12 @@ However, that might not catch all the initialization debug logging that could oc
|
|
581
581
|
config.log_level = :debug
|
582
582
|
```
|
583
583
|
|
584
|
+
If you are really having trouble tracking down a problem and can live with the significant impact of increasing the number and result size of queries and are ok with a lot more data being logged, you can turn on more verbose debug logging via:
|
585
|
+
|
586
|
+
```ruby
|
587
|
+
::Irie.debug = ::Irie.verbose = true
|
588
|
+
```
|
589
|
+
|
584
590
|
### restful_json
|
585
591
|
|
586
592
|
The project was originally named [restful_json][restful_json]. Old commit tags corresponding to restful_json versions may be found in [legacy][legacy].
|
data/lib/irie/class_methods.rb
CHANGED
@@ -45,7 +45,7 @@ module Irie
|
|
45
45
|
ordered_extension_syms.each do |arg_sym|
|
46
46
|
if module_class_name = self.available_extensions[arg_sym]
|
47
47
|
begin
|
48
|
-
logger.debug("Irie::ClassMethods.extensions! #{self} including #{module_class_name}") if ::Irie.debug?
|
48
|
+
::Irie.logger.debug("[Irie] Irie::ClassMethods.extensions! #{self} including #{module_class_name}") if ::Irie.debug?
|
49
49
|
include module_class_name.constantize
|
50
50
|
rescue NameError => e
|
51
51
|
raise ::Irie::ConfigurationError.new "Failed to constantize '#{module_class_name}' with extension key #{arg_sym.inspect} in self.available_extensions. Error: \n#{e.message}\n#{e.backtrace.join("\n")}"
|
data/lib/irie/config.rb
CHANGED
@@ -6,8 +6,10 @@ module Irie
|
|
6
6
|
:available_extensions,
|
7
7
|
:can_filter_by_default_using,
|
8
8
|
:debug,
|
9
|
+
:verbose,
|
9
10
|
:function_param_names,
|
10
11
|
:id_is_primary_key_param,
|
12
|
+
:logger,
|
11
13
|
:number_of_records_in_a_page,
|
12
14
|
:predicate_prefix,
|
13
15
|
:extension_include_order
|
@@ -17,6 +19,10 @@ module Irie
|
|
17
19
|
CONTROLLER_OPTIONS.each{|name|attr_accessor name; define_method("#{name}?") { !!public_send(name) } }
|
18
20
|
def configure(&blk); class_eval(&blk); end
|
19
21
|
|
22
|
+
def logger
|
23
|
+
@logger ||= defined?(Rails) ? Rails.logger : Logger.new(STDOUT)
|
24
|
+
end
|
25
|
+
|
20
26
|
# Adds to extension_include_order and extension_include_order, e.g.
|
21
27
|
# ::Irie.register_extension :boolean_params, '::Focal::Irie::BooleanParams'
|
22
28
|
# Is equivalent to:
|
@@ -120,7 +126,7 @@ end
|
|
120
126
|
# You shouldn't have to worry about configuring this typically.
|
121
127
|
self.available_extensions = {}
|
122
128
|
|
123
|
-
# If true, will logger.debug in instance methods to help with execution tracing at
|
129
|
+
# If true, will ::Irie.logger.debug in instance methods to help with execution tracing at
|
124
130
|
# runtime.
|
125
131
|
self.debug = false
|
126
132
|
end
|
@@ -8,8 +8,10 @@ module Irie
|
|
8
8
|
protected
|
9
9
|
|
10
10
|
def autorender_count(options={}, &block)
|
11
|
-
logger.debug("Irie::Extensions::AutorenderCount.autorender_count") if ::Irie.debug?
|
12
|
-
render
|
11
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::AutorenderCount.autorender_count: count: #{@count}") if ::Irie.debug?
|
12
|
+
result = render(request.format.symbol => { count: @count }, status: 200, layout: false)
|
13
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::AutorenderCount.autorender_count: result: #{result.inspect}") if ::Irie.verbose?
|
14
|
+
result
|
13
15
|
end
|
14
16
|
|
15
17
|
end
|
@@ -12,13 +12,15 @@ module Irie
|
|
12
12
|
|
13
13
|
# Converts request param value(s) 'NULL', 'null', and 'nil' to nil.
|
14
14
|
def convert_param(param_name, param_value_or_values)
|
15
|
-
logger.debug("Irie::Extensions::Conversion::NilParams.convert_param(#{param_name.inspect}, #{param_value_or_values.inspect})") if ::Irie.debug?
|
15
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Conversion::NilParams.convert_param(#{param_name.inspect}, #{param_value_or_values.inspect})") if ::Irie.debug?
|
16
16
|
param_value_or_values = super if defined?(super)
|
17
17
|
if param_value_or_values.is_a? Array
|
18
|
-
param_value_or_values.map{|v| v && NILS.include?(v) ? nil : v }
|
18
|
+
result = param_value_or_values.map{|v| v && NILS.include?(v) ? nil : v }
|
19
19
|
else
|
20
|
-
param_value_or_values && NILS.include?(param_value_or_values) ? nil : param_value_or_values
|
20
|
+
result = param_value_or_values && NILS.include?(param_value_or_values) ? nil : param_value_or_values
|
21
21
|
end
|
22
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Conversion::NilParams.convert_param: result: #{result.inspect}") if ::Irie.verbose?
|
23
|
+
result
|
22
24
|
end
|
23
25
|
|
24
26
|
end
|
@@ -10,10 +10,15 @@ module Irie
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def index(options={}, &block)
|
13
|
-
logger.debug("Irie::Extensions::Count.index") if ::Irie.debug?
|
13
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Count.index") if ::Irie.debug?
|
14
14
|
return super(options, &block) unless aliased_param_present?(:count)
|
15
15
|
@count = collection.count
|
16
|
-
|
16
|
+
|
17
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Count.index: count: #{@count}") if ::Irie.debug?
|
18
|
+
|
19
|
+
result = respond_to?(:autorender_count, true) ? autorender_count(options, &block) : super(options, &block)
|
20
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Count.index: result: #{result.inspect}") if ::Irie.verbose?
|
21
|
+
result
|
17
22
|
end
|
18
23
|
|
19
24
|
end
|
@@ -30,16 +30,19 @@ module Irie
|
|
30
30
|
protected
|
31
31
|
|
32
32
|
def collection
|
33
|
-
logger.debug("Irie::Extensions::IndexQuery.collection") if ::Irie.debug?
|
33
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::IndexQuery.collection") if ::Irie.debug?
|
34
34
|
object = super
|
35
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::IndexQuery.collection starting after super with object=#{object.inspect}") if ::Irie.verbose?
|
35
36
|
if self.custom_index_query
|
36
37
|
# convert to relation if model class because proc expects a relation
|
37
38
|
object = object.all unless object.is_a?(ActiveRecord::Relation)
|
38
39
|
a = object.to_s
|
40
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::IndexQuery.collection before custom_index_query with object=#{object.inspect}") if ::Irie.verbose?
|
39
41
|
object = self.custom_index_query.call(object)
|
42
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::IndexQuery.collection after custom_index_query with object=#{object.inspect}") if ::Irie.verbose?
|
40
43
|
end
|
41
44
|
|
42
|
-
logger.debug("Irie::Extensions::IndexQuery.collection: relation.to_sql so far: #{object.to_sql}") if ::Irie.debug? && object.respond_to?(:to_sql)
|
45
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::IndexQuery.collection: relation.to_sql so far: #{object.to_sql}") if ::Irie.debug? && object.respond_to?(:to_sql)
|
43
46
|
|
44
47
|
set_collection_ivar object
|
45
48
|
end
|
@@ -12,11 +12,15 @@ module Irie
|
|
12
12
|
protected
|
13
13
|
|
14
14
|
def collection
|
15
|
-
logger.debug("Irie::Extensions::Limit.collection") if ::Irie.debug?
|
15
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Limit.collection") if ::Irie.debug?
|
16
16
|
object = super
|
17
|
-
|
17
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Limit.collection: starting after super with object=#{object.inspect}") if ::Irie.verbose?
|
18
|
+
limit_params = aliased_params(:limit)
|
19
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Limit.collection: limit_params=#{limit_params.inspect}") if ::Irie.debug?
|
20
|
+
limit_params.each {|param_value| object = object.limit(param_value.to_i)}
|
21
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Limit.collection: after limits with object=#{object.inspect}") if ::Irie.verbose?
|
18
22
|
|
19
|
-
logger.debug("Irie::Extensions::Limit.collection: relation.to_sql so far: #{object.to_sql}") if ::Irie.debug? && object.respond_to?(:to_sql)
|
23
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Limit.collection: relation.to_sql so far: #{object.to_sql}") if ::Irie.debug? && object.respond_to?(:to_sql)
|
20
24
|
|
21
25
|
set_collection_ivar object
|
22
26
|
end
|
@@ -12,11 +12,15 @@ module Irie
|
|
12
12
|
protected
|
13
13
|
|
14
14
|
def collection
|
15
|
-
logger.debug("Irie::Extensions::Offset.collection") if ::Irie.debug?
|
15
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Offset.collection") if ::Irie.debug?
|
16
16
|
object = super
|
17
|
-
|
17
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Offset.collection starting after super with object=#{object.inspect}") if ::Irie.verbose?
|
18
|
+
offset_params = aliased_params(:offset)
|
19
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Offset.collection: offset_params=#{offset_params.inspect}") if ::Irie.debug?
|
20
|
+
offset_params.each {|param_value| object = object.offset(param_value.to_i)}
|
21
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Offset.collection: after offsets object=#{object.inspect}") if ::Irie.verbose?
|
18
22
|
|
19
|
-
logger.debug("Irie::Extensions::Offset.collection: relation.to_sql so far: #{object.to_sql}") if ::Irie.debug? && object.respond_to?(:to_sql)
|
23
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Offset.collection: relation.to_sql so far: #{object.to_sql}") if ::Irie.debug? && object.respond_to?(:to_sql)
|
20
24
|
|
21
25
|
set_collection_ivar object
|
22
26
|
end
|
@@ -85,8 +85,9 @@ module Irie
|
|
85
85
|
protected
|
86
86
|
|
87
87
|
def collection
|
88
|
-
logger.debug("Irie::Extensions::Order.collection") if ::Irie.debug?
|
88
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Order.collection") if ::Irie.debug?
|
89
89
|
object = super
|
90
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Order.collection starting after super with object=#{object.inspect}") if ::Irie.verbose?
|
90
91
|
|
91
92
|
already_ordered_by = []
|
92
93
|
aliased_params(:order).collect{|p| p.split(',')}.flatten.collect(&:strip).each do |split_param_name|
|
@@ -112,6 +113,7 @@ module Irie
|
|
112
113
|
# if there is one.
|
113
114
|
if self.can_be_ordered_by.include?(split_param_name) && !already_ordered_by.include?(attr_sym)
|
114
115
|
join_to_apply = join_for_param(split_param_name)
|
116
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Order.collection: can_be_ordered_by: calling joins(#{join_to_apply.inspect})") if ::Irie.verbose?
|
115
117
|
object = object.joins(join_to_apply) if join_to_apply
|
116
118
|
arel_table_column = get_arel_table(split_param_name)[attr_sym]
|
117
119
|
raise ::Irie::ConfigurationError.new "can_order_by/define_params config problem: could not find arel table/column for param name #{split_param_name.inspect} and/or attr_sym #{attr_sym.inspect}" unless arel_table_column
|
@@ -119,7 +121,10 @@ module Irie
|
|
119
121
|
sql_fragment = "#{arel_table_column.relation.name}.#{arel_table_column.name}#{direction == :desc ? ' DESC' : ''}"
|
120
122
|
# Important note! the behavior of multiple `order`'s' got reversed between Rails 4.0.0 and 4.0.1:
|
121
123
|
# http://weblog.rubyonrails.org/2013/11/1/Rails-4-0-1-has-been-released/
|
124
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Order.collection: aliased_params: calling order(#{sql_fragment.inspect})") if ::Irie.debug?
|
125
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Order.collection: aliased_params: before order object=#{object.inspect}") if ::Irie.verbose?
|
122
126
|
object = object.order(sql_fragment)
|
127
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Order.collection: aliased_params: after order object=#{object.inspect}") if ::Irie.verbose?
|
123
128
|
already_ordered_by << attr_sym
|
124
129
|
end
|
125
130
|
|
@@ -136,13 +141,16 @@ module Irie
|
|
136
141
|
arel_table_column = get_arel_table(split_param_name)[attr_sym]
|
137
142
|
raise ::Irie::ConfigurationError.new "default_order_by/define_params config problem: could not find arel table/column for param name #{split_param_name.inspect} and/or attr_sym #{attr_sym.inspect}" unless arel_table_column
|
138
143
|
#TODO: is there a better way? not sure how else to order on joined table columns- no example
|
139
|
-
sql_fragment = "#{arel_table_column.relation.name}.#{arel_table_column.name}#{direction == :desc ? ' DESC' : ''}"
|
144
|
+
sql_fragment = "#{arel_table_column.relation.name}.#{arel_table_column.name}#{direction == :desc ? ' DESC' : ''}"
|
145
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Order.collection: default_ordered_by: calling order(#{sql_fragment.inspect})") if ::Irie.debug?
|
146
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Order.collection: default_ordered_by: before order object=#{object.inspect}") if ::Irie.verbose?
|
140
147
|
object = object.order(sql_fragment)
|
148
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Order.collection: default_ordered_by: after order object=#{object.inspect}") if ::Irie.verbose?
|
141
149
|
already_ordered_by << attr_sym
|
142
150
|
end
|
143
151
|
end
|
144
152
|
|
145
|
-
logger.debug("Irie::Extensions::Order.collection: relation.to_sql so far: #{object.to_sql}") if ::Irie.debug? && object.respond_to?(:to_sql)
|
153
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Order.collection: relation.to_sql so far: #{object.to_sql}") if ::Irie.debug? && object.respond_to?(:to_sql)
|
146
154
|
|
147
155
|
set_collection_ivar object
|
148
156
|
end
|
@@ -14,7 +14,7 @@ module Irie
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def index(options={}, &block)
|
17
|
-
logger.debug("Irie::Extensions::
|
17
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Paging.index") if ::Irie.debug?
|
18
18
|
return super(options, &block) unless aliased_param_present?(:page_count)
|
19
19
|
@page_count = (collection.count.to_f / self.number_of_records_in_a_page.to_f).ceil
|
20
20
|
return respond_to?(:autorender_page_count, true) ? autorender_page_count(options, &block) : super(options, &block)
|
@@ -23,17 +23,25 @@ module Irie
|
|
23
23
|
protected
|
24
24
|
|
25
25
|
def collection
|
26
|
-
logger.debug("Irie::Extensions::Paging.collection") if ::Irie.debug?
|
26
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Paging.collection") if ::Irie.debug?
|
27
27
|
object = super
|
28
28
|
page_param_value = aliased_param(:page)
|
29
29
|
unless page_param_value.nil?
|
30
30
|
page = page_param_value.to_i
|
31
31
|
page = 1 if page < 1
|
32
|
-
|
33
|
-
|
32
|
+
::Irie.logger.debug
|
33
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Paging.collection: aliased_params: before offset and limit with object=#{object.inspect}") if ::Irie.verbose?
|
34
|
+
object = object.offset(self.number_of_records_in_a_page.to_i * (page - 1))
|
35
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Paging.collection: aliased_params: after offset/before limit with object=#{object.inspect}") if ::Irie.verbose?
|
36
|
+
object = object.limit(self.number_of_records_in_a_page.to_i)
|
37
|
+
begin
|
38
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Paging.collection: aliased_params: after offset and limit with object=#{object.inspect}") if ::Irie.verbose?
|
39
|
+
rescue => e
|
40
|
+
binding.pry
|
41
|
+
end
|
34
42
|
end
|
35
43
|
|
36
|
-
logger.debug("Irie::Extensions::Paging.collection: relation.to_sql so far: #{object.to_sql}") if ::Irie.debug? && object.respond_to?(:to_sql)
|
44
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Paging.collection: relation.to_sql so far: #{object.to_sql}") if ::Irie.debug? && object.respond_to?(:to_sql)
|
37
45
|
|
38
46
|
set_collection_ivar object
|
39
47
|
end
|
@@ -9,8 +9,10 @@ module Irie
|
|
9
9
|
protected
|
10
10
|
|
11
11
|
def autorender_page_count(options={}, &block)
|
12
|
-
logger.debug("Irie::Extensions::Paging::AutorenderPageCount.autorender_page_count") if ::Irie.debug?
|
13
|
-
render
|
12
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Paging::AutorenderPageCount.autorender_page_count: page_count: #{@page_count.inspect}") if ::Irie.debug?
|
13
|
+
result = render(request.format.symbol => { page_count: @page_count }, status: 200, layout: false)
|
14
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::Paging::AutorenderPageCount.autorender_page_count: result: #{result.inspect}") if ::Irie.verbose?
|
15
|
+
result
|
14
16
|
end
|
15
17
|
|
16
18
|
end
|
@@ -92,11 +92,15 @@ module Irie
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
+
IRIE_ARY_PREDICATES = [:not_eq_any, :not_eq_all, :eq_any, :eq_all, :in_any, :in_all, :not_in_any, :not_in_all, :matches_any, :matches_all, :does_not_match_all,
|
96
|
+
:gteq_any, :gteq_all, :gt_any, :gt_all, :lt_any, :lt_all, :lteq_any, :lteq_all]
|
97
|
+
|
95
98
|
protected
|
96
99
|
|
97
100
|
def collection
|
98
|
-
logger.debug("Irie::Extensions::ParamFilters.collection") if ::Irie.debug?
|
101
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::ParamFilters.collection") if ::Irie.debug?
|
99
102
|
object = super
|
103
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::ParamFilters.collection starting after super with object=#{object.inspect}") if ::Irie.verbose?
|
100
104
|
already_filtered_by_split_param_names = []
|
101
105
|
self.composite_param_to_param_name_and_arel_predicate.each do |composite_param, param_name_and_arel_predicate, split|
|
102
106
|
if params.key?(composite_param)
|
@@ -106,10 +110,16 @@ module Irie
|
|
106
110
|
# support for named_params/:through renaming of param name
|
107
111
|
attr_sym = attr_sym_for_param(split_param_name)
|
108
112
|
join_to_apply = join_for_param(split_param_name)
|
109
|
-
|
113
|
+
if join_to_apply
|
114
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::ParamFilters.collection: composite_param_to_param_name_and_arel_predicate: object.joins(#{join_to_apply.inspect})") if ::Irie.debug?
|
115
|
+
object = object.joins(join_to_apply)
|
116
|
+
end
|
117
|
+
# note: we call it column but it is Arel::Attributes::Attribute
|
110
118
|
arel_table_column = get_arel_table(split_param_name)[attr_sym]
|
111
119
|
raise ::Irie::ConfigurationError.new "can_filter_by/define_params config problem: could not find arel table/column for param name #{split_param_name.inspect} and/or attr_sym #{attr_sym.inspect}" unless arel_table_column
|
120
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::ParamFilters.collection: composite_param_to_param_name_and_arel_predicate: before adding where col=#{arel_table_column.inspect} pred=#{predicate_sym.inspect} equal_to_or_in=#{converted_param_values.inspect} with object=#{object.inspect}") if ::Irie.verbose?
|
112
121
|
object = object.where(arel_table_column.send(predicate_sym, converted_param_values))
|
122
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::ParamFilters.collection: composite_param_to_param_name_and_arel_predicate: after adding where col=#{arel_table_column.inspect} pred=#{predicate_sym.inspect} equal_to_or_in=#{converted_param_values.inspect} with object=#{object.inspect}") if ::Irie.verbose?
|
113
123
|
already_filtered_by_split_param_names << split_param_name
|
114
124
|
end
|
115
125
|
end
|
@@ -118,16 +128,23 @@ module Irie
|
|
118
128
|
unless already_filtered_by_split_param_names.include?(split_param_name) || predicates_to_default_values.blank?
|
119
129
|
attr_sym = attr_sym_for_param(split_param_name)
|
120
130
|
join_to_apply = join_for_param(split_param_name)
|
121
|
-
|
131
|
+
if join_to_apply
|
132
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::ParamFilters.collection: default_filtered_by: object.joins(#{join_to_apply.inspect})") if ::Irie.debug?
|
133
|
+
object = object.joins(join_to_apply)
|
134
|
+
end
|
135
|
+
# note: we call it column but it is Arel::Attributes::Attribute
|
122
136
|
arel_table_column = get_arel_table(split_param_name)[attr_sym]
|
123
137
|
raise ::Irie::ConfigurationError.new "default_filter_by/define_params config problem: could not find arel table/column for param name #{split_param_name.inspect} and/or attr_sym #{attr_sym.inspect}" unless arel_table_column
|
124
138
|
predicates_to_default_values.each do |predicate_sym, one_or_more_default_values|
|
125
|
-
|
139
|
+
one_or_more_default_values = Array.wrap(one_or_more_default_values) if IRIE_ARY_PREDICATES.include?(predicate_sym)
|
140
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::ParamFilters.collection: default_filtered_by: before adding where col=#{arel_table_column.inspect} pred=#{predicate_sym.inspect} equal_to_or_in=#{one_or_more_default_values.inspect} with object=#{object.inspect}") if ::Irie.verbose?
|
141
|
+
object = object.where(arel_table_column.send(predicate_sym, one_or_more_default_values))
|
142
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::ParamFilters.collection: default_filtered_by: after adding where col=#{arel_table_column.inspect} pred=#{predicate_sym.inspect} equal_to_or_in=#{one_or_more_default_values.inspect} with object=#{object.inspect}") if ::Irie.verbose?
|
126
143
|
end
|
127
144
|
end
|
128
145
|
end
|
129
146
|
|
130
|
-
logger.debug("Irie::Extensions::ParamFilters.collection: relation.to_sql so far: #{object.to_sql}") if ::Irie.debug? && object.respond_to?(:to_sql)
|
147
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::ParamFilters.collection: relation.to_sql so far: #{object.to_sql}") if ::Irie.debug? && object.respond_to?(:to_sql)
|
131
148
|
|
132
149
|
set_collection_ivar object
|
133
150
|
end
|
@@ -93,13 +93,15 @@ module Irie
|
|
93
93
|
end
|
94
94
|
|
95
95
|
(find_arel_table = ->(last_resource_class, val) do
|
96
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::ParamsToJoins.get_arel_table: calling anonymous function with #{last_resource_class.inspect}, #{val.inspect}") if ::Irie.debug?
|
96
97
|
case val
|
97
98
|
when String, Symbol
|
98
99
|
find_assoc_resource_class.call(last_resource_class, val).arel_table
|
99
100
|
when Hash
|
100
101
|
find_arel_table.call(find_assoc_resource_class.call(last_resource_class, val.keys.first), val.values.first)
|
101
102
|
else
|
102
|
-
|
103
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::ParamsToJoins.get_arel_table: unhandled val in anonymous function: #{val.inspect}") if ::Irie.debug?
|
104
|
+
raise ::Irie::ConfigurationError.new "get_arel_table failed because unhandled(#{last_resource_class.inspect}, #{val.inspect}) in joins in through"
|
103
105
|
end
|
104
106
|
end)[resource_class, opts[:joins]]
|
105
107
|
end
|
@@ -36,8 +36,9 @@ module Irie
|
|
36
36
|
protected
|
37
37
|
|
38
38
|
def collection
|
39
|
-
logger.debug("Irie::Extensions::QueryFilter.collection") if ::Irie.debug?
|
39
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::QueryFilter.collection") if ::Irie.debug?
|
40
40
|
object = super
|
41
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::QueryFilter.collection starting after super with object=#{object.inspect}") if ::Irie.verbose?
|
41
42
|
# convert to relation if model class because proc expects a relation
|
42
43
|
object = object.all unless object.is_a?(ActiveRecord::Relation)
|
43
44
|
|
@@ -45,11 +46,14 @@ module Irie
|
|
45
46
|
self.param_to_query.each do |param_name, param_query|
|
46
47
|
param_value = params[param_name]
|
47
48
|
unless param_value.nil?
|
48
|
-
|
49
|
+
converted_param = convert_param(param_name.to_s, param_value)
|
50
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::QueryFilter.collection: param_to_query: before query call with object=#{object.inspect} and converted_param=#{converted_param.inspect}") if ::Irie.verbose?
|
51
|
+
object = param_query.call(object, converted_param)
|
52
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::QueryFilter.collection: param_to_query: after query call with object=#{object.inspect}") if ::Irie.verbose?
|
49
53
|
end
|
50
54
|
end
|
51
55
|
|
52
|
-
logger.debug("Irie::Extensions::QueryFilter.collection: relation.to_sql so far: #{object.to_sql}") if ::Irie.debug? && object.respond_to?(:to_sql)
|
56
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::QueryFilter.collection: relation.to_sql so far: #{object.to_sql}") if ::Irie.debug? && object.respond_to?(:to_sql)
|
53
57
|
|
54
58
|
set_collection_ivar object
|
55
59
|
end
|
@@ -62,12 +62,16 @@ module Irie
|
|
62
62
|
|
63
63
|
this_includes = self.action_to_query_includes[params[:action].to_sym] || self.all_action_query_includes
|
64
64
|
if this_includes && this_includes.size > 0
|
65
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::QueryIncludes.collection: calling .includes(*#{this_includes.inspect})") if ::Irie.debug?
|
65
66
|
object = object.includes(*this_includes)
|
66
67
|
else
|
68
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::QueryIncludes.collection: not calling .includes") if ::Irie.debug?
|
67
69
|
object
|
68
70
|
end
|
69
71
|
|
70
|
-
logger.debug("Irie::Extensions::QueryIncludes.collection: relation.to_sql so far: #{object.to_sql}") if ::Irie.debug? && object.respond_to?(:to_sql)
|
72
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::QueryIncludes.collection: relation.to_sql so far: #{object.to_sql}") if ::Irie.debug? && object.respond_to?(:to_sql)
|
73
|
+
|
74
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::QueryIncludes.collection: object = #{object.inspect}") if ::Irie.verbose?
|
71
75
|
|
72
76
|
set_collection_ivar object
|
73
77
|
end
|
@@ -75,19 +79,22 @@ module Irie
|
|
75
79
|
def resource
|
76
80
|
cached = get_resource_ivar
|
77
81
|
if cached
|
78
|
-
logger.debug("Irie::Extensions::QueryIncludes.resource returning cached resource") if ::Irie.debug?
|
82
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::QueryIncludes.resource: returning cached resource") if ::Irie.debug?
|
79
83
|
return cached
|
80
84
|
end
|
81
85
|
logger.debug("Irie::Extensions::QueryIncludes.resource") if ::Irie.debug?
|
86
|
+
|
82
87
|
this_includes = self.action_to_query_includes[params[:action].to_sym] || self.all_action_query_includes
|
83
88
|
if this_includes && this_includes.size > 0
|
84
89
|
# can return the model class, so won't call bang (includes!) method
|
85
90
|
object = end_of_association_chain.includes(*this_includes)
|
86
91
|
|
87
|
-
logger.debug("Irie::Extensions::QueryIncludes.resource: end_of_association_chain.to_sql: #{object.to_sql}") if ::Irie.debug? && object.respond_to?(:to_sql)
|
92
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::QueryIncludes.resource: end_of_association_chain.to_sql: #{object.to_sql}") if ::Irie.debug? && object.respond_to?(:to_sql)
|
88
93
|
|
89
94
|
set_resource_ivar object.send(method_for_find, params[:id])
|
90
95
|
else
|
96
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::QueryIncludes.resource") if ::Irie.debug?
|
97
|
+
|
91
98
|
super
|
92
99
|
end
|
93
100
|
end
|
@@ -10,8 +10,12 @@ module Irie
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def index(options={}, &block)
|
13
|
-
|
14
|
-
|
13
|
+
if request.format.html?
|
14
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::SmartLayout.index: not merging layout:false into options because not html") if ::Irie.debug?
|
15
|
+
else
|
16
|
+
::Irie.logger.debug("[Irie] Irie::Extensions::SmartLayout.index: merging layout:false into options because format.html? is truthy") if ::Irie.debug?
|
17
|
+
options.merge!({layout: false}) unless request.format.html?
|
18
|
+
end
|
15
19
|
super(options, &block)
|
16
20
|
end
|
17
21
|
|
data/lib/irie/param_aliases.rb
CHANGED
@@ -9,7 +9,7 @@ module Irie
|
|
9
9
|
# values for all matching defined request params. Does *not* convert param
|
10
10
|
# value with convert_param(...).
|
11
11
|
def aliased_params(function_sym)
|
12
|
-
logger.debug("Irie::ParamAliases.aliased_params(#{function_sym.inspect})") if ::Irie.debug?
|
12
|
+
::Irie.logger.debug("[Irie] Irie::ParamAliases.aliased_params(#{function_sym.inspect})") if ::Irie.debug?
|
13
13
|
if self.function_param_names.key?(function_sym)
|
14
14
|
self.function_param_names[function_sym].select {|v| params.key?(v)}.collect {|param_name| params[param_name]}
|
15
15
|
else
|
@@ -18,7 +18,7 @@ module Irie
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def aliased_param_present?(function_sym)
|
21
|
-
logger.debug("Irie::ParamAliases.aliased_param_key?(#{function_sym.inspect})") if ::Irie.debug?
|
21
|
+
::Irie.logger.debug("[Irie] Irie::ParamAliases.aliased_param_key?(#{function_sym.inspect})") if ::Irie.debug?
|
22
22
|
if self.function_param_names.key?(function_sym)
|
23
23
|
self.function_param_names[function_sym].select {|v| params.key?(v)}.any? {|param_name| params.key?(param_name)}
|
24
24
|
else
|
@@ -28,7 +28,7 @@ module Irie
|
|
28
28
|
|
29
29
|
# Same as aliased_params(function_sym).first.
|
30
30
|
def aliased_param(function_sym)
|
31
|
-
logger.debug("Irie::ParamAliases.aliased_param(#{function_sym.inspect})") if ::Irie.debug?
|
31
|
+
::Irie.logger.debug("[Irie] Irie::ParamAliases.aliased_param(#{function_sym.inspect})") if ::Irie.debug?
|
32
32
|
aliased_params(function_sym).first
|
33
33
|
end
|
34
34
|
|
data/lib/irie/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: irie
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gary S. Weaver
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-10-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: inherited_resources
|
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
75
|
version: '0'
|
76
76
|
requirements: []
|
77
77
|
rubyforge_project:
|
78
|
-
rubygems_version: 2.
|
78
|
+
rubygems_version: 2.4.5.1
|
79
79
|
signing_key:
|
80
80
|
specification_version: 4
|
81
81
|
summary: Extend Inherited Resources.
|