eitil 1.1.22 → 1.1.23

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
  SHA256:
3
- metadata.gz: e42a5a3d86d85421291822209dfe66ee5f12d70cf25abf2faa21a80a53ccc5e1
4
- data.tar.gz: 2c267374fb18f64fd63766704936acf41df313e27cc3b8be92e993a2ad229bf4
3
+ metadata.gz: 2898766e78bb6b5706c24111deb28ee19f479a45f7d475d05d096843eb1cb748
4
+ data.tar.gz: 6240c052572bd8d9cf269c266863e5556e601f360ca99b8aaecc3a002daf7365
5
5
  SHA512:
6
- metadata.gz: de0c459606a7d746f3b68a15db80033cd41790ea9d24f3fc0b2db4a23986de9e82fef4a36bfd7daadc832b694acd85333ded21847958b988449c27623b5a1adc
7
- data.tar.gz: 8637f56a686e47d6e89020b68ecb3535a7094f87ed5023b89870e711970db80971eb1f93818e899c29d3181f4184462b17c27e136f9e56ca2934636807542db9
6
+ metadata.gz: 738bff100d4821b81d50a4f3b64bdd41b7d39ebc8dab0ee49a4124c51e6a35428f50f44a9c8cc14aaa5a8998edbc5446b517b09ccf47dafb44e2d64569a9d1ac
7
+ data.tar.gz: 40fb5472c8dafdf3e63e7ecea76f904467997100ee78e080cf8e384544bb8a9e488d1f0a0adb293a67fe182072fa2e144acf201b259db7f293fad006c457def2
data/eitil_core/README.md CHANGED
@@ -15,11 +15,14 @@ require "eitil_core/active_record"
15
15
  ```
16
16
 
17
17
  ```ruby
18
- # require "eitil_core/active_record/hash_to_relation"
18
+ # require "eitil_core/active_record/array_to_relation"
19
19
 
20
- [].to_relation
20
+ [].to_relation(fallback_class = ApplicationRecord)
21
21
  # converts an array of ActiveRecord instances to an ActiveRecord_Relation instance
22
22
  # call as: [#<instance1>,<instance2>].to_relation
23
+
24
+ # if the object is an empty array, the intended class cannot be derived from the object, so in order to
25
+ # prevent NoMethodError's you can optionally pass a fallback class which will be used to create an empty association
23
26
  ```
24
27
 
25
28
  ## ApplicationController
@@ -1,2 +1,2 @@
1
1
 
2
- require "eitil_core/active_record/hash_to_relation"
2
+ require "eitil_core/active_record/array_to_relation"
@@ -1,18 +1,18 @@
1
1
 
2
- # require "eitil_core/active_record/hash_to_relation"
2
+ # require "eitil_core/active_record/array_to_relation"
3
3
 
4
4
  require "eitil_core/errors/raise_error"
5
5
 
6
6
  class Array
7
7
 
8
- def to_relation
8
+ def to_relation(fallback_class = ApplicationRecord)
9
9
 
10
10
  # Return an empty ActiveRecord_Relation instance when no objects are present,
11
11
  # instead of returning the empty array itself. The reason being, that when you
12
12
  # always return an association, you won't run into problems with undefined methods
13
13
  # called later on, expecting an association instead of an array.
14
14
 
15
- return ApplicationRecord.none unless self.present?
15
+ return fallback_class.none unless self.present?
16
16
 
17
17
  unless self.all? { |item| item.class.ancestors.include? ApplicationRecord }
18
18
  raise_error "InvalidArrayError", ".to_relation requires that all array items are model instances"
@@ -5,7 +5,7 @@ module EitilWrapper
5
5
 
6
6
  def decorate(dec_item, dec_method: nil, dec_class: nil, **dec_kwargs)
7
7
  all_args_to_ivars binding
8
- set_ivars :dec_class, :dec_method, :decorator
8
+ set_ivars :dec_class, :decorator, :dec_method
9
9
  send_to_decorator
10
10
  end
11
11
 
@@ -29,9 +29,9 @@ module EitilWrapper
29
29
  end
30
30
 
31
31
  def derived_dec_method
32
- return unless respond_to? :params
33
- return :app if params["isMobile"]
34
- return :web if params["isWeb"]
32
+ return unless respond_to? :params
33
+ return :app if @decorator.respond_to?(:app) && params["isMobile"]
34
+ return :web if @decorator.respond_to?(:web) && params["isWeb"]
35
35
  end
36
36
 
37
37
  def set_dec_class
@@ -47,7 +47,7 @@ module EitilWrapper
47
47
  end
48
48
 
49
49
  def set_decorator
50
- @decorator = @dec_class.new controller_ivars
50
+ @dec_class.new ivars
51
51
  end
52
52
 
53
53
  def controller_ivars
@@ -56,5 +56,9 @@ module EitilWrapper
56
56
  end.inject &:merge
57
57
  end
58
58
 
59
+ def ivars
60
+ @dec_kwargs ? controller_ivars.merge(@dec_kwargs) : controller_ivars
61
+ end
62
+
59
63
  end
60
64
  end
data/lib/eitil/railtie.rb CHANGED
@@ -29,6 +29,8 @@ module Eitil
29
29
 
30
30
  mattr_accessor :controller_ivars
31
31
 
32
+ self.controller_ivars ||= []
33
+
32
34
  def self.set_config(&block)
33
35
  yield self
34
36
  end
data/lib/eitil/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Eitil
2
2
 
3
- VERSION = '1.1.22'
3
+ VERSION = '1.1.23'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eitil
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.22
4
+ version: 1.1.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jurriaan Schrofer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-08-03 00:00:00.000000000 Z
11
+ date: 2021-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -83,7 +83,7 @@ files:
83
83
  - eitil_core/README.md
84
84
  - eitil_core/lib/eitil_core.rb
85
85
  - eitil_core/lib/eitil_core/active_record.rb
86
- - eitil_core/lib/eitil_core/active_record/hash_to_relation.rb
86
+ - eitil_core/lib/eitil_core/active_record/array_to_relation.rb
87
87
  - eitil_core/lib/eitil_core/application_controller.rb
88
88
  - eitil_core/lib/eitil_core/application_controller/permit_model_atts.rb
89
89
  - eitil_core/lib/eitil_core/application_controller/slice_params.rb