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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c3460b007c73f49d972231031c2281279b6a643
4
- data.tar.gz: 0a6c442e63f9a7f83d89a98c43dcb141a5662cfe
3
+ metadata.gz: a16a411983d56d7c65b82929c86736782afa9095
4
+ data.tar.gz: aa72b75779620093adad0a8570f23af6ba29e4f1
5
5
  SHA512:
6
- metadata.gz: 79b151912c6f2fa4b25de3de8c019ae43a7912f11f34b0292753fcf98435563112dd2f9a3f5fd6bcad2ca729f5d2eae43ba6e32caa8e1e88289f5ce055fc426a
7
- data.tar.gz: 26bbc79dc416569b9367bee04d640ba395f59eafffe6643ad460374417a515727c5dae5281233bfc1ebc394389534337e5621a9ae9c74e36d9e926a7d35475e1
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 == :json_pretty
46
+ if @output_format.to_s.end_with? '_pretty'
47
47
  output_first = "[\n"
48
- output_ary = occi_resources.collect { |r| JSON.pretty_generate(r.as_json.to_hash) }
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 { |r| JSON.generate(r.as_json.to_hash) }
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
@@ -1,5 +1,5 @@
1
1
  module Occi
2
2
  module Cli
3
- VERSION = "4.2.2" unless defined?(::Occi::Cli::VERSION)
3
+ VERSION = "4.2.3" unless defined?(::Occi::Cli::VERSION)
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: occi-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.2
4
+ version: 4.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Feldhaus