occi-cli 4.2.2 → 4.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/occi/cli/resource_output_factory.rb +34 -4
- data/lib/occi/cli/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a16a411983d56d7c65b82929c86736782afa9095
|
4
|
+
data.tar.gz: aa72b75779620093adad0a8570f23af6ba29e4f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd7b8a10ef380ddf2cce77f925122c4c300a099e89141880fac1825ed4d4570b52e4946378782fd2b5b13f4528411068c32aa5667c788d5f390da287ecba9699
|
7
|
+
data.tar.gz: 3e2cf4d7c6170ca32ead56492c1d6ce0ab650972a69de2cadb5d48f60c27c523ba4e0477a68b17084624552c331105f7a853c3ccbabd90e2b9272feae63012cf
|
@@ -5,7 +5,7 @@ module Occi::Cli
|
|
5
5
|
|
6
6
|
class ResourceOutputFactory
|
7
7
|
|
8
|
-
@@allowed_formats = [:json, :plain, :json_pretty].freeze
|
8
|
+
@@allowed_formats = [:json, :plain, :json_pretty, :json_extended, :json_extended_pretty].freeze
|
9
9
|
|
10
10
|
attr_reader :output_format
|
11
11
|
|
@@ -43,14 +43,20 @@ module Occi::Cli
|
|
43
43
|
# generate JSON document from Occi::Core::Resources
|
44
44
|
occi_resources = occi_resources.to_a
|
45
45
|
|
46
|
-
if @output_format
|
46
|
+
if @output_format.to_s.end_with? '_pretty'
|
47
47
|
output_first = "[\n"
|
48
|
-
output_ary = occi_resources.collect
|
48
|
+
output_ary = occi_resources.collect do |r|
|
49
|
+
local_hash = @output_format.to_s.include?('_extended') ? extended_json(r) : r.as_json.to_hash
|
50
|
+
JSON.pretty_generate(local_hash)
|
51
|
+
end
|
49
52
|
separator = ",\n"
|
50
53
|
output_last = "\n]"
|
51
54
|
else
|
52
55
|
output_first = "["
|
53
|
-
output_ary = occi_resources.collect
|
56
|
+
output_ary = occi_resources.collect do |r|
|
57
|
+
local_hash = @output_format.to_s.include?('_extended') ? extended_json(r) : r.as_json.to_hash
|
58
|
+
JSON.generate(local_hash)
|
59
|
+
end
|
54
60
|
separator = ","
|
55
61
|
output_last = "]"
|
56
62
|
end
|
@@ -63,6 +69,28 @@ module Occi::Cli
|
|
63
69
|
alias_method :mixins_to_json, :resources_to_json
|
64
70
|
alias_method :mixins_to_json_pretty, :resources_to_json
|
65
71
|
|
72
|
+
alias_method :resources_to_json_extended, :resources_to_json
|
73
|
+
alias_method :resources_to_json_extended_pretty, :resources_to_json
|
74
|
+
alias_method :links_to_json_extended, :resources_to_json
|
75
|
+
alias_method :links_to_json_extended_pretty, :resources_to_json
|
76
|
+
alias_method :mixins_to_json_extended, :resources_to_json
|
77
|
+
alias_method :mixins_to_json_extended_pretty, :resources_to_json
|
78
|
+
|
79
|
+
# Renders Occi::Core::Links as a full JSON, not just a String
|
80
|
+
# array.
|
81
|
+
#
|
82
|
+
# @param resource [Occi::Core::Resource] resource to be rendered into extended JSON
|
83
|
+
# @return [Hash] extended JSON represented as a Hash instance
|
84
|
+
def extended_json(resource)
|
85
|
+
return resource.as_json.to_hash unless resource.respond_to?(:links)
|
86
|
+
return resource.as_json.to_hash unless resource.links.kind_of?(Occi::Core::Links)
|
87
|
+
|
88
|
+
links = resource.links
|
89
|
+
ext_json = resource.as_json
|
90
|
+
ext_json.links = links.as_json
|
91
|
+
ext_json.to_hash
|
92
|
+
end
|
93
|
+
|
66
94
|
def locations_to_json(url_locations)
|
67
95
|
# generate JSON document from an array of strings
|
68
96
|
if @output_format == :json_pretty
|
@@ -72,6 +100,8 @@ module Occi::Cli
|
|
72
100
|
end
|
73
101
|
end
|
74
102
|
alias_method :locations_to_json_pretty, :locations_to_json
|
103
|
+
alias_method :locations_to_json_extended_pretty, :locations_to_json
|
104
|
+
alias_method :locations_to_json_extended, :locations_to_json
|
75
105
|
|
76
106
|
def resources_to_plain(occi_resources)
|
77
107
|
# using ERB templates for known resource types
|
data/lib/occi/cli/version.rb
CHANGED