cavalry 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 967d285751a7b9c490680cbfc6291dab9e9cbb43
4
- data.tar.gz: 1b87f1ff8ef5d2749b57572d07dd9cb0c8cfa68a
3
+ metadata.gz: 9763a2b4bcd9e562d4bfa8c59a5ce211fe0b7a20
4
+ data.tar.gz: f0eb71747bd13a3477e3e08e8b1c81a70763ffc1
5
5
  SHA512:
6
- metadata.gz: '008f80c63a66b341afc6d372474ae7cc90d47c67ff21124063345b2d58c6bf2c23a5a2db83b72b01de9ec9477eb201e6841f2654b16e53c43d99908758cd576c'
7
- data.tar.gz: cfeb4852f8614f9b4f1823d49bc79be93445af6f8522fa390eeef9a74a858dab697b4e3845b1f76e559573e9c1291c51305f02f028a16dbaf1677a0260eb83fa
6
+ metadata.gz: 36d25a4617c14b01bb2119eb3e2309850099fc6952b755dd08d986bbad6e4fb80ce4faf943a67810a7d8c3aaee9a23568061bd8b2fa058f88a03b1eaaef78b7a
7
+ data.tar.gz: 03b927eb79f1f2538751e33c4783eb97aef4df18d043eccfd39762d105485c06900269c89036911fe3aad7bb56d0dfa6c5e75fce06c0c4b8e1239ece61eab06f
data/lib/cavalry.rb CHANGED
@@ -22,15 +22,14 @@ module Cavalry
22
22
  errors.blank?
23
23
  end
24
24
 
25
+ def config
26
+ @config ||= Config.new
27
+ end
25
28
 
26
29
  private
27
30
 
28
31
  def client
29
32
  @client ||= Client.new(config)
30
33
  end
31
-
32
- def config
33
- @config ||= Config.new
34
- end
35
34
  end
36
35
  end
@@ -6,6 +6,8 @@ module Cavalry
6
6
  # Defines validator definition path. files required with **/*.rb
7
7
  mattr_accessor :validators_path
8
8
 
9
+ mattr_accessor :force_check_belongs_to_association
10
+
9
11
  def load_models
10
12
  load_rb_files(models_path)
11
13
  end
@@ -9,6 +9,7 @@ module Cavalry
9
9
  end
10
10
 
11
11
  def validate
12
+ install_force_check_belongs_to_association if Cavalry.config.force_check_belongs_to_association && @source_class.respond_to?(:reflections)
12
13
  source_class.all.flat_map {|record| validate_record(record) }.compact
13
14
  end
14
15
 
@@ -18,6 +19,16 @@ module Cavalry
18
19
  return if record.valid?
19
20
  record
20
21
  end
22
+
23
+ def install_force_check_belongs_to_association
24
+ return unless defined?(ActiveRecord::Reflection::BelongsToReflection)
25
+
26
+ @source_class.class_eval do
27
+ reflections.values.select { |r| r.is_a?(ActiveRecord::Reflection::BelongsToReflection) }.each do |r|
28
+ validates r.name, presence: true
29
+ end
30
+ end
31
+ end
21
32
  end
22
33
  end
23
34
  end
@@ -1,3 +1,3 @@
1
1
  module Cavalry
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cavalry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Masashi AKISUE
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-18 00:00:00.000000000 Z
11
+ date: 2017-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel