rest-terminal 0.1.6 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -49,7 +49,7 @@ module Rest
49
49
  def _cd
50
50
  fp = full_path(@prm[0])
51
51
  if File.directory?("services#{fp}")
52
- @pwd = fp
52
+ @cpath = @pwd = fp
53
53
  else
54
54
  fp = "Service not exists! #{fp}".red
55
55
  end
@@ -76,7 +76,7 @@ module Rest
76
76
  def _ls
77
77
  path = Dir["#{current_path}*/"]
78
78
  path.collect do |x|
79
- puts x.sub(current_path,'/')
79
+ puts x.sub(current_path,'').sub(/\/$/,'')
80
80
  end
81
81
  @_status = "#{path.length} services"
82
82
  # p "lolllll >>#{@serv}<< ."
@@ -89,32 +89,33 @@ module Rest
89
89
  def _info
90
90
  multi_exec(:_info)
91
91
  @_status = ""
92
- # @_status = @services[@pwd]._info(@prm)
92
+ # @_status = @services[@cpath]._info(@prm)
93
93
  end
94
94
 
95
95
  def _response
96
- @_status = @services[@pwd]._response(@prm)
96
+ @_status = @services[@capth]._response(@prm)
97
97
  end
98
98
 
99
99
  def _headers
100
- @_status = @services[@pwd]._headers(@prm)
100
+ @_status = @services[@cpath]._headers(@prm)
101
101
  end
102
102
 
103
103
  def _body
104
- @_status = @services[@pwd]._body(@prm)
104
+ @_status = @services[@cpath]._body(@prm)
105
105
  end
106
106
 
107
107
  def _vars
108
+ # p "CPATH: >>#{@cpath}<<"
108
109
  if @prm.length>1 && !@prm[/\=/]
109
110
  pth = @prm.shift
110
111
  @_status = @services[pth]._vars(@prm)
111
112
  else
112
- @_status = @services[@pwd]._vars(@prm)
113
+ @_status = @services[@cpath]._vars(@prm)
113
114
  end
114
115
  end
115
116
 
116
117
  def _reset
117
- @_status = @services[@pwd]._reset(@prm)
118
+ @_status = @services[@cpath]._reset(@prm)
118
119
  end
119
120
 
120
121
  def _send
@@ -15,8 +15,10 @@ module Rest
15
15
  end
16
16
  pr = @services[@pwd]
17
17
  path = Dir["#{current_path}*/"]
18
+ # p "CHILDPATH #{path.inspect} >>#{current_path}*/<<"
18
19
  path.collect do |px|
19
20
  p2 = px[/\/.*/]
21
+ # p "CHILD #{p2}"
20
22
  @services[p2] = ServiceBase.new(pr,p2)
21
23
  end
22
24
  end
data/lib/rest/terminal.rb CHANGED
@@ -23,6 +23,7 @@ module Rest
23
23
  @prm = [ ]
24
24
  @pwd = '/'
25
25
  @cmd = ''
26
+ @cpath = ''
26
27
  @_status = ''
27
28
  end
28
29
 
@@ -53,16 +54,23 @@ module Rest
53
54
  def load_state
54
55
  if File.exists?('./.rest-terminal/persistent_rc.rb')
55
56
  require './.rest-terminal/persistent_rc'
56
- load_vars
57
+ load_vars
58
+ @cpath = @capth ? "#{@pwd}#{@cpath}/" : @pwd
57
59
  load_services
58
60
  end
59
61
  end
60
62
 
63
+ # sometime command can include the child service
64
+ # Ex: rest vars@child
65
+ # old code for this action use @pwd as current service path
66
+ # new code for this action introduce @cpath as current path
61
67
  def is_cmd_in_commands?
62
68
  puts ARGV.inspect.red
63
- @cmd = ARGV[0].to_s
64
- parm = ARGV[1,99]
65
- @prm = parm ? parm : [ ] #.join(' ') : ''
69
+ cmdp = ARGV[0].to_s.split('@')
70
+ parm = ARGV[1,99]
71
+ @cmd = cmdp[0]
72
+ @cpath = cmdp[1]
73
+ @prm = parm ? parm : [ ] #.join(' ') : ''
66
74
  commands.index(@cmd) ? @cmd : nil
67
75
  # if singleton_class.private_instance_methods(false).index(@@cmd.to_sym)
68
76
  end
@@ -94,11 +102,11 @@ module Rest
94
102
  end
95
103
 
96
104
  def space_path(spc)
97
- (spc[0] == '/') ? spc : "#{@pwd}#{spc}"
105
+ (spc[0] == '/') ? spc : "#{@cpath}#{spc}"
98
106
  end
99
107
 
100
108
  def full_path(spc)
101
- x = "#{@pwd} "
109
+ x = "#{@cpath} "
102
110
  l = x.count('/')+1
103
111
  dots = spc[/\.+/]
104
112
  if dots &&
@@ -114,9 +122,10 @@ module Rest
114
122
  def multi_exec(cmd)
115
123
  @prm = ['.'] if @prm==[]
116
124
  @prm.each do |prm|
117
- prm = @pwd if prm=='.'
125
+ prm = @cpath if prm=='.'
118
126
  pth = full_path(prm)
119
127
  puts "Service: #{pth}".yellow
128
+ # puts @services.keys.inspect
120
129
  @_status = @services[pth].send(cmd,prm)
121
130
  end
122
131
  end
data/lib/rest/version.rb CHANGED
@@ -23,7 +23,7 @@ module Rest
23
23
 
24
24
  # :nodoc:
25
25
  def patch
26
- 6
26
+ 7
27
27
  end
28
28
 
29
29
  # :nodoc:
data/lib/service_base.rb CHANGED
@@ -155,9 +155,14 @@ class ServiceBase
155
155
  end
156
156
 
157
157
  def body_join
158
- bodies.collect do |k,v|
159
- "#{k}=#{v}"
160
- end.join("&")
158
+ if headers[:"content-type"]=='application/json'
159
+ body = bodies.to_json
160
+ else
161
+ body = bodies.collect do |k,v|
162
+ "#{k}=#{v}"
163
+ end.join("&")
164
+ end
165
+ body
161
166
  end
162
167
 
163
168
  def set_value(key,prm)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-terminal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: