katalyst-tables 3.4.4 → 3.4.5
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc68e986f0047e4a30844861ec4cf0222649fa9635ca59a466846862090033da
|
4
|
+
data.tar.gz: fc12160c9acca555b6d5041ef49170af9630e8f6e67f81d6bec32564105e963a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d4334a6bb9b7edd4092ff131cc59a6e43ee9ce66c48c29c6aa5725585914da6c6b94e9e8cb9aa3babd8bcdaf35f24b3fc83f3d861f04e2a6294af6a8f8e3de0
|
7
|
+
data.tar.gz: 4a4a96c779a4ad08d0a5e1a4b415b465eb85a22b071d40321dd85f49856b372b63fd5a64ad41719a38d8bd282146eedb11982ca7821237f8ade93271b6de19d5
|
@@ -26,15 +26,30 @@ module Katalyst
|
|
26
26
|
keys = keys.select { |key| key.include?(attribute.value_before_type_cast.last) }
|
27
27
|
end
|
28
28
|
|
29
|
-
keys.map { |key| example(key, describe_key(model, attribute
|
29
|
+
keys.map { |key| example(key, describe_key(model, attribute, key)) }
|
30
30
|
end
|
31
31
|
|
32
32
|
private
|
33
33
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
34
|
+
def cast_value(value)
|
35
|
+
value.to_s
|
36
|
+
end
|
37
|
+
|
38
|
+
def describe_key(model, attribute, key)
|
39
|
+
label = model.human_attribute_name(attribute.name).downcase
|
40
|
+
value = model.human_attribute_name("#{attribute.name}.#{key}").downcase
|
41
|
+
|
42
|
+
description = "#{model.model_name.human} #{label} is #{value}"
|
43
|
+
description += " (default)" if default?(attribute, key)
|
44
|
+
description
|
45
|
+
end
|
46
|
+
|
47
|
+
def default?(attribute, value)
|
48
|
+
if multiple?
|
49
|
+
attribute.original_value&.intersection(cast(value))&.any?
|
50
|
+
else
|
51
|
+
attribute.default_value.eql?(cast(value))
|
52
|
+
end
|
38
53
|
end
|
39
54
|
end
|
40
55
|
end
|
@@ -48,7 +48,10 @@ module Katalyst
|
|
48
48
|
def examples_for(scope, attribute, limit: 10, order: :asc)
|
49
49
|
scope, model, column = model_and_column_for(scope, attribute)
|
50
50
|
|
51
|
-
|
51
|
+
unless model.attribute_types.has_key?(column)
|
52
|
+
raise(ArgumentError, "Unknown column '#{column}' for #{model}. " \
|
53
|
+
"Consider defining '#{attribute.name.parameterize.underscore}_examples'")
|
54
|
+
end
|
52
55
|
|
53
56
|
column = model.arel_table[column]
|
54
57
|
|