rubysite 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +22 -0
- data/Rakefile +74 -0
- data/lib/rubysite/public/css/default.css +0 -0
- data/lib/rubysite/version.rb +3 -0
- data/lib/rubysite/views/help.erb +6 -0
- data/lib/rubysite/views/index.erb +2 -0
- data/lib/rubysite/views/layout.erb +27 -0
- data/lib/rubysite/views/method/error.erb +4 -0
- data/lib/rubysite/views/method/form.erb +7 -0
- data/lib/rubysite/views/method/result.erb +12 -0
- data/lib/rubysite/views/module/command_list.erb +9 -0
- data/lib/rubysite.rb +208 -0
- data/rubysite.gemspec +27 -0
- data/test/rubysite/rubysite_test.rb +7 -0
- data/test/rubysite/util_test_composite.rb +20 -0
- data/test/rubysite/util_test_module.rb +112 -0
- data/test/rubysite/util_test_no_singleton.rb +9 -0
- metadata +154 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZDQ2NzIxNDc5MDhjZjI1YzYyYmU2ZDMxMGY3NjgxZGNkNzMzMWQxYQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NDQ2NzRlY2EyNzYzYjQ5OTgyYTZiNWZmZDgwY2ViZWUxMDU5YjIxMQ==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
Y2Y4MTE4ZDk1NDgzN2JkMmU0NzFmYmVhYjgxYTQ0YzlhNDllY2VmODgyZGE3
|
10
|
+
YWViNzcxZDE0YmNhZmZkNGU2N2I3Y2U4NTMzOTJhZWQ3NDU3OWVhOTM3OGY5
|
11
|
+
NzcwMDZhNWNlNzI3ZWMxNjNlYjk2OTY2MmI3ZmU3YTQ1MDRjNjE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
OTJlMWU4MDQwYjA0ZTNlNjZmYTNiZTliMjQ4MWE2ZDhlNWI2ZTg4ZjU5MmVk
|
14
|
+
ZjViOGZiMmU1ZDVlMWViNmJjMDQwMmQyNDRlNTdmYTdmN2Q3ZDQwNzE0MGIy
|
15
|
+
MGQxNmM5Y2M1ZTU4YTAxZmRhOTRhY2Q5YWIwYTAwZjVhNDcxZDM=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Danny Purcell
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Rubysite
|
2
|
+
---------------
|
3
|
+
|
4
|
+
© Danny Purcell 2013 | MIT license
|
5
|
+
|
6
|
+
Makes creating web service as easy as writing a function library.
|
7
|
+
|
8
|
+
Features
|
9
|
+
---------------
|
10
|
+
|
11
|
+
Allows the user to write a properly documented module/class as a function library and convert it to a web service
|
12
|
+
by simply including Rubysite.
|
13
|
+
|
14
|
+
Usage
|
15
|
+
---------------
|
16
|
+
|
17
|
+
Write your module of methods, document them as you normally would.
|
18
|
+
`include Rubysite`
|
19
|
+
Optionally `#!/usr/bin/env ruby` at the top.
|
20
|
+
|
21
|
+
Calling `ruby ./path/to/module.rb` will start the server.
|
22
|
+
Your module's singleton methods `def self.method_name` will be available from the web at `localhost:8080` by default.
|
data/Rakefile
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'yard'
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
task :default => [:package]
|
5
|
+
|
6
|
+
task :clean do
|
7
|
+
FileUtils.rm_rf('./doc')
|
8
|
+
FileUtils.rm_rf('./.yardoc')
|
9
|
+
FileUtils.rm_rf('./pkg')
|
10
|
+
FileUtils.rm(Dir.glob('./rubysite-*.gem'))
|
11
|
+
end
|
12
|
+
|
13
|
+
task :bundle do
|
14
|
+
system("bundle install")
|
15
|
+
end
|
16
|
+
|
17
|
+
Rake::TestTask.new do |t|
|
18
|
+
t.libs << "test"
|
19
|
+
t.test_files = FileList['test/*/*_test.rb']
|
20
|
+
t.verbose = true
|
21
|
+
end
|
22
|
+
|
23
|
+
YARD::Rake::YardocTask.new
|
24
|
+
|
25
|
+
task :package => [:clean, :bundle, :test, :yard] do
|
26
|
+
gem_specs = Dir.glob("**/*.gemspec")
|
27
|
+
gem_specs.each { |gem_spec|
|
28
|
+
system("gem build #{gem_spec}")
|
29
|
+
raise "Error during build phase" if $?.exitstatus != 0
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
task :install => :package do
|
34
|
+
load "#{File.expand_path(File.dirname(__FILE__))}/lib/rubysite/version.rb"
|
35
|
+
system("gem install #{File.expand_path(File.dirname(__FILE__))}/rubysite-#{Rubysite::VERSION}.gem")
|
36
|
+
end
|
37
|
+
|
38
|
+
task :upgrade => :package do
|
39
|
+
system("gem uninstall rubysite -a")
|
40
|
+
load "#{File.expand_path(File.dirname(__FILE__))}/lib/rubysite/version.rb"
|
41
|
+
system("gem install #{File.expand_path(File.dirname(__FILE__))}/rubysite-#{Rubysite::VERSION}.gem")
|
42
|
+
end
|
43
|
+
|
44
|
+
task :version_set, [:version] do |t, args|
|
45
|
+
raise "Must provide a version.\n If you called 'rake version_set 1.2.3', try 'rake version_set[1.2.3]'" if args[:version].nil? || args[:version].empty?
|
46
|
+
|
47
|
+
version_file = <<-END.gsub(/^ {4}/, '')
|
48
|
+
module Rubysite
|
49
|
+
VERSION = "#{args[:version]}"
|
50
|
+
end
|
51
|
+
END
|
52
|
+
puts "Writing version file:\n #{version_file}"
|
53
|
+
File.open("#{File.expand_path(File.dirname(__FILE__))}/lib/rubysite/version.rb", 'w+') { |file|
|
54
|
+
file.write(version_file)
|
55
|
+
}
|
56
|
+
file_text = File.read("#{File.expand_path(File.dirname(__FILE__))}/lib/rubysite/version.rb")
|
57
|
+
raise "Could not update version file" if file_text != version_file
|
58
|
+
end
|
59
|
+
|
60
|
+
task :release, [:version] => [:version_set, :package] do |t, args|
|
61
|
+
system("git clean -f")
|
62
|
+
system("git add .")
|
63
|
+
system("git commit -m\"Version to #{args[:version]}\"")
|
64
|
+
if $?.exitstatus == 0
|
65
|
+
system("git tag -a v#{args[:version]} -m\"Version #{args[:version]} Release\"")
|
66
|
+
if $?.exitstatus == 0
|
67
|
+
system("git push origin master --tags")
|
68
|
+
if $?.exitstatus == 0
|
69
|
+
load "#{File.expand_path(File.dirname(__FILE__))}/lib/rubysite/version.rb"
|
70
|
+
system("gem push #{File.expand_path(File.dirname(__FILE__))}/rubysite-#{Rubysite::VERSION}.gem")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
File without changes
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<html>
|
2
|
+
<head>
|
3
|
+
<title><%= layout[:name] %></title>
|
4
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
|
5
|
+
<link rel="stylesheet" type="text/css" media="screen" href="/css/<%= layout[:name] %>.css"/>
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
<div class='content_header'>
|
9
|
+
<h1><%= layout[:name] %></h1>
|
10
|
+
<%= (layout[:back_link].nil?) ? "" : "<a href='#{layout[:back_link]}'>#{layout[:back_link]}</a><br/>" %>
|
11
|
+
<h4><%= layout[:doc] %></h4>
|
12
|
+
</div>
|
13
|
+
<div class='navigation_panel'>
|
14
|
+
<ul>
|
15
|
+
<%= layout[:nav_entries].map{|entry|
|
16
|
+
"<li><a href='#{entry[:link]}' title='#{entry[:doc]}'>#{entry[:link_name]}</a></li>"
|
17
|
+
}.join("\n") %>
|
18
|
+
</ul>
|
19
|
+
</div>
|
20
|
+
<div class='content_body'>
|
21
|
+
<%= yield %>
|
22
|
+
</div>
|
23
|
+
<div class='content_footer'>
|
24
|
+
Powered by <a href='http://github.com/dannypurcell/rubysite'>Rubysite</a>!
|
25
|
+
</div>
|
26
|
+
</body>
|
27
|
+
</html>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<form name="<% form[:name] %>" action="<% form[:action] %>" method="<% form[:method] || "get" %>">
|
2
|
+
<% form[:fields].each do |field| %>
|
3
|
+
<% field[:text] %><input type='<% field[:type] %>' name='<% field[:name] %>'>
|
4
|
+
<% end %>
|
5
|
+
Username: <input type="text" name="user">
|
6
|
+
<input type="submit" value="Submit">
|
7
|
+
</form>
|
data/lib/rubysite.rb
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
require 'rubycom'
|
2
|
+
require 'sinatra'
|
3
|
+
require "sinatra/reloader" if development?
|
4
|
+
require 'json'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
# Provides a web interface for including modules
|
8
|
+
module Rubysite
|
9
|
+
class SiteError < StandardError;
|
10
|
+
end
|
11
|
+
|
12
|
+
# Detects that Rubysite was included in another module and calls Rubysite#run
|
13
|
+
#
|
14
|
+
# @param [Module] base the module which invoked 'include Rubysite'
|
15
|
+
def self.included(base)
|
16
|
+
base_file_path = caller.first.gsub(/:\d+:.+/, '')
|
17
|
+
if base.class == Module && (base_file_path == $0 || Rubycom.is_executed_by_gem?(base_file_path))
|
18
|
+
base.module_eval {
|
19
|
+
Rubysite.run(base, ARGV)
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Defines routes for all commands found in the including module and starts the web server
|
25
|
+
#
|
26
|
+
# @param [Module] base the module which invoked 'include Rubysite'
|
27
|
+
# @param [Array] args a String Array representing environment settings for the web server
|
28
|
+
def self.run(base, args=[])
|
29
|
+
args = [args] if args.class == String
|
30
|
+
base = Kernel.const_get(base.to_sym) if base.class == String
|
31
|
+
begin
|
32
|
+
raise SiteError, "Invalid base class invocation: #{base}" if base.nil?
|
33
|
+
Sinatra::Base::set :port, '8080'
|
34
|
+
Sinatra::Base::set :port, args[1] if !args[0].nil? && args[0] == '--port'
|
35
|
+
Sinatra::Base::set :port, args[0].split('=').last if !args[0].nil? && args[0].include?('--port=')
|
36
|
+
Sinatra::Base::set :root, Proc.new { File.join(File.expand_path(File.dirname(__FILE__)), 'rubysite') }
|
37
|
+
Sinatra::Base::set :public_folder, Proc.new { File.join(File.expand_path(File.dirname(__FILE__)), 'rubysite', 'public') }
|
38
|
+
Sinatra::Base::set :views, Proc.new { File.join(File.expand_path(File.dirname(__FILE__)), 'rubysite', 'views') }
|
39
|
+
Sinatra::Base::set :css_files, {default: File.join(File.expand_path(File.dirname(__FILE__)), 'rubysite', 'public', 'css', 'default.css')}
|
40
|
+
|
41
|
+
Rubysite.define_routes(base)
|
42
|
+
|
43
|
+
Sinatra::Base::run!
|
44
|
+
rescue SiteError => e
|
45
|
+
$stderr.puts e
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Recursively defines routes for the web service according to the commands included in the given base Module.
|
50
|
+
# Starts at '/'. Additionally defines any default routes required by the web service.
|
51
|
+
#
|
52
|
+
# @param [Module] base the Module for which a web interface should be generated
|
53
|
+
# @return [Array] a String array listing the routes which were defined for the given base Module
|
54
|
+
def self.define_routes(base)
|
55
|
+
base = Kernel.const_get(base.to_sym) if base.class == String
|
56
|
+
site_map = ['/', '/css', '/help'] + Rubysite.define_module_route(base)
|
57
|
+
|
58
|
+
Sinatra::Base::get "/?" do
|
59
|
+
layout = {
|
60
|
+
name: "#{base}",
|
61
|
+
doc: "A Rubysite generated service",
|
62
|
+
nav_entries: [
|
63
|
+
{link: '/', link_name: 'Home', doc: 'Home'},
|
64
|
+
{link: "/#{base}", link_name: "#{base}", doc: Rubycom::Documentation.get_module_doc(base)},
|
65
|
+
{link: "/help", link_name: "Help", doc: 'Interface documentation'}
|
66
|
+
]
|
67
|
+
}
|
68
|
+
erb(:index, locals: {layout: layout})
|
69
|
+
end
|
70
|
+
|
71
|
+
Sinatra::Base::get "/css/:css_name?" do |css_name|
|
72
|
+
css_sym = css_name.to_sym rescue :default
|
73
|
+
css_file = settings.css_files[css_sym] || settings.css_files[:default]
|
74
|
+
File.read(css_file)
|
75
|
+
end
|
76
|
+
|
77
|
+
Sinatra::Base::get "/help" do
|
78
|
+
layout = {
|
79
|
+
name: "Help",
|
80
|
+
back_link: "/",
|
81
|
+
doc: "Help page",
|
82
|
+
nav_entries: [
|
83
|
+
{link: '/', link_name: 'Home', doc: 'Home'},
|
84
|
+
{link: "/#{base}", link_name: "#{base}", doc: Rubycom::Documentation.get_module_doc(base)},
|
85
|
+
{link: "/help", link_name: "Help", doc: 'Interface documentation'}
|
86
|
+
]
|
87
|
+
}
|
88
|
+
help = {
|
89
|
+
site_map: site_map.flatten
|
90
|
+
}
|
91
|
+
erb(:help, locals: {layout: layout, help: help})
|
92
|
+
end
|
93
|
+
|
94
|
+
site_map.flatten
|
95
|
+
end
|
96
|
+
|
97
|
+
# Recursively defines routes for the web service according to the commands included in the given base Module.
|
98
|
+
# Starts at the given route_prefix.
|
99
|
+
#
|
100
|
+
# @param [Module] base the Module for which a web interface should be generated
|
101
|
+
# @param [String] route_prefix a route pattern to prefix on routes which will be generated in response to this call
|
102
|
+
# @return [Array] a String array listing the routes which were defined for the given base Module
|
103
|
+
def self.define_module_route(base, route_prefix='/')
|
104
|
+
base = Kernel.const_get(base.to_sym) if base.class == String
|
105
|
+
defined_routes = ["#{route_prefix.chomp('/')}/#{base.to_s}"]
|
106
|
+
|
107
|
+
commands = Rubycom::Commands.get_top_level_commands(base).select { |sym| sym != :Rubysite } || []
|
108
|
+
|
109
|
+
commands = commands.map { |command_sym|
|
110
|
+
if base.included_modules.map { |mod| mod.name.to_sym }.include?(command_sym)
|
111
|
+
defined_routes << Rubysite.define_module_route(base.included_modules.select { |mod| mod.name == command_sym.to_s }.first, defined_routes[0])
|
112
|
+
else
|
113
|
+
defined_routes << Rubysite.define_method_route(base, command_sym, defined_routes[0])
|
114
|
+
end
|
115
|
+
{
|
116
|
+
link: "#{defined_routes[0]}/#{command_sym.to_s}",
|
117
|
+
link_name: "#{command_sym.to_s}",
|
118
|
+
doc: Rubycom::Documentation.get_command_summary(base, command_sym, Rubycom::Documentation.get_separator(command_sym, Rubycom::Commands.get_longest_command_name(base).length)).gsub(command_sym.to_s, '')
|
119
|
+
}
|
120
|
+
} || []
|
121
|
+
|
122
|
+
Sinatra::Base::get "#{defined_routes[0]}/?" do
|
123
|
+
layout = {
|
124
|
+
name: "#{base}",
|
125
|
+
back_link: route_prefix,
|
126
|
+
doc: Rubycom::Documentation.get_module_doc(base.to_s),
|
127
|
+
nav_entries: [
|
128
|
+
{link: route_prefix, link_name: route_prefix.split('/').last || 'Home', doc: 'Back'},
|
129
|
+
] + commands + [ {link: "/help", link_name: "Help", doc: 'Interface documentation'} ]
|
130
|
+
}
|
131
|
+
command_list = {
|
132
|
+
command_list: commands
|
133
|
+
}
|
134
|
+
erb(:"module/command_list", locals: {layout: layout, command_list: command_list})
|
135
|
+
end
|
136
|
+
|
137
|
+
defined_routes.flatten
|
138
|
+
end
|
139
|
+
|
140
|
+
# Defines the route for the given command on the given base. The resulting route will be prefixed with the given route_prefix.
|
141
|
+
#
|
142
|
+
# @param [Module] base the Module which contains the specified command Method
|
143
|
+
# @param [Symbol] command the symbol representing the name of the command for which an interface should be generated
|
144
|
+
# @param [String] route_prefix a route pattern to prefix on routes which will be generated in response to this call
|
145
|
+
# @return [Array] a String array listing the routes which were defined for the given base Module
|
146
|
+
def self.define_method_route(base, command, route_prefix='/')
|
147
|
+
base = Kernel.const_get(base.to_sym) if base.class == String
|
148
|
+
defined_route = "#{route_prefix}/#{command.to_s}"
|
149
|
+
docs = Rubycom::Documentation.get_doc(base.public_method(command))
|
150
|
+
param_defs = Rubycom::Arguments.get_param_definitions(base.public_method(command))
|
151
|
+
route_params = param_defs.map { |key, val_hsh| (val_hsh[:type] == :opt) ? {":#{key}?" => val_hsh[:default]} : {":#{key}" => val_hsh[:default]} }.reduce(&:merge) || {}
|
152
|
+
Sinatra::Base::get "#{defined_route}/?" do
|
153
|
+
begin
|
154
|
+
rubysite_out = ''
|
155
|
+
def rubysite_out.write(data)
|
156
|
+
self << data
|
157
|
+
end
|
158
|
+
rubysite_err = ''
|
159
|
+
def rubysite_err.write(data)
|
160
|
+
self << data
|
161
|
+
end
|
162
|
+
o_stdout, $stdout = $stdout, rubysite_out
|
163
|
+
o_stderr, $stderr = $stderr, rubysite_err
|
164
|
+
|
165
|
+
puts Rubycom.call_method(base, command, params.map { |key, val| "--#{key}=#{val}" })
|
166
|
+
|
167
|
+
layout = {
|
168
|
+
name: "#{base}",
|
169
|
+
back_link: route_prefix,
|
170
|
+
nav_entries: [
|
171
|
+
{link: route_prefix, link_name: route_prefix.split('/').last || 'Home', doc: 'Parent Module'},
|
172
|
+
{link: "/help", link_name: "Help", doc: 'Interface documentation'}
|
173
|
+
]
|
174
|
+
}
|
175
|
+
result = {
|
176
|
+
params: params,
|
177
|
+
query: request.query_string,
|
178
|
+
param_defs: param_defs,
|
179
|
+
inputs: route_params.merge(params),
|
180
|
+
docs: docs,
|
181
|
+
output: rubysite_out,
|
182
|
+
error: rubysite_err
|
183
|
+
}
|
184
|
+
erb(:"method/result", locals: {layout: layout, result: result})
|
185
|
+
|
186
|
+
rescue Exception => e
|
187
|
+
layout = {
|
188
|
+
name: "#{base}",
|
189
|
+
back_link: route_prefix,
|
190
|
+
nav_entries: [
|
191
|
+
{link: route_prefix, link_name: route_prefix.split('/').last || 'Home', doc: 'Parent Module'},
|
192
|
+
{link: "/help", link_name: "Help", doc: 'Interface documentation'}
|
193
|
+
]
|
194
|
+
}
|
195
|
+
error = {
|
196
|
+
base: base,
|
197
|
+
message: e.message
|
198
|
+
}
|
199
|
+
erb(:"method/error", locals: {layout: layout, error: error})
|
200
|
+
ensure
|
201
|
+
$stdout = o_stdout
|
202
|
+
$stderr = o_stderr
|
203
|
+
end
|
204
|
+
end
|
205
|
+
defined_route
|
206
|
+
end
|
207
|
+
|
208
|
+
end
|
data/rubysite.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rubysite/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rubysite"
|
8
|
+
spec.version = Rubysite::VERSION
|
9
|
+
spec.authors = ["Danny Purcell"]
|
10
|
+
spec.email = ["d.purcell.jr+rubysite@gmail.com"]
|
11
|
+
spec.description = %q{Provides web access for singleton methods in an including module. Allows the user to make a web service by simply including Rubysite.}
|
12
|
+
spec.summary = %q{Converts singleton methods to web service routes upon inclusion.}
|
13
|
+
spec.homepage = "http://github.com/dannypurcell/Rubysite"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "test-unit"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_dependency 'rubycom'
|
25
|
+
spec.add_dependency 'sinatra'
|
26
|
+
spec.add_dependency 'sinatra-contrib'
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/../../lib/rubysite.rb"
|
3
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/util_test_module.rb"
|
4
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/util_test_no_singleton.rb"
|
5
|
+
|
6
|
+
module UtilTestComposite
|
7
|
+
include UtilTestModule
|
8
|
+
|
9
|
+
include UtilTestNoSingleton
|
10
|
+
|
11
|
+
# A test_command in a composite console
|
12
|
+
#
|
13
|
+
# @param [String] test_arg a test argument
|
14
|
+
# @return [String] the test arg
|
15
|
+
def self.test_composite_command(test_arg)
|
16
|
+
test_arg
|
17
|
+
end
|
18
|
+
|
19
|
+
include Rubysite
|
20
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require "#{File.expand_path(File.dirname(__FILE__))}/../../lib/rubysite.rb"
|
2
|
+
# A command module used for testing
|
3
|
+
module UtilTestModule
|
4
|
+
|
5
|
+
# A test non-command method
|
6
|
+
def non_command
|
7
|
+
puts 'fail'
|
8
|
+
end
|
9
|
+
|
10
|
+
# A basic test command
|
11
|
+
def self.test_command
|
12
|
+
puts 'command test'
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.test_command_no_docs
|
16
|
+
puts 'command test'
|
17
|
+
end
|
18
|
+
|
19
|
+
# A test_command with one arg
|
20
|
+
#
|
21
|
+
# @param [String] test_arg a test argument
|
22
|
+
def self.test_command_with_arg(test_arg)
|
23
|
+
"test_arg=#{test_arg}"
|
24
|
+
end
|
25
|
+
|
26
|
+
# A test_command with an arg named arg
|
27
|
+
#
|
28
|
+
# @param [String] arg a test argument whose parameter name is arg
|
29
|
+
def self.test_command_arg_named_arg(arg)
|
30
|
+
"arg=#{arg}"
|
31
|
+
end
|
32
|
+
|
33
|
+
# A test_command with two args
|
34
|
+
# @param [String] test_arg a test argument
|
35
|
+
# @param [String] another_test_arg another test argument
|
36
|
+
def self.test_command_with_args(test_arg, another_test_arg)
|
37
|
+
puts "test_arg=#{test_arg},another_test_arg=#{another_test_arg}"
|
38
|
+
end
|
39
|
+
|
40
|
+
# A test_command with an optional argument
|
41
|
+
# @param [String] test_arg a test argument
|
42
|
+
# @param [String] test_option an optional test argument
|
43
|
+
def self.test_command_with_options(test_arg, test_option='option_default')
|
44
|
+
puts "test_arg=#{test_arg},test_option=#{test_option}"
|
45
|
+
end
|
46
|
+
|
47
|
+
# A test_command with all optional arguments
|
48
|
+
# @param [String] test_arg an optional test argument
|
49
|
+
# @param [String] test_option another optional test argument
|
50
|
+
def self.test_command_all_options(test_arg='test_arg_default', test_option='test_option_default')
|
51
|
+
puts "Output is test_arg=#{test_arg},test_option=#{test_option}"
|
52
|
+
end
|
53
|
+
|
54
|
+
# A test_command with an options array
|
55
|
+
# @param [String] test_option an optional test argument
|
56
|
+
# @param [String] test_options an optional array of arguments
|
57
|
+
def self.test_command_options_arr (
|
58
|
+
test_option="test_option_default",
|
59
|
+
*test_options
|
60
|
+
)
|
61
|
+
puts "Output is test_option=#{test_option},test_option_arr=#{test_options}"
|
62
|
+
end
|
63
|
+
|
64
|
+
# A test_command with a return argument
|
65
|
+
#
|
66
|
+
# @param [String] test_arg a test argument
|
67
|
+
# @param [Integer] test_option_int an optional test argument which happens to be an Integer
|
68
|
+
# @return [Array] an array including both params if test_option_int != 1
|
69
|
+
# @return [String] a the first param if test_option_int == 1
|
70
|
+
def self.test_command_with_return(test_arg, test_option_int=1)
|
71
|
+
ret = [test_arg, test_option_int]
|
72
|
+
if test_option_int == 1
|
73
|
+
ret = test_arg
|
74
|
+
end
|
75
|
+
ret
|
76
|
+
end
|
77
|
+
|
78
|
+
# A test_command with a Timestamp argument and an unnecessarily long description which should overflow when
|
79
|
+
# it tries to line up with other descriptions.
|
80
|
+
# @param [Timestamp] test_time a test Timestamp argument
|
81
|
+
# @return [Hash] a hash including the given argument
|
82
|
+
def self.test_command_arg_timestamp(test_time)
|
83
|
+
{test_time: test_time}
|
84
|
+
end
|
85
|
+
|
86
|
+
# A test_command with a Boolean argument
|
87
|
+
# @param [Boolean] test_flag a test Boolean argument
|
88
|
+
# @return [Boolean] the flag passed in
|
89
|
+
def self.test_command_arg_false(test_flag=false)
|
90
|
+
test_flag
|
91
|
+
end
|
92
|
+
|
93
|
+
# A test_command with an array argument
|
94
|
+
#
|
95
|
+
# @param [Array] test_arr an Array test argument
|
96
|
+
def self.test_command_arg_arr(test_arr=[])
|
97
|
+
test_arr
|
98
|
+
end
|
99
|
+
|
100
|
+
# A test_command with an Hash argument
|
101
|
+
# @param [Hash] test_hash a Hash test argument
|
102
|
+
def self.test_command_arg_hash(test_hash={})
|
103
|
+
test_hash
|
104
|
+
end
|
105
|
+
|
106
|
+
# A test_command with several mixed options
|
107
|
+
def self.test_command_mixed_options(test_arg, test_arr=[], test_opt='test_opt_arg', test_hsh={}, test_bool=true, *test_rest)
|
108
|
+
"test_arg=#{test_arg} test_arr=#{test_arr} test_opt=#{test_opt} test_hsh=#{test_hsh} test_bool=#{test_bool} test_rest=#{test_rest}"
|
109
|
+
end
|
110
|
+
|
111
|
+
include Rubysite
|
112
|
+
end
|
metadata
ADDED
@@ -0,0 +1,154 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rubysite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Danny Purcell
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: test-unit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubycom
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: sinatra
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: sinatra-contrib
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Provides web access for singleton methods in an including module. Allows
|
98
|
+
the user to make a web service by simply including Rubysite.
|
99
|
+
email:
|
100
|
+
- d.purcell.jr+rubysite@gmail.com
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- .gitignore
|
106
|
+
- Gemfile
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- Rakefile
|
110
|
+
- lib/rubysite.rb
|
111
|
+
- lib/rubysite/public/css/default.css
|
112
|
+
- lib/rubysite/version.rb
|
113
|
+
- lib/rubysite/views/help.erb
|
114
|
+
- lib/rubysite/views/index.erb
|
115
|
+
- lib/rubysite/views/layout.erb
|
116
|
+
- lib/rubysite/views/method/error.erb
|
117
|
+
- lib/rubysite/views/method/form.erb
|
118
|
+
- lib/rubysite/views/method/result.erb
|
119
|
+
- lib/rubysite/views/module/command_list.erb
|
120
|
+
- rubysite.gemspec
|
121
|
+
- test/rubysite/rubysite_test.rb
|
122
|
+
- test/rubysite/util_test_composite.rb
|
123
|
+
- test/rubysite/util_test_module.rb
|
124
|
+
- test/rubysite/util_test_no_singleton.rb
|
125
|
+
homepage: http://github.com/dannypurcell/Rubysite
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ! '>='
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '0'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubyforge_project:
|
145
|
+
rubygems_version: 2.0.3
|
146
|
+
signing_key:
|
147
|
+
specification_version: 4
|
148
|
+
summary: Converts singleton methods to web service routes upon inclusion.
|
149
|
+
test_files:
|
150
|
+
- test/rubysite/rubysite_test.rb
|
151
|
+
- test/rubysite/util_test_composite.rb
|
152
|
+
- test/rubysite/util_test_module.rb
|
153
|
+
- test/rubysite/util_test_no_singleton.rb
|
154
|
+
has_rdoc:
|