irie 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +52 -91
- data/lib/irie/extensions/query_includes.rb +10 -0
- data/lib/irie/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 83d55681746b7b5b2d5ecc207a41000e69bf299c
|
4
|
+
data.tar.gz: 3bba10948d23a3c1676b0c4513cbcb6e37e01314
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d25b2cf8efe484b2e074bcf8832b3cfb508b24bf3d3106ffba5bba1a0dbe88695e02a92a142962ce3cb056ca63c134a3e5c6af915efa1edd14e86f7e6da2f2f
|
7
|
+
data.tar.gz: c5e2b0844fb810cbbf51beb00d68ebaca098f6612a96bd20054731674c9c9f5a0ef97206e41a8fc493724a34c06adc7ba667671b168d921262be5b01dcb93e11
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
Inherited Resources including extensions. Tested with Rails 4/edge, Inherited Resources 1.4/edge in Ruby 1.9.3, 2.0.0, and jruby-19mode.
|
6
6
|
|
7
|
-
Extend [Inherited Resources][inherited_resources] actions with the `extensions` method which provides symbolic references to do module includes as well as automatic inclusion of modules based on what actions are
|
7
|
+
Extend [Inherited Resources][inherited_resources] actions with the `extensions` method which provides symbolic references to do module includes as well as automatic inclusion of modules based on what `actions` are defined. The included extensions provide more of a DSL-like way to define your controllers. And, instead of model-heavy development via `scope` in models and `has_scope` in the controller, you can just define request parameter-based filters and their defaults in the controller. Ordering, parameter value conversion, pagination, and more are supported without additional dependencies.
|
8
8
|
|
9
9
|
```ruby
|
10
10
|
class PostsController < ApplicationController
|
@@ -246,45 +246,7 @@ The return value of the lambda becomes the new query, so you could really change
|
|
246
246
|
|
247
247
|
##### Customizing Request Parameter Value Conversion
|
248
248
|
|
249
|
-
Implement the `convert_param(param_name, param_values)` in your controller or an included module
|
250
|
-
|
251
|
-
```ruby
|
252
|
-
# example of custom parameter value converter
|
253
|
-
module Example
|
254
|
-
module BooleanParams
|
255
|
-
extend ::ActiveSupport::Concern
|
256
|
-
|
257
|
-
TRUE_VALUE = 'true'.freeze
|
258
|
-
FALSE_VALUE = 'false'.freeze
|
259
|
-
|
260
|
-
protected
|
261
|
-
|
262
|
-
# Converts request param value(s) 'true' to true and 'false' to false
|
263
|
-
def convert_param(param_name, param_value_or_values)
|
264
|
-
logger.debug("Example::BooleanParams.convert_param(#{param_name.inspect}, #{param_value_or_values.inspect})") if ::Irie.debug?
|
265
|
-
param_value_or_values = super if defined?(super)
|
266
|
-
if param_value_or_values.is_a? Array
|
267
|
-
param_value_or_values.map {|v| convert_boolean(v)}
|
268
|
-
else
|
269
|
-
convert_boolean(param_value_or_values)
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
273
|
-
private
|
274
|
-
|
275
|
-
def convert_boolean(value)
|
276
|
-
case value
|
277
|
-
when TRUE_VALUE
|
278
|
-
true
|
279
|
-
when FALSE_VALUE
|
280
|
-
false
|
281
|
-
else
|
282
|
-
value
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|
287
|
-
```
|
249
|
+
Implement the `convert_param(param_name, param_values)` in your controller or an included module. See [Writing Your Own Extensions](#writing-your-own-extensions) for an example.
|
288
250
|
|
289
251
|
#### Default Filters
|
290
252
|
|
@@ -488,79 +450,78 @@ The following concerns, which you can include via `extensions ...` or via includ
|
|
488
450
|
|
489
451
|
Extensions are just modules. There is no magic.
|
490
452
|
|
491
|
-
|
453
|
+
Some hopefully good examples of how to extend modules are in this project in `lib/irie/extensions/`.
|
492
454
|
|
493
|
-
|
494
|
-
|
495
|
-
Here's another example:
|
455
|
+
Here's a quick example:
|
496
456
|
|
497
457
|
```ruby
|
498
|
-
|
499
|
-
module BooleanParams
|
500
|
-
|
501
|
-
|
502
|
-
protected
|
503
|
-
|
504
|
-
def convert_param(param_name, param_values)
|
505
|
-
case param_values
|
506
|
-
when 'true'
|
507
|
-
true
|
508
|
-
when 'false'
|
509
|
-
false
|
510
|
-
else
|
511
|
-
super if defined?(super)
|
512
|
-
end
|
513
|
-
end
|
514
|
-
|
515
|
-
end
|
516
|
-
```
|
517
|
-
|
518
|
-
If you are just doing regular `include`'s in your controllers, that's all you need. If you'd like to use `extensions`, you get autoincludes and can use symbols, e.g. in `app/controllers/concerns/service_controller.rb`:
|
458
|
+
module Example
|
459
|
+
module BooleanParams
|
460
|
+
extend ::ActiveSupport::Concern
|
519
461
|
|
520
|
-
|
521
|
-
|
522
|
-
extend ::ActiveSupport::Concern
|
462
|
+
TRUE_VALUE = 'true'.freeze
|
463
|
+
FALSE_VALUE = 'false'.freeze
|
523
464
|
|
524
|
-
|
525
|
-
inherit_resources
|
526
|
-
respond_to :json
|
465
|
+
protected
|
527
466
|
|
528
|
-
#
|
529
|
-
|
467
|
+
# Converts request param value(s) 'true' to true and 'false' to false
|
468
|
+
def convert_param(param_name, param_value_or_values)
|
469
|
+
logger.debug("Example::BooleanParams.convert_param(#{param_name.inspect}, #{param_value_or_values.inspect})") if ::Irie.debug?
|
470
|
+
param_value_or_values = super if defined?(super)
|
471
|
+
if param_value_or_values.is_a? Array
|
472
|
+
param_value_or_values.map {|v| convert_boolean(v)}
|
473
|
+
else
|
474
|
+
convert_boolean(param_value_or_values)
|
475
|
+
end
|
476
|
+
end
|
530
477
|
|
531
|
-
|
532
|
-
# ::Irie.register_extension :boolean_params, '::Example::BooleanParams', include: :last #default
|
533
|
-
# ::Irie.register_extension :boolean_params, '::Example::BooleanParams', include: :first
|
534
|
-
# ::Irie.register_extension :boolean_params, '::Example::BooleanParams', after: :nil_params
|
535
|
-
# ::Irie.register_extension :boolean_params, '::Example::BooleanParams', before: :nil_params
|
478
|
+
private
|
536
479
|
|
480
|
+
def convert_boolean(value)
|
481
|
+
case value
|
482
|
+
when TRUE_VALUE
|
483
|
+
true
|
484
|
+
when FALSE_VALUE
|
485
|
+
false
|
486
|
+
else
|
487
|
+
value
|
488
|
+
end
|
489
|
+
end
|
537
490
|
end
|
538
|
-
|
539
491
|
end
|
540
492
|
```
|
541
493
|
|
542
|
-
|
494
|
+
If you are just doing regular `include`'s in your controllers, that's all you need, and you can include when you need to.
|
543
495
|
|
544
|
-
|
545
|
-
include ServiceController
|
496
|
+
If you'd like to use your modules via the `extensions` method, just register the extension in an initializer, e.g. in `config/initializers/irie.rb`:
|
546
497
|
|
547
|
-
|
548
|
-
|
498
|
+
```ruby
|
499
|
+
# note: Referencing as string so we don't load the concern before it is used.
|
500
|
+
::Irie.register_extension :boolean_params, '::Example::BooleanParams'
|
549
501
|
```
|
550
502
|
|
551
|
-
|
503
|
+
Now, you could do this in your controller:
|
552
504
|
|
553
|
-
|
505
|
+
```ruby
|
506
|
+
respond_to :json
|
507
|
+
inherit_resources
|
554
508
|
|
555
|
-
|
509
|
+
actions :index
|
510
|
+
extensions :boolean_params
|
511
|
+
```
|
556
512
|
|
557
|
-
|
513
|
+
Irie includes a way to specify order of module inclusion independent of the class/module it is included in, and you can specify that at registration, e.g. in an initializer like `config/initializers/irie.rb`, you might do one of the following:
|
558
514
|
|
559
|
-
|
515
|
+
```ruby
|
516
|
+
::Irie.register_extension :boolean_params, '::Example::BooleanParams', include: :last # last is the default, so don't need to specify this option
|
517
|
+
::Irie.register_extension :boolean_params, '::Example::BooleanParams', include: :first
|
518
|
+
::Irie.register_extension :boolean_params, '::Example::BooleanParams', after: :nil_params
|
519
|
+
::Irie.register_extension :boolean_params, '::Example::BooleanParams', before: :nil_params
|
520
|
+
```
|
560
521
|
|
561
|
-
|
522
|
+
Note: an extension must be registered before you can use `after:` or `before:` to place your extension include after or before it. Use `require` and declare dependencies if possible to ensure registration of other extensions, and nothing is stopping you from registering something else. The extension class constant isn't going to be referenced by Irie until `extensions` is called with it.
|
562
523
|
|
563
|
-
|
524
|
+
The `extensions` method is just a companion to `actions` if you want to use it. You can still use [include/extend/prepend](http://ruby-doc.org/core-2.0.0/Module.html), if you'd rather.
|
564
525
|
|
565
526
|
### Troubleshooting
|
566
527
|
|
@@ -73,6 +73,11 @@ module Irie
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def resource
|
76
|
+
cached = get_resource_ivar
|
77
|
+
if cached
|
78
|
+
logger.debug("Irie::Extensions::QueryIncludes.resource returning cached resource") if ::Irie.debug?
|
79
|
+
return cached
|
80
|
+
end
|
76
81
|
logger.debug("Irie::Extensions::QueryIncludes.resource") if ::Irie.debug?
|
77
82
|
this_includes = self.action_to_query_includes[params[:action].to_sym] || self.all_action_query_includes
|
78
83
|
if this_includes && this_includes.size > 0
|
@@ -88,6 +93,11 @@ module Irie
|
|
88
93
|
end
|
89
94
|
|
90
95
|
def build_resource
|
96
|
+
cached = get_resource_ivar
|
97
|
+
if cached
|
98
|
+
logger.debug("Irie::Extensions::QueryIncludes.resource returning cached resource") if ::Irie.debug?
|
99
|
+
return cached
|
100
|
+
end
|
91
101
|
logger.debug("Irie::Extensions::QueryIncludes.build_resource") if ::Irie.debug?
|
92
102
|
this_includes = self.action_to_query_includes[params[:action].to_sym] || self.all_action_query_includes
|
93
103
|
if this_includes && this_includes.size > 0
|
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.0.1
|
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: 2013-12-
|
12
|
+
date: 2013-12-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: inherited_resources
|