material 0.2.21 → 0.2.22

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: 9ae59554fed28abb2569c2b32b6bbca5575d60c5af44a7e5830007d8ef49c357
4
- data.tar.gz: 1bf61511f2eb3064d965c1c3a5be255087159d99dddcecbfb7f0d4f90e9b5a66
3
+ metadata.gz: f1c068082b23728d7529c57e25c8219de1622454fc4c0fb3d003d5edc579620b
4
+ data.tar.gz: 63289acc7d4808c010117e421b59c8503dc409ad212d3affc33da6296bf50bd2
5
5
  SHA512:
6
- metadata.gz: 025bb61f457490ad7022ec151cde12440c9dfc6b1cb6c1c75796004b3b53b5e7a96a94c538c327c4fb744fa6480aaadd16fc16e98297c3cae5cf4dcbcd8df90f
7
- data.tar.gz: 8b35d548680cacbcea1e2c7ed8faf23193e064011d02add633cf84c53f8a2d559a39bc0486b102ea1ef00f97c3aa64c2d42099fd90a7fd2add5a821c22d4a688
6
+ metadata.gz: 68a519e6a5af1e0bb0bbdaaa83267de587bdfca0d4c65415e77ed3f68823eab5720f0e59694079a91fcf3eb1d56d02c07e66dfb431062892df908f99418c26d2
7
+ data.tar.gz: 7b54cf5e1fc6ac7daec66628bcd23cb6954611031ec933bc14633abb6cdeeb573f3dcb5c6503aa2ee9ad6cb0bd456bbc63abd80af66406d8f2c9e0d49d7864fc
data/lib/material/base.rb CHANGED
@@ -4,20 +4,27 @@ module Material
4
4
  class Base < Spicerack::AttributeObject
5
5
  extend ActiveSupport::NumberHelper
6
6
 
7
+ include Conjunction::Junction
8
+ suffixed_with "Material"
9
+
7
10
  include Material::Components
8
11
  include Material::Core
9
12
  include Material::Display
10
13
  include Material::Text
11
14
  include Material::Site
12
- include Material::For
13
15
  include Material::Format
14
16
  include Material::Attributes
15
17
 
16
18
  register_component :list_item_style
17
19
 
18
- def self.for(object)
19
- material_class = material_class_for(object, "Material")
20
- material_class.new(object) if material_class.present?
20
+ class << self
21
+ def for(object)
22
+ for_class(object)&.new(object)
23
+ end
24
+
25
+ def for_class(object)
26
+ object.try(:conjugate!, self)
27
+ end
21
28
  end
22
29
 
23
30
  def to_source_model
@@ -30,7 +30,7 @@ module Material
30
30
  ary = super
31
31
  return ary if ary.empty?
32
32
 
33
- material_class = self.class.material_class_for(ary.first, "Material")
33
+ material_class = ary.first.try(:conjugate, Material::Base)
34
34
  material_class.nil? ? ary : ary.map(&material_class.method(:new))
35
35
  end
36
36
  end
data/lib/material/list.rb CHANGED
@@ -2,11 +2,13 @@
2
2
 
3
3
  module Material
4
4
  class List < Collectible::CollectionBase
5
+ include Conjunction::Junction
6
+ suffixed_with "List"
7
+
5
8
  include Material::Components
6
9
  include Material::Display
7
10
  include Material::Text
8
11
  include Material::Site
9
- include Material::For
10
12
  include Material::Pagination
11
13
  include Material::Mount
12
14
  include Material::Collection
@@ -14,8 +16,20 @@ module Material
14
16
 
15
17
  class << self
16
18
  def for(object)
17
- material_class = material_class_for(object, "List")
18
- material_class.new if material_class.present?
19
+ klass = for_class(object.respond_to?(:first) ? object.first : object)
20
+ materialize(object, klass) if klass.present?
21
+ end
22
+
23
+ def for_class(object)
24
+ object.try(:conjugate!, self)
25
+ end
26
+
27
+ private
28
+
29
+ def materialize(object, klass)
30
+ return klass.new(object) if object.present? && !object.is_a?(Class)
31
+
32
+ klass.new
19
33
  end
20
34
  end
21
35
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Material
4
- VERSION = "0.2.21"
4
+ VERSION = "0.2.22"
5
5
  end
data/lib/material.rb CHANGED
@@ -4,14 +4,13 @@ require "active_support"
4
4
  require "active_support/core_ext"
5
5
  require "active_support/number_helper"
6
6
 
7
- require "spicerack"
7
+ require "spicery"
8
8
 
9
9
  require_relative "material/concerns/components"
10
10
  require_relative "material/concerns/core"
11
11
  require_relative "material/concerns/display"
12
12
  require_relative "material/concerns/text"
13
13
  require_relative "material/concerns/site"
14
- require_relative "material/concerns/for"
15
14
  require_relative "material/concerns/pagination"
16
15
  require_relative "material/concerns/mount"
17
16
  require_relative "material/concerns/collection"
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.21
4
+ version: 0.2.22
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-10-11 00:00:00.000000000 Z
11
+ date: 2020-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -25,12 +25,12 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 5.2.1
27
27
  - !ruby/object:Gem::Dependency
28
- name: spicerack
28
+ name: spicery
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.16.2
33
+ version: 0.20.4
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
36
  version: '1.0'
@@ -40,7 +40,7 @@ dependencies:
40
40
  requirements:
41
41
  - - ">="
42
42
  - !ruby/object:Gem::Version
43
- version: 0.16.2
43
+ version: 0.20.4
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '1.0'
@@ -58,20 +58,6 @@ dependencies:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: 2.0.1
61
- - !ruby/object:Gem::Dependency
62
- name: faker
63
- requirement: !ruby/object:Gem::Requirement
64
- requirements:
65
- - - "~>"
66
- - !ruby/object:Gem::Version
67
- version: '1.8'
68
- type: :development
69
- prerelease: false
70
- version_requirements: !ruby/object:Gem::Requirement
71
- requirements:
72
- - - "~>"
73
- - !ruby/object:Gem::Version
74
- version: '1.8'
75
61
  - !ruby/object:Gem::Dependency
76
62
  name: pry-byebug
77
63
  requirement: !ruby/object:Gem::Requirement
@@ -100,20 +86,6 @@ dependencies:
100
86
  - - "~>"
101
87
  - !ruby/object:Gem::Version
102
88
  version: '10.0'
103
- - !ruby/object:Gem::Dependency
104
- name: rspec
105
- requirement: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - "~>"
108
- - !ruby/object:Gem::Version
109
- version: '3.0'
110
- type: :development
111
- prerelease: false
112
- version_requirements: !ruby/object:Gem::Requirement
113
- requirements:
114
- - - "~>"
115
- - !ruby/object:Gem::Version
116
- version: '3.0'
117
89
  - !ruby/object:Gem::Dependency
118
90
  name: simplecov
119
91
  requirement: !ruby/object:Gem::Requirement
@@ -148,7 +120,7 @@ dependencies:
148
120
  requirements:
149
121
  - - ">="
150
122
  - !ruby/object:Gem::Version
151
- version: 0.16.2
123
+ version: 0.20.4
152
124
  - - "<"
153
125
  - !ruby/object:Gem::Version
154
126
  version: '1.0'
@@ -158,7 +130,7 @@ dependencies:
158
130
  requirements:
159
131
  - - ">="
160
132
  - !ruby/object:Gem::Version
161
- version: 0.16.2
133
+ version: 0.20.4
162
134
  - - "<"
163
135
  - !ruby/object:Gem::Version
164
136
  version: '1.0'
@@ -168,7 +140,7 @@ dependencies:
168
140
  requirements:
169
141
  - - ">="
170
142
  - !ruby/object:Gem::Version
171
- version: 0.16.2
143
+ version: 0.20.4
172
144
  - - "<"
173
145
  - !ruby/object:Gem::Version
174
146
  version: '1.0'
@@ -178,7 +150,7 @@ dependencies:
178
150
  requirements:
179
151
  - - ">="
180
152
  - !ruby/object:Gem::Version
181
- version: 0.16.2
153
+ version: 0.20.4
182
154
  - - "<"
183
155
  - !ruby/object:Gem::Version
184
156
  version: '1.0'
@@ -213,7 +185,6 @@ files:
213
185
  - lib/material/concerns/components.rb
214
186
  - lib/material/concerns/core.rb
215
187
  - lib/material/concerns/display.rb
216
- - lib/material/concerns/for.rb
217
188
  - lib/material/concerns/format.rb
218
189
  - lib/material/concerns/mount.rb
219
190
  - lib/material/concerns/pagination.rb
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Build materials from objects based either an explicit definition or an optimistic lookup
4
- module Material
5
- module For
6
- extend ActiveSupport::Concern
7
-
8
- class_methods do
9
- def material_class_for(object, subtype)
10
- method = "#{subtype.downcase}_class".to_sym
11
- object_class = object.is_a?(Class) ? object : object.class
12
- lookup(object, method) || lookup(object_class, method) || "#{object_class.name}#{subtype}".safe_constantize
13
- end
14
-
15
- private
16
-
17
- def lookup(object, lookup_name)
18
- object.public_send(lookup_name) if object.respond_to?(lookup_name)
19
- end
20
- end
21
- end
22
- end