Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
reference-repository
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
GitLab upgrade completed. Current version is 17.11.4.
Show more breadcrumbs
grid5000
reference-repository
Commits
b3a6a77e
Commit
b3a6a77e
authored
16 years ago
by
Cyril Rohr
Committed by
g5kadmin user
16 years ago
Browse files
Options
Downloads
Patches
Plain Diff
refactored so that it works with ruby < 1.8.7
parent
55638816
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
generators/lib/core_extensions.rb
+19
-1
19 additions, 1 deletion
generators/lib/core_extensions.rb
generators/lib/g5k_generator.rb
+57
-19
57 additions, 19 deletions
generators/lib/g5k_generator.rb
with
76 additions
and
20 deletions
generators/lib/core_extensions.rb
+
19
−
1
View file @
b3a6a77e
...
...
@@ -91,4 +91,22 @@ class Hash
result
end
end
\ No newline at end of file
end
# for versions of ruby < 1.8.7
module
Enumerable
def
index_by
inject
({})
do
|
accum
,
elem
|
accum
[
yield
(
elem
)]
=
elem
accum
end
end
def
group_by
#:yield:
#h = k = e = nil
r
=
Hash
.
new
each
{
|
e
|
(
r
[
yield
(
e
)]
||=
[])
<<
e
}
r
end
end
This diff is collapsed.
Click to expand it.
generators/lib/g5k_generator.rb
+
57
−
19
View file @
b3a6a77e
...
...
@@ -63,27 +63,65 @@ class ReferenceGenerator
Resolv
.
getaddress
(
network_address
)
end
%w{site cluster environment node service}
.
each
do
|
method
|
define_method
(
method
)
do
|
uid
,
*
options
,
&
block
|
key
=
method
.
pluralize
.
to_sym
uid
=
uid
.
to_s
options
=
options
.
first
||
Hash
.
new
old_context
=
@context
@context
[
key
]
||=
G5K
::
Folder
.
new
if
options
.
has_key?
:refer_to
@context
[
key
]
<<
G5K
::
Link
.
new
(
uid
,
options
[
:refer_to
])
else
# if the same object already exists, we return it for completion/modification
if
(
same_trees
=
@context
[
key
].
select
{
|
tree
|
tree
[
:uid
]
==
uid
}).
size
>
0
@context
=
same_trees
.
first
else
@context
[
key
]
<<
G5K
::
Tree
.
new
.
replace
({
:uid
=>
uid
,
:type
=>
method
})
@context
=
@context
[
key
].
last
end
block
.
call
(
uid
)
if
block
# This doesn't work with Ruby < 1.8.7. Replaced by a call to build_context (see below).
#
# %w{site cluster environment node service}.each do |method|
# define_method(method) do |uid, *options, &block|
# key = method.pluralize.to_sym
# uid = uid.to_s
# options = options.first || Hash.new
# old_context = @context
# @context[key] ||= G5K::Folder.new
# if options.has_key? :refer_to
# @context[key] << G5K::Link.new(uid, options[:refer_to])
# else
# # if the same object already exists, we return it for completion/modification
# if (same_trees = @context[key].select{|tree| tree[:uid] == uid}).size > 0
# @context = same_trees.first
# else
# @context[key] << G5K::Tree.new.replace({:uid => uid, :type => method})
# @context = @context[key].last
# end
# block.call(uid) if block
# end
# @context = old_context
# end
# end
def
site
(
uid
,
*
options
,
&
block
)
build_context
(
:sites
,
uid
,
*
options
,
&
block
)
end
def
cluster
(
uid
,
*
options
,
&
block
)
build_context
(
:clusters
,
uid
,
*
options
,
&
block
)
end
def
environment
(
uid
,
*
options
,
&
block
)
build_context
(
:environments
,
uid
,
*
options
,
&
block
)
end
def
node
(
uid
,
*
options
,
&
block
)
build_context
(
:nodes
,
uid
,
*
options
,
&
block
)
end
def
service
(
uid
,
*
options
,
&
block
)
build_context
(
:services
,
uid
,
*
options
,
&
block
)
end
def
build_context
(
key
,
uid
,
*
options
,
&
block
)
type
=
key
.
to_s
.
chop
uid
=
uid
.
to_s
options
=
options
.
first
||
Hash
.
new
old_context
=
@context
@context
[
key
]
||=
G5K
::
Folder
.
new
if
options
.
has_key?
:refer_to
@context
[
key
]
<<
G5K
::
Link
.
new
(
uid
,
options
[
:refer_to
])
else
# if the same object already exists, we return it for completion/modification
if
(
same_trees
=
@context
[
key
].
select
{
|
tree
|
tree
[
:uid
]
==
uid
}).
size
>
0
@context
=
same_trees
.
first
else
@context
[
key
]
<<
G5K
::
Tree
.
new
.
replace
({
:uid
=>
uid
,
:type
=>
type
})
@context
=
@context
[
key
].
last
end
@context
=
old_context
block
.
call
(
uid
)
if
block
end
@context
=
old_context
end
# Initializes a new generator that will generates data files in a hierachical way.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment