Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
Noah
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Noah
Commits
4386dac7
Commit
4386dac7
authored
Mar 09, 2011
by
John E. Vincent
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ephemeral nodes. no specs yet
parent
48a08b0e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
7 deletions
+36
-7
app.rb
lib/noah/app.rb
+1
-1
ephemeral_routes.rb
lib/noah/ephemeral_routes.rb
+28
-5
ephemerals.rb
lib/noah/models/ephemerals.rb
+7
-1
No files found.
lib/noah/app.rb
View file @
4386dac7
...
...
@@ -63,7 +63,7 @@ module Noah
load
File
.
join
(
File
.
dirname
(
__FILE__
),
'application_routes.rb'
)
load
File
.
join
(
File
.
dirname
(
__FILE__
),
'configuration_routes.rb'
)
load
File
.
join
(
File
.
dirname
(
__FILE__
),
'watcher_routes.rb'
)
#load File.joint
(File.dirname(__FILE__), 'ephemeral_routes.rb')
load
File
.
join
(
File
.
dirname
(
__FILE__
),
'ephemeral_routes.rb'
)
end
end
lib/noah/ephemeral_routes.rb
View file @
4386dac7
require
'logger'
require
'base64'
class
Noah
::
App
# Stubbing Ephemeral endpoints
get
'/e/?'
do
halt
404
end
get
'/e/*'
do
# Some logic to handle splats for ephemerals
# Eventually I'll move to root path
logger
=
Logger
.
new
(
STDOUT
)
params
[
"splat"
].
size
==
0
?
(
halt
404
)
:
(
e
=
Noah
::
Ephemeral
.
find
(
:path
=>
"/
#{
params
[
"splat"
][
0
]
}
"
).
first
)
return
e
.
to_json
end
put
'/e/*/watch'
do
# Logic for adding watches to ephemerals
required_params
=
[
"endpoint"
]
data
=
JSON
.
parse
(
request
.
body
.
read
)
(
data
.
keys
.
sort
==
required_params
.
sort
)
?
(
e
=
Noah
::
Watcher
.
find
(:
path
=>
params
[
:splat
][
0
]).
first
)
:
(
raise
"Missing Parameters"
)
e
.
nil?
?
(
halt
404
)
:
(
w
=
e
.
watch!
(
:endpoint
=>
data
[
"endpoint"
]))
w
.
to_json
end
put
'/e/*'
do
# Some logic for creating ephemerals
raise
(
"Data too large"
)
if
request
.
body
.
size
>
512
d
=
Base64
.
encode64
(
request
.
body
.
read
)
||
nil
e
=
Noah
::
Ephemeral
.
new
(
:path
=>
params
[
:splat
][
0
],
:data
=>
d
)
e
.
valid?
?
(
e
.
save
;
e
.
to_json
)
:
(
raise
"
#{
e
.
errors
}
"
)
end
delete
'/e/*'
do
# See previous two entries
p
=
params
[
:splat
][
0
]
e
=
Noah
::
Ephemeral
.
find
(
:path
=>
p
).
first
if
e
e
.
delete
r
=
{
"result"
=>
"success"
,
"id"
=>
"
#{
e
.
id
}
"
,
"action"
=>
"delete"
,
"path"
=>
e
.
name
}
r
.
to_json
else
halt
404
end
end
end
lib/noah/models/ephemerals.rb
View file @
4386dac7
require
'
digest/sha1
'
require
'
base64
'
module
Noah
class
Ephemeral
<
Model
#NYI
attribute
:path
attribute
:data
attribute
:lifetime
index
:path
...
...
@@ -17,6 +18,11 @@ module Noah
@name
=
path
end
def
to_hash
data
.
nil?
?
d
=
nil
:
d
=
Base64
.
decode64
(
data
)
h
=
{
:path
=>
path
,
:data
=>
d
,
:created_at
=>
created_at
,
:updated_at
=>
:updated_at
}
super
.
merge
(
h
)
end
protected
def
save_hook
# called after any create,update,delete
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment