material 0.2.11 → 0.2.12

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: ed245f0f0fe5e5166138014bd4a4b9d25be10f8d6962b07933ddb8759fda864f
4
- data.tar.gz: 92c654d62c960e15fdc7d500ab8d9c1fc9424593fea193cee138ef77349bbd11
3
+ metadata.gz: 7b5ded57612bad30122179909d02f23dc9cd6d95d8753b38a34e66e7e63733b7
4
+ data.tar.gz: f0cf9ea4391602a51124e9e31144b09a5411d34d63f482809e16043b7077dbb0
5
5
  SHA512:
6
- metadata.gz: 35d9dd166b68b9a25616c9683d0f61bb4cfb521f9f1890d49578b9cea51077bf801781e414c8425e30007a022d8b4f4c677ff797943d4d28a425beb051fac636
7
- data.tar.gz: 568a26a8db39af7e74eae8d096b1de1a6df0dc0d712a964f7389827835534efdd0b89cf50a68bf4e46482787682827f8cef281614c30b0e157316c0d4585adcd
6
+ metadata.gz: 6a370486799c5418ce9348f9acc4b82bbf0b6acf2dd58a1bcf254547943aec19940d5363fcb9cd56e858f6d036864f69fd021f901ae42cf4d9a161d7ff9e8fe8
7
+ data.tar.gz: 68178b2c5cccb6b1edf9d59eabd1444c4a25b063524da60f094efb7cc282952a3535cc989843237731a18ccc5480c57397dae59f94bdf20125386d88983ef5f4
data/lib/material/base.rb CHANGED
@@ -13,5 +13,13 @@ module Material
13
13
  material_class = material_class_for(object, "Material")
14
14
  material_class.new(object) if material_class.present?
15
15
  end
16
+
17
+ def to_source_model
18
+ source.to_model
19
+ end
20
+
21
+ def to_model
22
+ self
23
+ end
16
24
  end
17
25
  end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Material
4
+ module Collection
5
+ extend ActiveSupport::Concern
6
+
7
+ class_methods do
8
+ def item_class
9
+ return item_enforcement if item_enforcement.is_a?(Class)
10
+
11
+ item_class = superclass.__send__(:item_enforcement) if superclass.respond_to?(:item_enforcement, true)
12
+ return item_class if item_class.present?
13
+
14
+ # Prevents against the case of `Material::List` becoming `Material` and returning a module
15
+ item_class = name.chomp("List").safe_constantize
16
+ item_class if item_class.is_a?(Class)
17
+ end
18
+
19
+ def ensure_item_validity_with
20
+ super || item_class
21
+ end
22
+ end
23
+
24
+ def to_ary
25
+ ary = super
26
+ return ary if ary.empty?
27
+
28
+ material_class = self.class.material_class_for(ary.first, "Material")
29
+ material_class.nil? ? ary : ary.map(&material_class.method(:new))
30
+ end
31
+ end
32
+ end
data/lib/material/list.rb CHANGED
@@ -13,27 +13,13 @@ module Material
13
13
  include Material::For
14
14
  include Material::Pagination
15
15
  include Material::Mount
16
+ include Material::Collection
16
17
 
17
18
  class << self
18
19
  def for(object)
19
20
  material_class = material_class_for(object, "List")
20
21
  material_class.new if material_class.present?
21
22
  end
22
-
23
- def item_class
24
- return item_enforcement if item_enforcement.is_a?(Class)
25
-
26
- item_class = superclass.__send__(:item_enforcement) if superclass.respond_to?(:item_enforcement, true)
27
- return item_class if item_class.present?
28
-
29
- # Prevents against the case of `Material::List` becoming `Material` and returning a module
30
- item_class = name.chomp("List").safe_constantize
31
- item_class if item_class.is_a?(Class)
32
- end
33
-
34
- def ensure_item_validity_with
35
- super || item_class
36
- end
37
23
  end
38
24
 
39
25
  def default_title
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Material
4
- VERSION = "0.2.11"
4
+ VERSION = "0.2.12"
5
5
  end
data/lib/material.rb CHANGED
@@ -12,6 +12,7 @@ require_relative "material/concerns/site"
12
12
  require_relative "material/concerns/for"
13
13
  require_relative "material/concerns/pagination"
14
14
  require_relative "material/concerns/mount"
15
+ require_relative "material/concerns/collection"
15
16
 
16
17
  require "material/version"
17
18
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: material
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.11
4
+ version: 0.2.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Garside
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-09 00:00:00.000000000 Z
11
+ date: 2019-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -208,6 +208,7 @@ files:
208
208
  - README.md
209
209
  - lib/material.rb
210
210
  - lib/material/base.rb
211
+ - lib/material/concerns/collection.rb
211
212
  - lib/material/concerns/components.rb
212
213
  - lib/material/concerns/core.rb
213
214
  - lib/material/concerns/for.rb