rumx 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.md +6 -0
- data/LICENSE.txt +201 -0
- data/README.md +107 -0
- data/Rakefile +23 -0
- data/examples/bean_list/README +2 -0
- data/examples/bean_list/config.ru +9 -0
- data/examples/bean_list/my_bean.rb +35 -0
- data/examples/embedded/README +2 -0
- data/examples/embedded/config.ru +9 -0
- data/examples/embedded/my_bean.rb +23 -0
- data/examples/embedded/my_embedded_bean.rb +22 -0
- data/examples/list/README +2 -0
- data/examples/list/config.ru +9 -0
- data/examples/list/my_bean.rb +28 -0
- data/examples/simple/README +2 -0
- data/examples/simple/config.ru +11 -0
- data/examples/simple/my_bean.rb +36 -0
- data/examples/timer/README +7 -0
- data/examples/timer/config.ru +9 -0
- data/examples/timer/my_bean.rb +28 -0
- data/lib/rumx/argument.rb +11 -0
- data/lib/rumx/attribute.rb +38 -0
- data/lib/rumx/bean.rb +484 -0
- data/lib/rumx/beans/folder.rb +9 -0
- data/lib/rumx/beans/message.rb +16 -0
- data/lib/rumx/beans/timer.rb +75 -0
- data/lib/rumx/beans.rb +3 -0
- data/lib/rumx/operation.rb +26 -0
- data/lib/rumx/server/public/_lib/jquery.cookie.js +96 -0
- data/lib/rumx/server/public/_lib/jquery.hotkeys.js +99 -0
- data/lib/rumx/server/public/_lib/jquery.js +18 -0
- data/lib/rumx/server/public/attribute_test.html +148 -0
- data/lib/rumx/server/public/jquery-ui-1.8.16.custom.min.js +132 -0
- data/lib/rumx/server/public/jquery.jstree.js +4551 -0
- data/lib/rumx/server/public/jquery.layout.min-1.2.0.js +80 -0
- data/lib/rumx/server/public/themes/apple/bg.jpg +0 -0
- data/lib/rumx/server/public/themes/apple/d.png +0 -0
- data/lib/rumx/server/public/themes/apple/dot_for_ie.gif +0 -0
- data/lib/rumx/server/public/themes/apple/style.css +61 -0
- data/lib/rumx/server/public/themes/apple/throbber.gif +0 -0
- data/lib/rumx/server/public/themes/classic/d.gif +0 -0
- data/lib/rumx/server/public/themes/classic/d.png +0 -0
- data/lib/rumx/server/public/themes/classic/dot_for_ie.gif +0 -0
- data/lib/rumx/server/public/themes/classic/style.css +77 -0
- data/lib/rumx/server/public/themes/classic/throbber.gif +0 -0
- data/lib/rumx/server/public/themes/default/d.gif +0 -0
- data/lib/rumx/server/public/themes/default/d.png +0 -0
- data/lib/rumx/server/public/themes/default/style.css +74 -0
- data/lib/rumx/server/public/themes/default/throbber.gif +0 -0
- data/lib/rumx/server/public/themes/default-rtl/d.gif +0 -0
- data/lib/rumx/server/public/themes/default-rtl/d.png +0 -0
- data/lib/rumx/server/public/themes/default-rtl/dots.gif +0 -0
- data/lib/rumx/server/public/themes/default-rtl/style.css +84 -0
- data/lib/rumx/server/public/themes/default-rtl/throbber.gif +0 -0
- data/lib/rumx/server/views/attribute_value_tag.haml +4 -0
- data/lib/rumx/server/views/content_attribute.haml +35 -0
- data/lib/rumx/server/views/content_attributes.haml +31 -0
- data/lib/rumx/server/views/content_operation.haml +39 -0
- data/lib/rumx/server/views/content_operations.haml +36 -0
- data/lib/rumx/server/views/index.haml +1 -0
- data/lib/rumx/server/views/layout.haml +18 -0
- data/lib/rumx/server/views/link_to_content.haml +1 -0
- data/lib/rumx/server/views/tree.haml +11 -0
- data/lib/rumx/server/views/tree_bean.haml +6 -0
- data/lib/rumx/server/views/tree_bean_attributes.haml +6 -0
- data/lib/rumx/server/views/tree_bean_operations.haml +6 -0
- data/lib/rumx/server.rb +185 -0
- data/lib/rumx/type.rb +36 -0
- data/lib/rumx.rb +7 -0
- metadata +123 -0
@@ -0,0 +1,36 @@
|
|
1
|
+
%h3= path[1..-1]
|
2
|
+
%h4 Operations
|
3
|
+
%table{:width => '100%'}
|
4
|
+
%thead
|
5
|
+
%tr
|
6
|
+
%td Name
|
7
|
+
%td Description
|
8
|
+
%td Returns
|
9
|
+
%td{:colspan => 4} Arguments
|
10
|
+
%tr
|
11
|
+
%td
|
12
|
+
%td
|
13
|
+
%td
|
14
|
+
%td Index
|
15
|
+
%td Name
|
16
|
+
%td Description
|
17
|
+
%td Type
|
18
|
+
%tbody
|
19
|
+
- bean.bean_each_operation do |operation, rel_path|
|
20
|
+
%tr
|
21
|
+
%td= link_to_operation(path, rel_path)
|
22
|
+
%td= operation.description
|
23
|
+
%td= operation.type.to_s
|
24
|
+
%td
|
25
|
+
%td
|
26
|
+
%td
|
27
|
+
%td
|
28
|
+
- operation.arguments.each_with_index do |arg, i|
|
29
|
+
%tr
|
30
|
+
%td
|
31
|
+
%td
|
32
|
+
%td
|
33
|
+
%td= i+1
|
34
|
+
%td= arg.name
|
35
|
+
%td= arg.description
|
36
|
+
%td= arg.type
|
@@ -0,0 +1 @@
|
|
1
|
+
- # Intentionally left blank
|
@@ -0,0 +1,18 @@
|
|
1
|
+
!!!XML
|
2
|
+
!!!1.1
|
3
|
+
%html{"xml:lang" => "en", :xmlns => "http://www.w3.org/1999/xhtml"}
|
4
|
+
%head
|
5
|
+
%script{:type => 'text/javascript', :src => url('/_lib/jquery.js')}
|
6
|
+
%script{:type => 'text/javascript', :src => url('/jquery.jstree.js')}
|
7
|
+
%script{:type => 'text/javascript', :src => url('/jquery.layout.min-1.2.0.js')}
|
8
|
+
%script{:type => 'text/javascript', :src => url('/jquery-ui-1.8.16.custom.min.js')}
|
9
|
+
:javascript
|
10
|
+
$(document).ready(function () {
|
11
|
+
$('body').layout({ applyDefaultStyles: true });
|
12
|
+
});
|
13
|
+
%title Rumx Console
|
14
|
+
%body
|
15
|
+
.ui-layout-west
|
16
|
+
= partial :tree
|
17
|
+
.ui-layout-center#content
|
18
|
+
= yield
|
@@ -0,0 +1 @@
|
|
1
|
+
%a{ :href => href, :onclick => "$('#content').load('#{href}'); return false" }= name
|
data/lib/rumx/server.rb
ADDED
@@ -0,0 +1,185 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'json'
|
3
|
+
require 'haml'
|
4
|
+
require 'uri'
|
5
|
+
|
6
|
+
module Rumx
|
7
|
+
class Server < Sinatra::Base
|
8
|
+
configure do
|
9
|
+
enable :logging
|
10
|
+
end
|
11
|
+
|
12
|
+
set :root, File.join(File.dirname(__FILE__), 'server')
|
13
|
+
|
14
|
+
helpers do
|
15
|
+
def render_tree_bean_attributes(path, bean)
|
16
|
+
return '' unless bean.bean_has_attributes?
|
17
|
+
partial :tree_bean_attributes, :locals => {:path => path, :bean => bean}
|
18
|
+
end
|
19
|
+
|
20
|
+
def render_tree_bean_operations(path, bean)
|
21
|
+
return '' unless bean.bean_has_operations?
|
22
|
+
partial :tree_bean_operations, :locals => {:path => path, :bean => bean}
|
23
|
+
end
|
24
|
+
|
25
|
+
def render_tree_bean_children(parent_path, parent_bean)
|
26
|
+
val = ''
|
27
|
+
parent_bean.bean_children.each do |name, bean|
|
28
|
+
#puts "in child name=#{name} bean=#{bean}"
|
29
|
+
path = "#{parent_path}/#{name}"
|
30
|
+
val << partial(:tree_bean, :locals => {:path => path, :name =>name, :bean => bean})
|
31
|
+
end
|
32
|
+
val
|
33
|
+
end
|
34
|
+
|
35
|
+
def attributes_path(path)
|
36
|
+
URI.escape(path + '/attributes')
|
37
|
+
end
|
38
|
+
|
39
|
+
def attribute_path(path)
|
40
|
+
URI.escape(path + '/attribute')
|
41
|
+
end
|
42
|
+
|
43
|
+
def operations_path(path)
|
44
|
+
URI.escape(path + '/operations')
|
45
|
+
end
|
46
|
+
|
47
|
+
def operation_path(path)
|
48
|
+
URI.escape(path + '/operation')
|
49
|
+
end
|
50
|
+
|
51
|
+
# http://sinatra-book.gittr.com/#implementation_of_rails_style_partials but extract_options! part of ActiveSupport
|
52
|
+
# Also look at http://stackoverflow.com/questions/3974878/rendering-a-partial-from-a-haml-file
|
53
|
+
def partial(template, options={})
|
54
|
+
options.merge!(:layout => false)
|
55
|
+
if collection = options.delete(:collection) then
|
56
|
+
collection.inject([]) do |buffer, member|
|
57
|
+
buffer << haml(template, options.merge(
|
58
|
+
:layout => false,
|
59
|
+
:locals => {template.to_sym => member}
|
60
|
+
)
|
61
|
+
)
|
62
|
+
end.join("\n")
|
63
|
+
else
|
64
|
+
haml(template, options)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def haml_for_ajax(template, options={})
|
69
|
+
layout = request.xhr? ? false : :layout
|
70
|
+
options = options.merge(:layout => layout)
|
71
|
+
haml template, options
|
72
|
+
end
|
73
|
+
|
74
|
+
def link_to_attributes(path)
|
75
|
+
partial :link_to_content, :locals => {:href => attributes_path(path), :name => 'Attributes'}
|
76
|
+
end
|
77
|
+
|
78
|
+
def link_to_attribute(parent_path, rel_path)
|
79
|
+
partial :link_to_content, :locals => {:href => attribute_path(parent_path+'/'+rel_path), :name => rel_path}
|
80
|
+
end
|
81
|
+
|
82
|
+
def link_to_operations(path)
|
83
|
+
partial :link_to_content, :locals => {:href => operations_path(path), :name => 'Operations'}
|
84
|
+
end
|
85
|
+
|
86
|
+
def link_to_operation(parent_path, rel_path)
|
87
|
+
partial :link_to_content, :locals => {:href => operation_path(parent_path+'/'+rel_path), :name => rel_path}
|
88
|
+
end
|
89
|
+
|
90
|
+
def attribute_value_tag(attribute, param_name, value)
|
91
|
+
partial :attribute_value_tag, :locals => {:attribute => attribute, :param_name => param_name, :value => value}
|
92
|
+
end
|
93
|
+
|
94
|
+
def name_value_hash(attribute_value_hash)
|
95
|
+
hash = {}
|
96
|
+
attribute_value_hash.each do |attribute, value|
|
97
|
+
if attribute.kind_of?(Rumx::Attribute)
|
98
|
+
hash[attribute.name] = value
|
99
|
+
elsif attribute.kind_of?(String)
|
100
|
+
# It's an embedded bean, attribute is actually the bean name and value is the hash of Attribute/values
|
101
|
+
hash[attribute] = name_value_hash(value)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
hash
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
get '/' do
|
109
|
+
haml :index
|
110
|
+
end
|
111
|
+
|
112
|
+
get '/*/attributes.?:format?' do
|
113
|
+
path = params[:splat][0]
|
114
|
+
bean = Bean.find(path.split('/'))
|
115
|
+
return 404 unless bean
|
116
|
+
# For get we read, then write. post is the other way around.
|
117
|
+
if params[:format] == 'json'
|
118
|
+
bean.bean_get_and_set_attributes(params).to_json
|
119
|
+
else
|
120
|
+
haml_for_ajax :content_attributes, :locals => {:get_set_method => :bean_get_and_set_attributes, :params => params, :path => path, :bean => bean}
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
post '/*/attributes.?:format?' do
|
125
|
+
path = params[:splat][0]
|
126
|
+
bean = Bean.find(path.split('/'))
|
127
|
+
return 404 unless bean
|
128
|
+
#puts "params=#{params.inspect}"
|
129
|
+
# For post we write, then read. get is the other way around.
|
130
|
+
if params[:format] == 'json'
|
131
|
+
bean.bean_set_and_get_attributes(params).to_json
|
132
|
+
else
|
133
|
+
haml_for_ajax :content_attributes, :locals => {:get_set_method => :bean_set_and_get_attributes, :params => params, :path => path, :bean => bean}
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
get '/*/attribute.?:format?' do
|
138
|
+
path = params[:splat][0]
|
139
|
+
bean, attribute, param_name, value = Bean.find_attribute(path.split('/'))
|
140
|
+
return 404 unless bean
|
141
|
+
if params[:format] == 'json'
|
142
|
+
else
|
143
|
+
haml_for_ajax :content_attribute, :locals => {:path => '/' + path, :bean => bean, :attribute => attribute, :param_name => param_name, :value => value}
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
post '/*/attribute.?:format?' do
|
148
|
+
path = params[:splat][0]
|
149
|
+
bean, attribute, param_name, value = Bean.find_attribute(path.split('/'))
|
150
|
+
return 404 unless bean
|
151
|
+
bean.bean_set_attributes(params)
|
152
|
+
# Do it again to get the updated value
|
153
|
+
bean, attribute, param_name, value = Bean.find_attribute(path.split('/'))
|
154
|
+
if params[:format] == 'json'
|
155
|
+
else
|
156
|
+
haml_for_ajax :content_attribute, :locals => {:path => '/' + path, :bean => bean, :attribute => attribute, :param_name => param_name, :value => value}
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
get '/*/operations' do
|
161
|
+
path = params[:splat][0]
|
162
|
+
bean = Bean.find(path.split('/'))
|
163
|
+
return 404 unless bean
|
164
|
+
haml_for_ajax :content_operations, :locals => {:path => '/' + path, :bean => bean}
|
165
|
+
end
|
166
|
+
|
167
|
+
get '/*/operation.?:format?' do
|
168
|
+
path = params[:splat][0]
|
169
|
+
bean, operation = Bean.find_operation(path.split('/'))
|
170
|
+
return 404 unless bean
|
171
|
+
if params[:format] == 'json'
|
172
|
+
else
|
173
|
+
haml_for_ajax :content_operation, :locals => {:path => '/' + path, :bean => bean, :operation => operation}
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
post '/*/operation.?:format?' do
|
178
|
+
path = params[:splat][0]
|
179
|
+
bean, operation = Bean.find_operation(path.split('/'))
|
180
|
+
return 404 unless bean
|
181
|
+
operation.run(bean, params).to_json
|
182
|
+
end
|
183
|
+
|
184
|
+
end
|
185
|
+
end
|
data/lib/rumx/type.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module Rumx
|
2
|
+
class Type
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def self.find(type_name)
|
6
|
+
type = @@allowed_types[type_name.to_sym]
|
7
|
+
raise "No such type=#{type_name} in Rumx::Type" unless type
|
8
|
+
type
|
9
|
+
end
|
10
|
+
|
11
|
+
def initialize(name, string_to_value_proc, value_to_string_proc=lambda{|v| v.to_s})
|
12
|
+
@name = name
|
13
|
+
@string_to_value_proc = string_to_value_proc
|
14
|
+
@value_to_string_proc = value_to_string_proc
|
15
|
+
end
|
16
|
+
|
17
|
+
def string_to_value(string)
|
18
|
+
@string_to_value_proc.call(string)
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
@name.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
@@allowed_types = {
|
26
|
+
:integer => new(:integer, lambda {|s| s.to_i}),
|
27
|
+
:float => new(:float, lambda {|s| s.to_f}),
|
28
|
+
:string => new(:string, lambda {|s| s.to_s}),
|
29
|
+
:boolean => new(:boolean, lambda {|s| s.to_s == 'true'}),
|
30
|
+
:void => new(:void, lambda {|s| nil}, lambda {|v| ''})
|
31
|
+
}
|
32
|
+
|
33
|
+
# We've created all the instances we need
|
34
|
+
private_class_method :new
|
35
|
+
end
|
36
|
+
end
|
data/lib/rumx.rb
ADDED
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rumx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Brad Pardee
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-11-15 00:00:00 Z
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: A Ruby version of JMX
|
17
|
+
email:
|
18
|
+
- bradpardee@gmail.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files: []
|
24
|
+
|
25
|
+
files:
|
26
|
+
- examples/bean_list/config.ru
|
27
|
+
- examples/bean_list/my_bean.rb
|
28
|
+
- examples/bean_list/README
|
29
|
+
- examples/embedded/config.ru
|
30
|
+
- examples/embedded/my_bean.rb
|
31
|
+
- examples/embedded/my_embedded_bean.rb
|
32
|
+
- examples/embedded/README
|
33
|
+
- examples/list/config.ru
|
34
|
+
- examples/list/my_bean.rb
|
35
|
+
- examples/list/README
|
36
|
+
- examples/simple/config.ru
|
37
|
+
- examples/simple/my_bean.rb
|
38
|
+
- examples/simple/README
|
39
|
+
- examples/timer/config.ru
|
40
|
+
- examples/timer/my_bean.rb
|
41
|
+
- examples/timer/README
|
42
|
+
- lib/rumx.rb
|
43
|
+
- lib/rumx/argument.rb
|
44
|
+
- lib/rumx/attribute.rb
|
45
|
+
- lib/rumx/bean.rb
|
46
|
+
- lib/rumx/beans.rb
|
47
|
+
- lib/rumx/operation.rb
|
48
|
+
- lib/rumx/server.rb
|
49
|
+
- lib/rumx/type.rb
|
50
|
+
- lib/rumx/beans/folder.rb
|
51
|
+
- lib/rumx/beans/message.rb
|
52
|
+
- lib/rumx/beans/timer.rb
|
53
|
+
- lib/rumx/server/public/attribute_test.html
|
54
|
+
- lib/rumx/server/public/jquery-ui-1.8.16.custom.min.js
|
55
|
+
- lib/rumx/server/public/jquery.jstree.js
|
56
|
+
- lib/rumx/server/public/jquery.layout.min-1.2.0.js
|
57
|
+
- lib/rumx/server/public/_lib/jquery.cookie.js
|
58
|
+
- lib/rumx/server/public/_lib/jquery.hotkeys.js
|
59
|
+
- lib/rumx/server/public/_lib/jquery.js
|
60
|
+
- lib/rumx/server/public/themes/apple/bg.jpg
|
61
|
+
- lib/rumx/server/public/themes/apple/d.png
|
62
|
+
- lib/rumx/server/public/themes/apple/dot_for_ie.gif
|
63
|
+
- lib/rumx/server/public/themes/apple/style.css
|
64
|
+
- lib/rumx/server/public/themes/apple/throbber.gif
|
65
|
+
- lib/rumx/server/public/themes/classic/d.gif
|
66
|
+
- lib/rumx/server/public/themes/classic/d.png
|
67
|
+
- lib/rumx/server/public/themes/classic/dot_for_ie.gif
|
68
|
+
- lib/rumx/server/public/themes/classic/style.css
|
69
|
+
- lib/rumx/server/public/themes/classic/throbber.gif
|
70
|
+
- lib/rumx/server/public/themes/default/d.gif
|
71
|
+
- lib/rumx/server/public/themes/default/d.png
|
72
|
+
- lib/rumx/server/public/themes/default/style.css
|
73
|
+
- lib/rumx/server/public/themes/default/throbber.gif
|
74
|
+
- lib/rumx/server/public/themes/default-rtl/d.gif
|
75
|
+
- lib/rumx/server/public/themes/default-rtl/d.png
|
76
|
+
- lib/rumx/server/public/themes/default-rtl/dots.gif
|
77
|
+
- lib/rumx/server/public/themes/default-rtl/style.css
|
78
|
+
- lib/rumx/server/public/themes/default-rtl/throbber.gif
|
79
|
+
- lib/rumx/server/views/attribute_value_tag.haml
|
80
|
+
- lib/rumx/server/views/content_attribute.haml
|
81
|
+
- lib/rumx/server/views/content_attributes.haml
|
82
|
+
- lib/rumx/server/views/content_operation.haml
|
83
|
+
- lib/rumx/server/views/content_operations.haml
|
84
|
+
- lib/rumx/server/views/index.haml
|
85
|
+
- lib/rumx/server/views/layout.haml
|
86
|
+
- lib/rumx/server/views/link_to_content.haml
|
87
|
+
- lib/rumx/server/views/tree.haml
|
88
|
+
- lib/rumx/server/views/tree_bean.haml
|
89
|
+
- lib/rumx/server/views/tree_bean_attributes.haml
|
90
|
+
- lib/rumx/server/views/tree_bean_operations.haml
|
91
|
+
- LICENSE.txt
|
92
|
+
- Rakefile
|
93
|
+
- History.md
|
94
|
+
- README.md
|
95
|
+
homepage: http://github.com/ClarityServices/rumx
|
96
|
+
licenses: []
|
97
|
+
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: "0"
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
none: false
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: "0"
|
115
|
+
requirements: []
|
116
|
+
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 1.8.9
|
119
|
+
signing_key:
|
120
|
+
specification_version: 3
|
121
|
+
summary: Ruby Management Extensions
|
122
|
+
test_files: []
|
123
|
+
|