nazar 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/nazar/formatter/active_record_collection.rb +1 -1
- data/lib/nazar/formatter/struct.rb +13 -6
- data/lib/nazar/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9ec818a6ac5c3b06e2544c97f8af1239fc25489f3098f9ca93557458a84d3aa6
|
4
|
+
data.tar.gz: febf9e37e281d3443d5d89924584d59383faa813cb8e346700355eae0ecc3975
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b236ed7da8a4aceb2c60de3ec716b65af4ff823899bd5194613f6cb264396722c31d90903a30a7482a5b6426b2fe0ffa6dca89e8fa412532f46f66dd919a123
|
7
|
+
data.tar.gz: 2a0e0ac62a27f00ff1a36f9422ef4ed2ac9f86621ad3533b4b62b25080f598f19249b3584500f1e5a0f3dfda23150227320bba0a52bb950388e214bc3310ddb3
|
@@ -16,7 +16,7 @@ module Nazar
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.valid?(data)
|
19
|
-
return false if data.is_a?(Struct) || (defined?(OpenStruct) && data.is_a?(OpenStruct))
|
19
|
+
return false if data.is_a?(::Struct) || (defined?(OpenStruct) && data.is_a?(OpenStruct))
|
20
20
|
|
21
21
|
data.is_a?(ActiveRecord::Associations::CollectionProxy) ||
|
22
22
|
data.is_a?(ActiveRecord::Relation) ||
|
@@ -4,30 +4,37 @@ module Nazar
|
|
4
4
|
module Formatter
|
5
5
|
class Struct
|
6
6
|
def initialize(item)
|
7
|
-
@collection = Array
|
8
|
-
@attributes =
|
9
|
-
@item = item
|
7
|
+
@collection = item.is_a?(Array) ? item : [item]
|
8
|
+
@attributes = @collection.first.to_h.keys
|
10
9
|
end
|
11
10
|
|
12
11
|
def self.valid?(data)
|
12
|
+
valid_struct?(data) || (data.is_a?(Array) && data.all? { valid_struct?(_1) })
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.valid_struct?(data)
|
13
16
|
data.is_a?(::Struct) || data.is_a?(::OpenStruct)
|
14
17
|
end
|
15
18
|
|
16
19
|
def valid?
|
17
|
-
|
20
|
+
@attributes.any?
|
18
21
|
end
|
19
22
|
|
20
23
|
def headers
|
21
|
-
HeadersFormatter.new(attributes).format
|
24
|
+
HeadersFormatter.new(@attributes).format
|
22
25
|
end
|
23
26
|
|
24
27
|
def cells
|
25
28
|
@cells ||= @collection.map do |item|
|
26
|
-
item.
|
29
|
+
item.to_h.values.map do |value|
|
27
30
|
CellFormatter.new(value, type: nil).format
|
28
31
|
end
|
29
32
|
end
|
30
33
|
end
|
34
|
+
|
35
|
+
def summary
|
36
|
+
false
|
37
|
+
end
|
31
38
|
end
|
32
39
|
end
|
33
40
|
end
|
data/lib/nazar/version.rb
CHANGED