introspective_grape 0.2.3 → 0.2.4

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: c030a296ffbf221b0efa559f3e7e6ab2d30afae4
4
- data.tar.gz: 9eb9b3edc3fa75e0204de34d1b704700ed08f621
3
+ metadata.gz: 83d87bcd4a1b094140084f652e87311d763b4259
4
+ data.tar.gz: ad9cc7c59b4675a4b105e656c3bc82e7a6db2b45
5
5
  SHA512:
6
- metadata.gz: 1423ab9e477c4f022d0ddcb424ffccca23a778d393eb43cbaa060b86a5e11d366130227230686aedb4258a139d68577adfbde889531d4a6606e0d0938a477c8b
7
- data.tar.gz: c683edd9b8fc4733e0cc05901e77775c4ef9a40997c44d8a81a7e5d357918decd12f0142e30fd9ec770a768db950e1928d4fcc263490a77527cb64bea4402994
6
+ metadata.gz: d1e241e2e6b14512efe1b3da193f3a382def1c7a953dc9790d4b6680f68b1168b2397d45be5a09e2641eb7b5e5a392f31e42a37148aec9e394e40a176c25b8cf
7
+ data.tar.gz: aa769217ebffabc67b73732108c7e56c77482e6bd48a6ff8b929f35bfd3491f99ea3881b08f2c02e8534957add7941687a47b7bf81db5b5a4963df7e86d588da
data/CHANGELOG.md CHANGED
@@ -1,4 +1,15 @@
1
1
 
2
+ 0.2.4 10/26/2016
3
+ ==============
4
+
5
+ ### Bug Fix
6
+
7
+ Validate the presence of required belongs_to associations.
8
+
9
+ ### Features
10
+
11
+ Add a default_sort for the index action option, rather than relying on custom_filters or a default_scope.
12
+
2
13
  0.2.3 10/21/2016
3
14
  ==============
4
15
  ### Bug Fix
@@ -397,9 +397,12 @@ module IntrospectiveGrape
397
397
  end
398
398
 
399
399
  def param_required?(model,f)
400
- return false if skip_presence_validations.include? f
401
400
  # Detect if the field is a required field for the create action
402
- model.validators_on(f.to_sym).any?{|v| v.kind_of? ActiveRecord::Validations::PresenceValidator }
401
+ return false if skip_presence_validations.include? f
402
+
403
+ validated_field = (f =~ /_id/) ? f.to_s.sub(/_id\z/,'').to_sym : f.to_sym
404
+
405
+ model.validators_on(validated_field).any? {|v| v.kind_of? ActiveRecord::Validations::PresenceValidator }
403
406
  end
404
407
 
405
408
  def add_destroy_param(dsl,model,reflection)
@@ -4,6 +4,10 @@ module IntrospectiveGrape::Filters
4
4
  # customer filters for the index in a method.
5
5
  #
6
6
 
7
+ def default_sort(*args)
8
+ @default_sort ||= args
9
+ end
10
+
7
11
  def custom_filter(*args)
8
12
  custom_filters( *args )
9
13
  end
@@ -72,6 +76,8 @@ module IntrospectiveGrape::Filters
72
76
  end
73
77
 
74
78
  def apply_filter_params(klass, model, api_params, params, records)
79
+ records = records.order(default_sort) if default_sort.present?
80
+
75
81
  simple_filters(klass, model, api_params).each do |field|
76
82
  next if params[field].blank?
77
83
 
@@ -1,3 +1,3 @@
1
1
  module IntrospectiveGrape
2
- VERSION = "0.2.3".freeze
2
+ VERSION = "0.2.4".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: introspective_grape
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Buermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-21 00:00:00.000000000 Z
11
+ date: 2016-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails