lore 0.4.3 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/custom_models.rb +93 -0
- data/lib/lore/README.txt +3 -3
- data/lib/lore/cache/abstract_entity_cache.rb +1 -1
- data/lib/lore/cache/mmap_entity_cache.rb +9 -9
- data/lib/lore/clause.rb +29 -25
- data/lib/lore/gui/erb_template.rb +3 -3
- data/lib/lore/gui/form_element.rb +2 -2
- data/lib/lore/gui/templates/button.rhtml +0 -0
- data/lib/lore/gui/templates/checkbox.rhtml +0 -0
- data/lib/lore/gui/templates/file.rhtml +0 -0
- data/lib/lore/gui/templates/form_element.rhtml +0 -0
- data/lib/lore/gui/templates/form_table.rhtml +0 -0
- data/lib/lore/gui/templates/radio.rhtml +0 -0
- data/lib/lore/gui/templates/select.rhtml +0 -0
- data/lib/lore/gui/templates/text.rhtml +0 -0
- data/lib/lore/gui/templates/text_readonly.rhtml +0 -0
- data/lib/lore/gui/templates/textarea.rhtml +0 -0
- data/lib/lore/result.rb +19 -0
- data/lib/lore/table_accessor.rb +56 -221
- data/lib/lore/table_instance.rb +4 -2
- data/lib/lore/table_selector.rb +12 -11
- data/lib/lore.rb +1 -1
- data/lore.gemspec +5 -3
- data/test/model.rb +1 -1
- data/test/tc_aspect.rb +1 -1
- data/test/tc_cache.rb +5 -2
- data/test/tc_clause.rb +1 -1
- data/test/tc_deep_inheritance.rb +1 -1
- data/test/tc_factory.rb +1 -1
- data/test/tc_filter.rb +1 -1
- data/test/tc_form.rb +1 -1
- data/test/tc_model.rb +57 -3
- data/test/tc_prepare.rb +1 -2
- data/test/tc_refined_query.rb +1 -1
- data/test/tc_table_accessor.rb +2 -0
- data/test/tc_thread.rb +100 -0
- data/test/test_lore.rb +12 -11
- metadata +6 -6
- data/lore-0.4.3.gem +0 -0
- data/test/lore_test.log +0 -617
data/custom_models.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
|
2
|
+
require('lore/model')
|
3
|
+
|
4
|
+
module Some
|
5
|
+
module App
|
6
|
+
|
7
|
+
class New_Model < Lore::Model
|
8
|
+
table :new_model, :public
|
9
|
+
primary_key :model_id, :model_id_seq
|
10
|
+
has_attribute :name, Lore::Type.integer
|
11
|
+
has_attribute :created, Lore::Type.timestamp
|
12
|
+
has_attribute :model_id, Lore::Type.integer
|
13
|
+
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module Some
|
20
|
+
module App
|
21
|
+
|
22
|
+
class New_Model < Lore::Model
|
23
|
+
table :new_model, :public
|
24
|
+
primary_key :model_id, :model_id_seq
|
25
|
+
has_attribute :name, Lore::Type.integer
|
26
|
+
has_attribute :created, Lore::Type.timestamp
|
27
|
+
has_attribute :model_id, Lore::Type.integer
|
28
|
+
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module Some
|
35
|
+
module App
|
36
|
+
|
37
|
+
class New_Model < Lore::Model
|
38
|
+
table :new_model, :public
|
39
|
+
primary_key :model_id, :model_id_seq
|
40
|
+
has_attribute :name, Lore::Type.integer
|
41
|
+
has_attribute :created, Lore::Type.timestamp
|
42
|
+
has_attribute :model_id, Lore::Type.integer
|
43
|
+
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
module Some
|
50
|
+
module App
|
51
|
+
|
52
|
+
class New_Model < Lore::Model
|
53
|
+
table :new_model, :public
|
54
|
+
primary_key :model_id, :model_id_seq
|
55
|
+
has_attribute :name, Lore::Type.integer
|
56
|
+
has_attribute :created, Lore::Type.timestamp
|
57
|
+
has_attribute :model_id, Lore::Type.integer
|
58
|
+
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
module Some
|
65
|
+
module App
|
66
|
+
|
67
|
+
class New_Model < Lore::Model
|
68
|
+
table :new_model, :public
|
69
|
+
primary_key :model_id, :model_id_seq
|
70
|
+
has_attribute :name, Lore::Type.integer
|
71
|
+
has_attribute :created, Lore::Type.timestamp
|
72
|
+
has_attribute :model_id, Lore::Type.integer
|
73
|
+
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
module Some
|
80
|
+
module App
|
81
|
+
|
82
|
+
class New_Model < Lore::Model
|
83
|
+
table :new_model, :public
|
84
|
+
primary_key :model_id, :model_id_seq
|
85
|
+
has_attribute :name, Lore::Type.integer
|
86
|
+
has_attribute :created, Lore::Type.timestamp
|
87
|
+
has_attribute :model_id, Lore::Type.integer
|
88
|
+
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
data/lib/lore/README.txt
CHANGED
@@ -26,9 +26,9 @@ A: First provide login data for a database (aka Context):
|
|
26
26
|
|
27
27
|
Lore::Context.enter :dbname
|
28
28
|
# Operate in database dbname
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
Lore::Context.enter :other_dbname
|
30
|
+
# Operate in database other_dbname
|
31
|
+
Lore::Context.leave
|
32
32
|
# Operate in database dbname
|
33
33
|
Lore::Context.enter :other_dbname
|
34
34
|
|
@@ -45,7 +45,7 @@ module Cache
|
|
45
45
|
# Create cache entry for a specific query_string on a model.
|
46
46
|
# Expects result from given query string as it has to be
|
47
47
|
# returned when calling Cache_Implementation.read(query_string)
|
48
|
-
def self.create(accessor,
|
48
|
+
def self.create(accessor, query_object, result)
|
49
49
|
raise ::Exception.new('Not implemented')
|
50
50
|
end
|
51
51
|
|
@@ -33,20 +33,20 @@ module Cache
|
|
33
33
|
}
|
34
34
|
end
|
35
35
|
|
36
|
-
def self.read(accessor,
|
37
|
-
@@logger.debug('Loading from cache: ' << index_for(
|
38
|
-
store = Mmap.new(storefile_of(accessor.table_name,
|
36
|
+
def self.read(accessor, query_obj)
|
37
|
+
@@logger.debug('Loading from cache: ' << index_for(query_obj[:query]))
|
38
|
+
store = Mmap.new(storefile_of(accessor.table_name, query_obj[:query]))
|
39
39
|
@@logger.debug('STORE: ' << store.inspect)
|
40
40
|
return [] unless store
|
41
41
|
result = Marshal::load(store)
|
42
42
|
return result['dump']
|
43
43
|
end
|
44
44
|
|
45
|
-
def self.create(accessor,
|
46
|
-
storefile = create_mmap(accessor,
|
45
|
+
def self.create(accessor, query_object, result)
|
46
|
+
storefile = create_mmap(accessor, query_object, result)
|
47
47
|
end
|
48
|
-
def self.create_mmap(accessor,
|
49
|
-
storefile = storefile_of(accessor.table_name,
|
48
|
+
def self.create_mmap(accessor, query_object, result)
|
49
|
+
storefile = storefile_of(accessor.table_name, query_object[:query])
|
50
50
|
store = create_store(storefile)
|
51
51
|
store.transaction do
|
52
52
|
store['dump'] = result
|
@@ -56,8 +56,8 @@ module Cache
|
|
56
56
|
return storefile
|
57
57
|
end
|
58
58
|
|
59
|
-
def self.include?(accessor,
|
60
|
-
FileTest.exist?(storefile_of(accessor.table_name,
|
59
|
+
def self.include?(accessor, query_obj)
|
60
|
+
FileTest.exist?(storefile_of(accessor.table_name, query_obj[:query]))
|
61
61
|
end
|
62
62
|
|
63
63
|
def self.delete(index)
|
data/lib/lore/clause.rb
CHANGED
@@ -35,23 +35,24 @@ module Lore
|
|
35
35
|
class Join # :nodoc:
|
36
36
|
# {{{
|
37
37
|
|
38
|
-
def initialize(clause, join_klass, type=:natural)
|
38
|
+
def initialize(clause, base_klass, join_klass, type=:natural)
|
39
39
|
@type = type
|
40
40
|
@clause_parser = clause
|
41
|
+
@base_klass = base_klass
|
41
42
|
@join_klass = join_klass
|
42
43
|
@string = ''
|
43
44
|
# By joining with another klass, new attributes are added
|
44
45
|
# we have to include in the AS part of the query:
|
45
46
|
new_attributes = ''
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
47
|
+
# join_klass.get_attributes.each { |attr_set|
|
48
|
+
# table = attr_set[0]
|
49
|
+
# attr_set[1].each { |attrib_name|
|
50
|
+
# new_attributes += ', ' << "\n"
|
51
|
+
# new_attributes += table + '.' << attrib_name
|
52
|
+
# new_attributes += ' AS '
|
53
|
+
# new_attributes += '"' << table << '.' << attrib_name << '" '
|
54
|
+
# }
|
55
|
+
# }
|
55
56
|
implicit_joins = ''
|
56
57
|
@clause_parser.add_as(new_attributes)
|
57
58
|
|
@@ -72,12 +73,16 @@ module Lore
|
|
72
73
|
@string
|
73
74
|
end
|
74
75
|
|
76
|
+
# Will transform into ON clause, as USING drops duplicate fields
|
75
77
|
def using(key, &block)
|
76
78
|
if @type == :natural then cmd = 'JOIN '
|
77
79
|
elsif @type == :left then cmd = 'LEFT JOIN '
|
78
80
|
elsif @type == :right then cmd = 'RIGHT JOIN '
|
79
81
|
end
|
80
|
-
|
82
|
+
key = key.to_s
|
83
|
+
using_string = "#{@base_klass.table_name}.#{key} = "
|
84
|
+
using_string << "#{@join_klass.table_name}.#{key}"
|
85
|
+
@string = "\n" << cmd << @join_klass.table_name << ' ON (' << using_string << ') '
|
81
86
|
@clause_parser.append_join(self)
|
82
87
|
yield @clause_parser # use extended clause parser for inner block argument
|
83
88
|
end
|
@@ -99,14 +104,14 @@ module Lore
|
|
99
104
|
|
100
105
|
attr_reader :field_name, :value_string, :left_side, :plan
|
101
106
|
|
102
|
-
def initialize(field_name, left_side='', value_string='', plan={})
|
107
|
+
def initialize(field_name='', left_side='', value_string='', plan={})
|
103
108
|
@value_string = value_string
|
104
109
|
@left_side = left_side
|
105
110
|
@field_name = field_name
|
106
111
|
end
|
107
112
|
|
108
113
|
def self.for(accessor)
|
109
|
-
Clause_Parser.new(accessor
|
114
|
+
Clause_Parser.new(accessor)
|
110
115
|
end
|
111
116
|
|
112
117
|
def not_in(nested_query_string)
|
@@ -296,10 +301,6 @@ module Lore
|
|
296
301
|
def to_sql
|
297
302
|
@left_side + @value_string
|
298
303
|
end
|
299
|
-
|
300
|
-
def plan_name
|
301
|
-
|
302
|
-
end
|
303
304
|
|
304
305
|
end # class }}}
|
305
306
|
|
@@ -308,7 +309,7 @@ module Lore
|
|
308
309
|
class Clause_Parser # :nodoc
|
309
310
|
# {{{
|
310
311
|
|
311
|
-
def initialize(
|
312
|
+
def initialize(base_accessor)
|
312
313
|
|
313
314
|
@clause = Hash.new
|
314
315
|
@clause[:limit] = ''
|
@@ -320,12 +321,13 @@ module Lore
|
|
320
321
|
@clause[:set] = ''
|
321
322
|
@clause[:filter] = ''
|
322
323
|
@clause[:where] = 't'
|
323
|
-
@
|
324
|
+
@clause[:joined] = []
|
325
|
+
@base_accessor = base_accessor
|
324
326
|
|
325
327
|
end # def
|
326
328
|
|
327
329
|
def self.for(accessor)
|
328
|
-
Clause_Parser.new(accessor
|
330
|
+
Clause_Parser.new(accessor)
|
329
331
|
end
|
330
332
|
|
331
333
|
def parts
|
@@ -433,19 +435,20 @@ module Lore
|
|
433
435
|
def join(join_klass)
|
434
436
|
# this Join instance also will update this Clause_Parser's
|
435
437
|
# as_part (so passing self is crucial):
|
436
|
-
|
438
|
+
@clause[:joined] << join_klass
|
439
|
+
j = Join.new(self, @base_accessor, join_klass)
|
437
440
|
return j
|
438
441
|
end
|
439
442
|
def left_join(join_klass)
|
440
443
|
# this Join instance also will update this Clause_Parser's
|
441
444
|
# as_part (so passing self is crucial):
|
442
|
-
j = Join.new(self, join_klass, :left)
|
445
|
+
j = Join.new(self, @base_accessor, join_klass, :left)
|
443
446
|
return j
|
444
447
|
end
|
445
448
|
def right_join(join_klass)
|
446
449
|
# this Join instance also will update this Clause_Parser's
|
447
450
|
# as_part (so passing self is crucial):
|
448
|
-
j = Join.new(self, join_klass, :right)
|
451
|
+
j = Join.new(self, @base_accessor, join_klass, :right)
|
449
452
|
return j
|
450
453
|
end
|
451
454
|
|
@@ -511,11 +514,12 @@ module Lore
|
|
511
514
|
field_name = absolute_field_name.to_s
|
512
515
|
end
|
513
516
|
|
514
|
-
|
517
|
+
# return Clause.new("#{@base_table}.#{field_name}")
|
518
|
+
return Clause.new(field_name)
|
515
519
|
end
|
516
520
|
|
517
521
|
def id()
|
518
|
-
return Clause.new("#{@
|
522
|
+
return Clause.new("#{@base_accessor.table_name}.id")
|
519
523
|
end
|
520
524
|
|
521
525
|
def perform
|
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
require('lore
|
2
|
+
require('lore')
|
3
3
|
require('logger')
|
4
4
|
require('erb')
|
5
5
|
|
@@ -38,11 +38,11 @@ module GUI
|
|
38
38
|
@logger = Lore.logger
|
39
39
|
|
40
40
|
@template = ''
|
41
|
-
IO.foreach(Lore.path + 'gui/erb_template_helpers.rhtml') { |line|
|
41
|
+
IO.foreach(Lore.path + 'lore/gui/erb_template_helpers.rhtml') { |line|
|
42
42
|
@template << line
|
43
43
|
}
|
44
44
|
template_path = template_path.to_s << '.rhtml' if template_path.instance_of? Symbol
|
45
|
-
IO.foreach(Lore.path + 'gui/templates/' << template_path) { |line|
|
45
|
+
IO.foreach(Lore.path + 'lore/gui/templates/' << template_path) { |line|
|
46
46
|
@template << line
|
47
47
|
}
|
48
48
|
|
@@ -658,8 +658,8 @@ module GUI
|
|
658
658
|
class Hidden < Form_Element
|
659
659
|
# {{{
|
660
660
|
|
661
|
-
def initialize(_table, _attrib_name)
|
662
|
-
setup(_table, _attrib_name, '', nil,
|
661
|
+
def initialize(_table, _attrib_name, value=nil)
|
662
|
+
setup(_table, _attrib_name, '', nil, value)
|
663
663
|
end
|
664
664
|
|
665
665
|
def string()
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/lore/result.rb
CHANGED
@@ -72,6 +72,25 @@ class Result
|
|
72
72
|
@result_rows[row_num] = row_result
|
73
73
|
return row_result
|
74
74
|
|
75
|
+
end
|
76
|
+
def get_row_with_field_names(row_num=0)
|
77
|
+
|
78
|
+
return @result_rows.at(row_num) if @result_rows.at(row_num)
|
79
|
+
return if @result.num_tuples == 0
|
80
|
+
|
81
|
+
row_result = Array.new
|
82
|
+
|
83
|
+
@field_counter = 0
|
84
|
+
for @field_counter in 0...@num_fields do
|
85
|
+
row_result << @result.getvalue(row_num, @field_counter)
|
86
|
+
end
|
87
|
+
@result_rows[row_num] = row_result
|
88
|
+
@fieldnames = []
|
89
|
+
for @field_counter in 0...@num_fields do
|
90
|
+
@fieldnames << @result.fieldname(@field_counter)
|
91
|
+
end
|
92
|
+
return { :values => row_result, :fields => @fieldnames }
|
93
|
+
|
75
94
|
end
|
76
95
|
|
77
96
|
def get_rows()
|