rejuicer 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/ext/rejuicer_set.c +2 -6
- data/lib/rejuicer.rb +7 -4
- metadata +3 -3
data/ext/rejuicer_set.c
CHANGED
@@ -367,9 +367,7 @@ static VALUE t_add(VALUE self, VALUE value)
|
|
367
367
|
unsigned int num;
|
368
368
|
|
369
369
|
Data_Get_Struct(self, struct _root_node, root);
|
370
|
-
|
371
|
-
add_num(root, num);
|
372
|
-
}
|
370
|
+
add_num(root, NUM2UINT(value));
|
373
371
|
|
374
372
|
return self;
|
375
373
|
}
|
@@ -383,9 +381,7 @@ static VALUE t_delete(VALUE self, VALUE value)
|
|
383
381
|
unsigned int num;
|
384
382
|
|
385
383
|
Data_Get_Struct(self, struct _root_node, root);
|
386
|
-
|
387
|
-
delete_num(root, num);
|
388
|
-
}
|
384
|
+
delete_num(root, NUM2UINT(value));
|
389
385
|
|
390
386
|
return self;
|
391
387
|
}
|
data/lib/rejuicer.rb
CHANGED
@@ -21,6 +21,7 @@ class Rejuicer
|
|
21
21
|
# that index target
|
22
22
|
#
|
23
23
|
def initialize(*args)
|
24
|
+
@base = RejuicerSet.new
|
24
25
|
@tree = args.inject({}){|t,i| t[i.to_sym] = {};t}
|
25
26
|
end
|
26
27
|
|
@@ -39,10 +40,11 @@ class Rejuicer
|
|
39
40
|
# id_attr : index id
|
40
41
|
#
|
41
42
|
def add(obj, id_attr = :id)
|
43
|
+
obj_id = obj.__send__(id_attr)
|
44
|
+
@base << obj_id
|
42
45
|
@tree.keys.each do |k|
|
43
46
|
begin
|
44
47
|
at = obj.__send__(k)
|
45
|
-
obj_id = obj.__send__(id_attr)
|
46
48
|
rescue NoMethodError
|
47
49
|
next
|
48
50
|
end
|
@@ -59,10 +61,11 @@ class Rejuicer
|
|
59
61
|
# id_attr : index id
|
60
62
|
#
|
61
63
|
def delete(obj, id_attr = :id)
|
64
|
+
obj_id = obj.__send__(id_attr)
|
65
|
+
@base.delete(obj_id)
|
62
66
|
@tree.keys.each do |k|
|
63
67
|
begin
|
64
68
|
at = obj.__send__(k)
|
65
|
-
obj_id = obj.__send__(id_attr)
|
66
69
|
rescue NoMethodError
|
67
70
|
next
|
68
71
|
end
|
@@ -76,8 +79,8 @@ class Rejuicer
|
|
76
79
|
# search
|
77
80
|
# conditions: search target
|
78
81
|
#
|
79
|
-
def search(conditions)
|
80
|
-
|
82
|
+
def search(conditions = nil)
|
83
|
+
return @base.to_a if conditions.nil? || conditions.empty?
|
81
84
|
|
82
85
|
f_cond = conditions.shift
|
83
86
|
f_set = @tree[f_cond.first.to_sym][f_cond.last]
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rejuicer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tsukasa OISHI
|