razor-client 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS.md +7 -0
- data/lib/razor/cli/document.rb +16 -13
- data/lib/razor/cli/format.rb +2 -2
- data/lib/razor/cli/navigate.rb +11 -15
- data/lib/razor/cli/version.rb +1 -1
- data/lib/razor/cli/views.rb +3 -0
- data/lib/razor/cli/views.yaml +3 -1
- data/spec/cli/document_spec.rb +46 -0
- data/spec/cli/format_spec.rb +0 -5
- metadata +4 -2
data/NEWS.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Razor Client Release Notes
|
2
2
|
|
3
|
+
## 1.3.0 - 2016-05-19
|
4
|
+
|
5
|
+
* NEW: Added elegant display of the `razor config` collection.
|
6
|
+
* IMPROVEMENT: Individual properties in collections can now be scoped.
|
7
|
+
Previously, only arrays and objects were allowed, now you can find
|
8
|
+
a single value.
|
9
|
+
|
3
10
|
## 1.2.0 - 2016-03-08
|
4
11
|
|
5
12
|
* BUGFIX: Razor client version will be reported even if the Razor server is
|
data/lib/razor/cli/document.rb
CHANGED
@@ -4,21 +4,24 @@ module Razor::CLI
|
|
4
4
|
class HideColumnError < RuntimeError; end
|
5
5
|
class Document
|
6
6
|
extend Forwardable
|
7
|
-
attr_reader 'spec', 'items', 'format_view', 'original_items'
|
7
|
+
attr_reader 'spec', 'type', 'items', 'format_view', 'original_items',
|
8
|
+
'command'
|
8
9
|
def initialize(doc, format_type)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@
|
17
|
-
|
18
|
-
|
10
|
+
@type = :single
|
11
|
+
if doc.is_a?(Hash)
|
12
|
+
if doc['+spec'].is_a?(Array)
|
13
|
+
@spec, remaining_navigation = doc['+spec']
|
14
|
+
else
|
15
|
+
@spec = doc['spec']
|
16
|
+
end
|
17
|
+
@command = doc['command']
|
18
|
+
if doc.has_key?('items')
|
19
|
+
@type = :list
|
20
|
+
@items = doc['items']
|
21
|
+
end
|
19
22
|
end
|
20
|
-
@items
|
21
|
-
@format_view = Razor::CLI::Views.find_formatting(@spec, format_type,
|
23
|
+
@items ||= Array[doc]
|
24
|
+
@format_view = Razor::CLI::Views.find_formatting(@spec, format_type, remaining_navigation)
|
22
25
|
|
23
26
|
# Untransformed and unordered for displaying nested views.
|
24
27
|
@original_items = @items
|
data/lib/razor/cli/format.rb
CHANGED
@@ -50,7 +50,7 @@ module Razor::CLI
|
|
50
50
|
# We assume that all collections are homogenous
|
51
51
|
def format_objects(objects, indent = 0)
|
52
52
|
objects.map do |obj|
|
53
|
-
obj.is_a?(Hash) ? format_object(obj, indent) : ' '*indent + obj.
|
53
|
+
obj.is_a?(Hash) ? format_object(obj, indent) : ' '*indent + obj.to_s
|
54
54
|
end.join "\n\n"
|
55
55
|
end
|
56
56
|
|
@@ -143,7 +143,7 @@ module Razor::CLI
|
|
143
143
|
else
|
144
144
|
case f
|
145
145
|
when "spec" then "\"#{Format.spec_name(value)}\""
|
146
|
-
else value.
|
146
|
+
else value.to_s # Could be `false` or `nil` possibly
|
147
147
|
end
|
148
148
|
end
|
149
149
|
end.join "\n"
|
data/lib/razor/cli/navigate.rb
CHANGED
@@ -113,11 +113,11 @@ module Razor::CLI
|
|
113
113
|
obj = @doc.find {|x| x.is_a?(Hash) and x["name"] == key }
|
114
114
|
elsif @doc.is_a?(Hash) && @doc['items'].is_a?(Array)
|
115
115
|
obj = @doc['items'].find {|x| x.is_a?(Hash) and x["name"] == key }
|
116
|
-
elsif @doc.is_a?
|
116
|
+
elsif @doc.is_a?(Hash)
|
117
117
|
obj = @doc[key]
|
118
118
|
end
|
119
119
|
|
120
|
-
raise NavigationError.new(@doc_resource, key, @doc)
|
120
|
+
raise NavigationError.new(@doc_resource, key, @doc) if obj.nil?
|
121
121
|
|
122
122
|
if obj.is_a?(Hash) && obj["id"]
|
123
123
|
url = URI.parse(obj["id"])
|
@@ -125,26 +125,22 @@ module Razor::CLI
|
|
125
125
|
@doc = json_get(url, {}, params)
|
126
126
|
elsif obj.is_a?(Hash) && obj['spec']
|
127
127
|
@doc = obj
|
128
|
-
elsif obj.is_a?(Hash)
|
129
|
-
#
|
128
|
+
elsif obj.is_a?(Hash) || obj.is_a?(Array)
|
129
|
+
# We have reached a data structure that doesn't have a spec string!
|
130
|
+
# This means we should use the parent's string and keep track of which
|
131
|
+
# extra navigation is needed, so we can still format the data
|
132
|
+
# accordingly.
|
130
133
|
if @doc['+spec'].is_a?(Array)
|
131
134
|
# Something's been added.
|
132
135
|
@doc['+spec'] << key
|
133
136
|
elsif @doc['+spec'].nil? || @doc['+spec'].is_a?(String)
|
134
137
|
@doc['+spec'] = [@doc['spec'], key]
|
135
138
|
end
|
136
|
-
@doc = obj.merge({'+spec' => @doc['+spec']})
|
137
|
-
|
138
|
-
|
139
|
-
if @doc['+spec'].is_a?(Array)
|
140
|
-
# Something's already been added.
|
141
|
-
@doc['+spec'] << key
|
142
|
-
elsif @doc['+spec'].nil? || @doc['+spec'].is_a?(String)
|
143
|
-
@doc['+spec'] = [@doc['spec'], key]
|
144
|
-
end
|
145
|
-
@doc = {'+spec' => @doc['+spec'], 'items' => obj}
|
139
|
+
@doc = obj.merge({'+spec' => @doc['+spec']}) if obj.is_a?(Hash)
|
140
|
+
@doc = {'+spec' => @doc['+spec'], 'items' => obj} if obj.is_a?(Array)
|
141
|
+
@doc
|
146
142
|
else
|
147
|
-
@doc =
|
143
|
+
@doc = obj
|
148
144
|
end
|
149
145
|
end
|
150
146
|
|
data/lib/razor/cli/version.rb
CHANGED
@@ -18,7 +18,7 @@ module Razor
|
|
18
18
|
#
|
19
19
|
# The next line is the one that our packaging tools modify, so please make
|
20
20
|
# sure that any change to it is discussed and agreed first.
|
21
|
-
version = '1.
|
21
|
+
version = '1.3.0'
|
22
22
|
|
23
23
|
if version == "DEVELOPMENT"
|
24
24
|
root = File.expand_path("../../..", File.dirname(__FILE__))
|
data/lib/razor/cli/views.rb
CHANGED
data/lib/razor/cli/views.yaml
CHANGED
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
# Needed to make the client work on Ruby 1.8.7
|
3
|
+
unless Kernel.respond_to?(:require_relative)
|
4
|
+
module Kernel
|
5
|
+
def require_relative(path)
|
6
|
+
require File.join(File.dirname(caller[0]), path.to_str)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
require_relative '../spec_helper'
|
12
|
+
|
13
|
+
describe Razor::CLI::Document do
|
14
|
+
def document(doc, format_type)
|
15
|
+
Razor::CLI::Document.new(doc, format_type)
|
16
|
+
end
|
17
|
+
def check_doc(reality, expectation)
|
18
|
+
[:spec, :items, :type, :format_view, :command].each do |prop|
|
19
|
+
reality.public_send(prop).should == expectation[prop] if expectation[prop]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
describe "#new" do
|
23
|
+
it "creates a blank document successfully" do
|
24
|
+
doc = document({}, 'short')
|
25
|
+
check_doc(doc, items: [{}], type: :single)
|
26
|
+
end
|
27
|
+
it "creates a normal document successfully" do
|
28
|
+
doc = document({'spec' => 'some/path', 'abc' => 'def'}, 'short')
|
29
|
+
check_doc(doc, type: :single, spec: 'some/path')
|
30
|
+
end
|
31
|
+
it "includes the command if supplied" do
|
32
|
+
doc = document({'spec' => 'some/path', 'abc' => 'def', 'command' => 123}, 'short')
|
33
|
+
check_doc(doc, type: :single, spec: 'some/path', command: 123)
|
34
|
+
end
|
35
|
+
it "finds formatting based on the spec string" do
|
36
|
+
Razor::CLI::Views.views = {'collections' => {'item' => {'+short' => {'+layout' => 'list'}}}}
|
37
|
+
doc = document({'spec' => '/collections/item', 'abc' => 'def'}, 'short')
|
38
|
+
check_doc(doc, type: :single, spec: '/collections/item', format_view: {'+layout' => 'list'})
|
39
|
+
end
|
40
|
+
it "finds formatting based on the spec array" do
|
41
|
+
Razor::CLI::Views.views = {'collections' => {'more' => {'scoping' => {'+short' => {'+layout' => 'list'}}}}}
|
42
|
+
doc = document({'+spec' => ['/collections/more', 'scoping'], 'abc' => 'def'}, 'short')
|
43
|
+
check_doc(doc, type: :single, spec: '/collections/more', format_view: {'+layout' => 'list'})
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
data/spec/cli/format_spec.rb
CHANGED
@@ -42,11 +42,6 @@ describe Razor::CLI::Format do
|
|
42
42
|
result = format doc
|
43
43
|
result.should_not =~ /Query additional details/
|
44
44
|
end
|
45
|
-
it "hides array spec array from additional details" do
|
46
|
-
doc = {'abc' => [], 'spec' => ['def', 'jkl']}
|
47
|
-
result = format doc
|
48
|
-
result.should =~ /Query additional details via: `razor something else \[abc\]`\z/
|
49
|
-
end
|
50
45
|
it "hides array +spec array from additional details" do
|
51
46
|
doc = {'abc' => [], '+spec' => ['def', 'jkl']}
|
52
47
|
result = format doc
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: razor-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-05-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mime-types
|
@@ -116,6 +116,7 @@ files:
|
|
116
116
|
- spec/testing.md
|
117
117
|
- spec/cli/navigate_spec.rb
|
118
118
|
- spec/cli/command_spec.rb
|
119
|
+
- spec/cli/document_spec.rb
|
119
120
|
- spec/cli/parse_spec.rb
|
120
121
|
- spec/cli/format_spec.rb
|
121
122
|
- spec/fixtures/vcr/Razor_CLI_Parse/_new/_help/should_print_a_list_of_known_endpoints.yml
|
@@ -181,6 +182,7 @@ test_files:
|
|
181
182
|
- spec/testing.md
|
182
183
|
- spec/cli/navigate_spec.rb
|
183
184
|
- spec/cli/command_spec.rb
|
185
|
+
- spec/cli/document_spec.rb
|
184
186
|
- spec/cli/parse_spec.rb
|
185
187
|
- spec/cli/format_spec.rb
|
186
188
|
- spec/fixtures/vcr/Razor_CLI_Parse/_new/_help/should_print_a_list_of_known_endpoints.yml
|