ivanvc-sweat 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +4 -0
- data/Rakefile +18 -0
- data/VERSION +1 -0
- data/ext/extconf.rb +4 -0
- data/ext/sweat.c +140 -0
- metadata +70 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Iván Valdés (@ivanvc)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "ivanvc-sweat"
|
8
|
+
gem.summary = ''
|
9
|
+
gem.description = ''
|
10
|
+
gem.email = "iv@nvald.es"
|
11
|
+
gem.homepage = "http://github.com/ivanvc/sweat"
|
12
|
+
gem.authors = ["Iván Valdés (@ivanvc)"]
|
13
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
14
|
+
end
|
15
|
+
Jeweler::GemcutterTasks.new
|
16
|
+
rescue LoadError
|
17
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
18
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
data/ext/extconf.rb
ADDED
data/ext/sweat.c
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
#include "version.h"
|
3
|
+
|
4
|
+
#ifndef TEMPLATESSIZE
|
5
|
+
#define TEMPLATESSIZE 20
|
6
|
+
#endif
|
7
|
+
|
8
|
+
typedef struct app_struct
|
9
|
+
{
|
10
|
+
VALUE id;
|
11
|
+
int app_templates[TEMPLATESSIZE];
|
12
|
+
int app_templates_index;
|
13
|
+
int index;
|
14
|
+
VALUE templates;
|
15
|
+
struct app_struct *next;
|
16
|
+
} app_struct;
|
17
|
+
|
18
|
+
app_struct *app_push(app_struct **p, VALUE id, int app_template, VALUE templates)
|
19
|
+
{
|
20
|
+
if (p == NULL)
|
21
|
+
return NULL;
|
22
|
+
|
23
|
+
app_struct *n = malloc(sizeof(app_struct));
|
24
|
+
if (n == NULL)
|
25
|
+
return NULL;
|
26
|
+
|
27
|
+
int current_index = 0;
|
28
|
+
if((*p) != NULL)
|
29
|
+
current_index = (*p)->index + 1;
|
30
|
+
|
31
|
+
n->next = *p;
|
32
|
+
*p = n;
|
33
|
+
n->id = id;
|
34
|
+
n->app_templates[0] = app_template;
|
35
|
+
n->app_templates_index = 1;
|
36
|
+
n->index = current_index;
|
37
|
+
n->templates = templates;
|
38
|
+
|
39
|
+
return *p;
|
40
|
+
}
|
41
|
+
|
42
|
+
void app_push_template(app_struct *p, int app_template, VALUE template)
|
43
|
+
{
|
44
|
+
p->app_templates[p->app_templates_index++] = app_template;
|
45
|
+
rb_ary_push(p->templates, template);
|
46
|
+
}
|
47
|
+
|
48
|
+
void app_remove(app_struct **p)
|
49
|
+
{
|
50
|
+
if (p != NULL && *p != NULL)
|
51
|
+
{
|
52
|
+
app_struct *n = *p;
|
53
|
+
*p = (*p)->next;
|
54
|
+
free(n);
|
55
|
+
}
|
56
|
+
}
|
57
|
+
|
58
|
+
app_struct *app_search(app_struct **n, VALUE id)
|
59
|
+
{
|
60
|
+
if(n == NULL || *n == NULL)
|
61
|
+
return NULL;
|
62
|
+
|
63
|
+
if((*n)->id == id)
|
64
|
+
return *n;
|
65
|
+
|
66
|
+
return &(*app_search(&(*n)->next, id));
|
67
|
+
}
|
68
|
+
|
69
|
+
int app_template_search(app_struct *n, int app_template_id)
|
70
|
+
{
|
71
|
+
return app_template_search_n(n, app_template_id, 0);
|
72
|
+
}
|
73
|
+
|
74
|
+
int app_template_search_n(app_struct *n, int app_template_id, int index)
|
75
|
+
{
|
76
|
+
if(index >= n->app_templates_index)
|
77
|
+
return 0;
|
78
|
+
if(app_template_id == n->app_templates[index])
|
79
|
+
return 1;
|
80
|
+
return app_template_search_n(n, app_template_id, ++index);
|
81
|
+
}
|
82
|
+
|
83
|
+
VALUE rb_mSweat;
|
84
|
+
|
85
|
+
VALUE rb_Sweat_candy(VALUE self, VALUE apps_array)
|
86
|
+
{
|
87
|
+
VALUE apps = rb_ary_new();
|
88
|
+
VALUE cApp = rb_const_get(rb_cObject, rb_intern("App"));
|
89
|
+
VALUE cApp_template = rb_const_get(rb_cObject, rb_intern("AppTemplate"));
|
90
|
+
app_struct *app_list = NULL;
|
91
|
+
app_struct *current_app_struct;
|
92
|
+
|
93
|
+
int i;
|
94
|
+
for(i = 0; i < RARRAY(apps_array)->len; ++i)
|
95
|
+
{
|
96
|
+
VALUE hash = rb_ary_entry(apps_array, i);
|
97
|
+
VALUE current_app_id = rb_hash_aref(hash, rb_str_new2("app_id"));
|
98
|
+
VALUE current_app_template_id = rb_hash_aref(hash, rb_str_new2("app_template_id"));
|
99
|
+
if(NIL_P(current_app_template_id))
|
100
|
+
continue;
|
101
|
+
int current_app_template_id_int = FIX2INT(current_app_template_id);
|
102
|
+
|
103
|
+
VALUE current_app_instance = rb_funcall(cApp, rb_intern("find"), 1, current_app_id);
|
104
|
+
|
105
|
+
if(NIL_P(current_app_instance))
|
106
|
+
continue;
|
107
|
+
current_app_struct = app_search(&app_list, current_app_id);
|
108
|
+
if(current_app_struct == NULL)
|
109
|
+
{
|
110
|
+
VALUE hash_app = rb_funcall(current_app_instance, rb_intern("as_json"), 0);
|
111
|
+
VALUE installation_repository_app = rb_funcall(current_app_instance, rb_intern("installation_repository_app"), 0);
|
112
|
+
VALUE app_template = rb_funcall(cApp_template, rb_intern("find"), 1, current_app_template_id);
|
113
|
+
VALUE templates = rb_ary_new();
|
114
|
+
rb_ary_push(templates, rb_funcall(app_template, rb_intern("as_json"), 0));
|
115
|
+
rb_hash_aset(hash_app, rb_str_new2("templates"), templates);
|
116
|
+
rb_hash_aset(hash_app, rb_str_new2("installation_repository_app"), rb_funcall(installation_repository_app, rb_intern("as_json"), 0));
|
117
|
+
rb_ary_push(apps, hash_app);
|
118
|
+
app_push(&app_list, current_app_id, current_app_template_id_int, templates);
|
119
|
+
} else
|
120
|
+
{
|
121
|
+
if(!app_template_search(current_app_struct, current_app_template_id_int))
|
122
|
+
{
|
123
|
+
VALUE app_template = rb_funcall(cApp_template, rb_intern("find"), 1, current_app_template_id);
|
124
|
+
app_push_template(current_app_struct, current_app_template_id_int, rb_funcall(app_template, rb_intern("as_json"), 0));
|
125
|
+
}
|
126
|
+
}
|
127
|
+
}
|
128
|
+
|
129
|
+
while(app_list != NULL)
|
130
|
+
app_remove(&app_list);
|
131
|
+
|
132
|
+
return apps;
|
133
|
+
}
|
134
|
+
|
135
|
+
void Init_sweat()
|
136
|
+
{
|
137
|
+
rb_mSweat = rb_define_module("Sweat");
|
138
|
+
|
139
|
+
rb_define_method(rb_mSweat, "candy", rb_Sweat_candy, 1);
|
140
|
+
}
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ivanvc-sweat
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- "Iv\xC3\xA1n Vald\xC3\xA9s (@ivanvc)"
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-07-08 00:00:00 -05:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: ""
|
22
|
+
email: iv@nvald.es
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions:
|
26
|
+
- ext/extconf.rb
|
27
|
+
extra_rdoc_files:
|
28
|
+
- LICENSE
|
29
|
+
- README.rdoc
|
30
|
+
files:
|
31
|
+
- .document
|
32
|
+
- .gitignore
|
33
|
+
- LICENSE
|
34
|
+
- README.rdoc
|
35
|
+
- Rakefile
|
36
|
+
- VERSION
|
37
|
+
- ext/extconf.rb
|
38
|
+
- ext/sweat.c
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/ivanvc/sweat
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --charset=UTF-8
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
segments:
|
53
|
+
- 0
|
54
|
+
version: "0"
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
requirements: []
|
63
|
+
|
64
|
+
rubyforge_project:
|
65
|
+
rubygems_version: 1.3.6
|
66
|
+
signing_key:
|
67
|
+
specification_version: 3
|
68
|
+
summary: ""
|
69
|
+
test_files: []
|
70
|
+
|