snaptable 2.2.2 → 2.2.3
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 +4 -4
- data/lib/snaptable/constructor/renderer.rb +12 -9
- data/lib/snaptable/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b0203c800bc07e68796bd21371315d3ad87d083f0431d2c9aa42b7b856dde471
|
4
|
+
data.tar.gz: 5c33e463f36a732c9091f379ced36caf3d2e105cb5c080cdff1879cd022c6506
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c76e95b4382399619cbe008fe107ee9f2c3ecb1c0e519d5afce71993e932c0f9c717afaf405d1b897ba1a633ee9dae8da53a371ac60d40417037486b20c8466b
|
7
|
+
data.tar.gz: 28736105c9c34676597409ab2e32b1c042d77be09cdbab4c354dd062085dfca9acd97482ab177887ac920b9caccbe370a551ff10094cc9bcfcccbbf96eb3b540
|
@@ -28,27 +28,30 @@ module Snaptable
|
|
28
28
|
|
29
29
|
def values(element)
|
30
30
|
attributes.map do |attribute|
|
31
|
-
|
32
|
-
element.send(attribute)
|
33
|
-
else
|
34
|
-
element.send(
|
31
|
+
if attribute.is_a?(Symbol) || attribute.is_a?(String)
|
32
|
+
attr_value = element.send(attribute)
|
33
|
+
else # a hash { model: :attribute }
|
34
|
+
attr_value = element.send(attribute.keys[0]).send(attribute.values[0])
|
35
|
+
attr_model = attribute.keys[0].to_s.capitalize.constantize
|
36
|
+
attribute = attribute.values[0]
|
35
37
|
end
|
36
|
-
format(attribute, attr_value)
|
38
|
+
format(attribute, attr_value, attr_model)
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
40
|
-
def format(attribute, attr_value)
|
42
|
+
def format(attribute, attr_value, attr_model)
|
43
|
+
attr_model ||= model
|
41
44
|
if attr_value.is_a?(Date) || attr_value.is_a?(Time) || attr_value.is_a?(DateTime)
|
42
45
|
attr_value = l(attr_value, format: :snaptable)
|
43
|
-
elsif !attr_value.nil? && attribute.to_s.in?(enums)
|
44
|
-
attr_value = t("#{
|
46
|
+
elsif !attr_value.nil? && attribute.to_s.in?(enums(attr_model))
|
47
|
+
attr_value = t("#{attr_model.model_name.i18n_key}.#{attribute.to_s.pluralize}.#{attr_value}")
|
45
48
|
end
|
46
49
|
attr_value = view_context.strip_tags(attr_value.to_s)
|
47
50
|
attr_value = view_context.truncate(attr_value, length: 40) unless options[:truncate] == false
|
48
51
|
return attr_value
|
49
52
|
end
|
50
53
|
|
51
|
-
def enums
|
54
|
+
def enums(model)
|
52
55
|
model.defined_enums.keys
|
53
56
|
end
|
54
57
|
|
data/lib/snaptable/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snaptable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- khcr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-02-
|
11
|
+
date: 2019-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|