lore 0.4.2

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.
Files changed (90) hide show
  1. data/LICENSE +19 -0
  2. data/README +74 -0
  3. data/aspect.rb +80 -0
  4. data/behaviours/lockable.rb +41 -0
  5. data/behaviours/movable.rb +54 -0
  6. data/behaviours/versioned.rb +24 -0
  7. data/benchmark.rb +193 -0
  8. data/bits.rb +52 -0
  9. data/cache/abstract_entity_cache.rb +82 -0
  10. data/cache/bits.rb +22 -0
  11. data/cache/cacheable.rb +202 -0
  12. data/cache/cached_entities.rb +116 -0
  13. data/cache/file_index.rb +35 -0
  14. data/cache/mmap_entity_cache.rb +67 -0
  15. data/clause.rb +528 -0
  16. data/connection.rb +155 -0
  17. data/custom_functions.sql +14 -0
  18. data/exception/ambiguous_attribute.rb +14 -0
  19. data/exception/cache_exception.rb +30 -0
  20. data/exception/invalid_klass_parameters.rb +63 -0
  21. data/exception/invalid_parameter.rb +42 -0
  22. data/exception/unknown_typecode.rb +19 -0
  23. data/file_index.sql +56 -0
  24. data/gui/erb_template.rb +79 -0
  25. data/gui/erb_template_helpers.rhtml +19 -0
  26. data/gui/form.rb +314 -0
  27. data/gui/form_element.rb +676 -0
  28. data/gui/form_generator.rb +151 -0
  29. data/gui/templates/button.rhtml +2 -0
  30. data/gui/templates/checkbox.rhtml +3 -0
  31. data/gui/templates/checkbox_row.rhtml +1 -0
  32. data/gui/templates/file.rhtml +2 -0
  33. data/gui/templates/file_readonly.rhtml +3 -0
  34. data/gui/templates/form_element.rhtml +5 -0
  35. data/gui/templates/form_element_horizontal.rhtml +3 -0
  36. data/gui/templates/form_element_listed.rhtml +8 -0
  37. data/gui/templates/form_table.rhtml +3 -0
  38. data/gui/templates/form_table_blank.rhtml +3 -0
  39. data/gui/templates/form_table_horizontal.rhtml +8 -0
  40. data/gui/templates/password.rhtml +2 -0
  41. data/gui/templates/password_readonly.rhtml +3 -0
  42. data/gui/templates/radio.rhtml +1 -0
  43. data/gui/templates/radio_row.rhtml +1 -0
  44. data/gui/templates/select.rhtml +23 -0
  45. data/gui/templates/text.rhtml +2 -0
  46. data/gui/templates/text_readonly.rhtml +3 -0
  47. data/gui/templates/textarea.rhtml +3 -0
  48. data/gui/templates/textarea_readonly.rhtml +4 -0
  49. data/lore.gemspec +40 -0
  50. data/lore.rb +94 -0
  51. data/migration.rb +48 -0
  52. data/model.rb +139 -0
  53. data/model_factory.rb +202 -0
  54. data/model_shortcuts.rb +16 -0
  55. data/query_shortcuts.rb +367 -0
  56. data/reserved_methods.txt +3 -0
  57. data/result.rb +100 -0
  58. data/symbol.rb +58 -0
  59. data/table_accessor.rb +1926 -0
  60. data/table_deleter.rb +115 -0
  61. data/table_inserter.rb +168 -0
  62. data/table_instance.rb +384 -0
  63. data/table_selector.rb +314 -0
  64. data/table_updater.rb +155 -0
  65. data/test/README +31 -0
  66. data/test/env.rb +5 -0
  67. data/test/lore_test.log +8218 -0
  68. data/test/model.rb +142 -0
  69. data/test/prepare.rb +37 -0
  70. data/test/tc_aspect.rb +58 -0
  71. data/test/tc_cache.rb +80 -0
  72. data/test/tc_clause.rb +104 -0
  73. data/test/tc_deep_inheritance.rb +49 -0
  74. data/test/tc_factory.rb +57 -0
  75. data/test/tc_filter.rb +37 -0
  76. data/test/tc_form.rb +32 -0
  77. data/test/tc_model.rb +86 -0
  78. data/test/tc_prepare.rb +45 -0
  79. data/test/tc_refined_query.rb +88 -0
  80. data/test/tc_table_accessor.rb +265 -0
  81. data/test/test.log +181 -0
  82. data/test/test_db.sql +400 -0
  83. data/test/ts_lore.rb +49 -0
  84. data/types.rb +55 -0
  85. data/validation/message.rb +60 -0
  86. data/validation/parameter_validator.rb +104 -0
  87. data/validation/reason.rb +54 -0
  88. data/validation/type_validator.rb +91 -0
  89. data/validation.rb +65 -0
  90. metadata +170 -0
data/test/test_db.sql ADDED
@@ -0,0 +1,400 @@
1
+ --
2
+ -- PostgreSQL database dump
3
+ --
4
+
5
+ SET client_encoding = 'SQL_ASCII';
6
+ SET standard_conforming_strings = off;
7
+ SET check_function_bodies = false;
8
+ SET client_min_messages = warning;
9
+ SET escape_string_warning = off;
10
+
11
+ --
12
+ -- Name: SCHEMA public; Type: COMMENT; Schema: -; Owner: postgres
13
+ --
14
+
15
+ COMMENT ON SCHEMA public IS 'Standard public schema';
16
+
17
+
18
+ SET search_path = public, pg_catalog;
19
+
20
+ SET default_tablespace = '';
21
+
22
+ SET default_with_oids = false;
23
+
24
+ --
25
+ -- Name: bike; Type: TABLE; Schema: public; Owner: lore; Tablespace:
26
+ --
27
+
28
+ CREATE TABLE bike (
29
+ bike_id integer NOT NULL,
30
+ vehicle_id integer NOT NULL,
31
+ is_chopper boolean NOT NULL
32
+ );
33
+
34
+
35
+ ALTER TABLE public.bike OWNER TO lore;
36
+
37
+ --
38
+ -- Name: bike_id_seq; Type: SEQUENCE; Schema: public; Owner: lore
39
+ --
40
+
41
+ CREATE SEQUENCE bike_id_seq
42
+ START WITH 1
43
+ INCREMENT BY 1
44
+ NO MAXVALUE
45
+ NO MINVALUE
46
+ CACHE 1;
47
+
48
+
49
+ ALTER TABLE public.bike_id_seq OWNER TO lore;
50
+
51
+ --
52
+ -- Name: car; Type: TABLE; Schema: public; Owner: lore; Tablespace:
53
+ --
54
+
55
+ CREATE TABLE car (
56
+ id integer NOT NULL,
57
+ vehicle_id integer NOT NULL,
58
+ car_type_id integer NOT NULL,
59
+ num_doors smallint NOT NULL
60
+ );
61
+
62
+
63
+ ALTER TABLE public.car OWNER TO lore;
64
+
65
+ --
66
+ -- Name: car_id_seq; Type: SEQUENCE; Schema: public; Owner: lore
67
+ --
68
+
69
+ CREATE SEQUENCE car_id_seq
70
+ INCREMENT BY 1
71
+ NO MAXVALUE
72
+ NO MINVALUE
73
+ CACHE 1;
74
+
75
+
76
+ ALTER TABLE public.car_id_seq OWNER TO lore;
77
+
78
+ --
79
+ -- Name: car_type; Type: TABLE; Schema: public; Owner: lore; Tablespace:
80
+ --
81
+
82
+ CREATE TABLE car_type (
83
+ car_type_id integer NOT NULL,
84
+ name character varying(100) NOT NULL
85
+ );
86
+
87
+
88
+ ALTER TABLE public.car_type OWNER TO lore;
89
+
90
+ --
91
+ -- Name: car_type_id_seq; Type: SEQUENCE; Schema: public; Owner: lore
92
+ --
93
+
94
+ CREATE SEQUENCE car_type_id_seq
95
+ INCREMENT BY 1
96
+ NO MAXVALUE
97
+ NO MINVALUE
98
+ CACHE 1;
99
+
100
+
101
+ ALTER TABLE public.car_type_id_seq OWNER TO lore;
102
+
103
+ --
104
+ -- Name: garage; Type: TABLE; Schema: public; Owner: lore; Tablespace:
105
+ --
106
+
107
+ CREATE TABLE garage (
108
+ garage_id integer NOT NULL,
109
+ vehicle_id integer NOT NULL
110
+ );
111
+
112
+
113
+ ALTER TABLE public.garage OWNER TO lore;
114
+
115
+ --
116
+ -- Name: garage_id_seq; Type: SEQUENCE; Schema: public; Owner: lore
117
+ --
118
+
119
+ CREATE SEQUENCE garage_id_seq
120
+ START WITH 1
121
+ INCREMENT BY 1
122
+ NO MAXVALUE
123
+ NO MINVALUE
124
+ CACHE 1;
125
+
126
+
127
+ ALTER TABLE public.garage_id_seq OWNER TO lore;
128
+
129
+ --
130
+ -- Name: manuf_id_seq; Type: SEQUENCE; Schema: public; Owner: lore
131
+ --
132
+
133
+ CREATE SEQUENCE manuf_id_seq
134
+ INCREMENT BY 1
135
+ NO MAXVALUE
136
+ NO MINVALUE
137
+ CACHE 1;
138
+
139
+
140
+ ALTER TABLE public.manuf_id_seq OWNER TO lore;
141
+
142
+ --
143
+ -- Name: manufacturer; Type: TABLE; Schema: public; Owner: lore; Tablespace:
144
+ --
145
+
146
+ CREATE TABLE manufacturer (
147
+ manuf_id integer NOT NULL,
148
+ name character varying(100) NOT NULL
149
+ );
150
+
151
+
152
+ ALTER TABLE public.manufacturer OWNER TO lore;
153
+
154
+ --
155
+ -- Name: owner; Type: TABLE; Schema: public; Owner: lore; Tablespace:
156
+ --
157
+
158
+ CREATE TABLE "owner" (
159
+ owner_id integer NOT NULL,
160
+ name character varying(200) NOT NULL
161
+ );
162
+
163
+
164
+ ALTER TABLE public."owner" OWNER TO lore;
165
+
166
+ --
167
+ -- Name: owner_id_seq; Type: SEQUENCE; Schema: public; Owner: lore
168
+ --
169
+
170
+ CREATE SEQUENCE owner_id_seq
171
+ INCREMENT BY 1
172
+ NO MAXVALUE
173
+ NO MINVALUE
174
+ CACHE 1;
175
+
176
+
177
+ ALTER TABLE public.owner_id_seq OWNER TO lore;
178
+
179
+ --
180
+ -- Name: trailer; Type: TABLE; Schema: public; Owner: lore; Tablespace:
181
+ --
182
+
183
+ CREATE TABLE trailer (
184
+ trailer_id integer NOT NULL,
185
+ car_id integer NOT NULL,
186
+ maxweight integer NOT NULL
187
+ );
188
+
189
+
190
+ ALTER TABLE public.trailer OWNER TO lore;
191
+
192
+ --
193
+ -- Name: trailer_id_seq; Type: SEQUENCE; Schema: public; Owner: lore
194
+ --
195
+
196
+ CREATE SEQUENCE trailer_id_seq
197
+ START WITH 1
198
+ INCREMENT BY 1
199
+ NO MAXVALUE
200
+ NO MINVALUE
201
+ CACHE 1;
202
+
203
+
204
+ ALTER TABLE public.trailer_id_seq OWNER TO lore;
205
+
206
+ --
207
+ -- Name: vehicle; Type: TABLE; Schema: public; Owner: lore; Tablespace:
208
+ --
209
+
210
+ CREATE TABLE vehicle (
211
+ id integer NOT NULL,
212
+ manuf_id integer NOT NULL,
213
+ num_seats smallint NOT NULL,
214
+ maxspeed integer NOT NULL,
215
+ name character varying(100) NOT NULL,
216
+ owner_id integer
217
+ );
218
+
219
+
220
+ ALTER TABLE public.vehicle OWNER TO lore;
221
+
222
+ --
223
+ -- Name: vehicle_id_seq; Type: SEQUENCE; Schema: public; Owner: lore
224
+ --
225
+
226
+ CREATE SEQUENCE vehicle_id_seq
227
+ INCREMENT BY 1
228
+ NO MAXVALUE
229
+ NO MINVALUE
230
+ CACHE 1;
231
+
232
+
233
+ ALTER TABLE public.vehicle_id_seq OWNER TO lore;
234
+
235
+ --
236
+ -- Name: vehicle_owner; Type: TABLE; Schema: public; Owner: lore; Tablespace:
237
+ --
238
+
239
+ CREATE TABLE vehicle_owner (
240
+ owner_id integer NOT NULL,
241
+ vehicle_id integer NOT NULL
242
+ );
243
+
244
+
245
+ ALTER TABLE public.vehicle_owner OWNER TO lore;
246
+
247
+ --
248
+ -- Name: public; Type: ACL; Schema: -; Owner: postgres
249
+ --
250
+
251
+ REVOKE ALL ON SCHEMA public FROM PUBLIC;
252
+ REVOKE ALL ON SCHEMA public FROM postgres;
253
+ GRANT ALL ON SCHEMA public TO postgres;
254
+ GRANT ALL ON SCHEMA public TO PUBLIC;
255
+
256
+
257
+ --
258
+ -- Name: bike; Type: ACL; Schema: public; Owner: lore
259
+ --
260
+
261
+ REVOKE ALL ON TABLE bike FROM PUBLIC;
262
+ REVOKE ALL ON TABLE bike FROM lore;
263
+ GRANT ALL ON TABLE bike TO lore;
264
+ GRANT ALL ON TABLE bike TO "lore";
265
+
266
+
267
+ --
268
+ -- Name: bike_id_seq; Type: ACL; Schema: public; Owner: lore
269
+ --
270
+
271
+ REVOKE ALL ON SEQUENCE bike_id_seq FROM PUBLIC;
272
+ REVOKE ALL ON SEQUENCE bike_id_seq FROM lore;
273
+ GRANT ALL ON SEQUENCE bike_id_seq TO lore;
274
+ GRANT ALL ON SEQUENCE bike_id_seq TO "lore";
275
+
276
+
277
+ --
278
+ -- Name: car; Type: ACL; Schema: public; Owner: lore
279
+ --
280
+
281
+ REVOKE ALL ON TABLE car FROM PUBLIC;
282
+ REVOKE ALL ON TABLE car FROM lore;
283
+ GRANT ALL ON TABLE car TO lore;
284
+ GRANT ALL ON TABLE car TO "lore";
285
+
286
+
287
+ --
288
+ -- Name: car_id_seq; Type: ACL; Schema: public; Owner: lore
289
+ --
290
+
291
+ REVOKE ALL ON SEQUENCE car_id_seq FROM PUBLIC;
292
+ REVOKE ALL ON SEQUENCE car_id_seq FROM lore;
293
+ GRANT ALL ON SEQUENCE car_id_seq TO lore;
294
+ GRANT ALL ON SEQUENCE car_id_seq TO "lore";
295
+
296
+
297
+ --
298
+ -- Name: car_type; Type: ACL; Schema: public; Owner: lore
299
+ --
300
+
301
+ REVOKE ALL ON TABLE car_type FROM PUBLIC;
302
+ REVOKE ALL ON TABLE car_type FROM lore;
303
+ GRANT ALL ON TABLE car_type TO lore;
304
+ GRANT ALL ON TABLE car_type TO "lore";
305
+
306
+
307
+ --
308
+ -- Name: car_type_id_seq; Type: ACL; Schema: public; Owner: lore
309
+ --
310
+
311
+ REVOKE ALL ON SEQUENCE car_type_id_seq FROM PUBLIC;
312
+ REVOKE ALL ON SEQUENCE car_type_id_seq FROM lore;
313
+ GRANT ALL ON SEQUENCE car_type_id_seq TO lore;
314
+ GRANT ALL ON SEQUENCE car_type_id_seq TO "lore";
315
+
316
+
317
+ --
318
+ -- Name: garage; Type: ACL; Schema: public; Owner: lore
319
+ --
320
+
321
+ REVOKE ALL ON TABLE garage FROM PUBLIC;
322
+ REVOKE ALL ON TABLE garage FROM lore;
323
+ GRANT ALL ON TABLE garage TO lore;
324
+ GRANT ALL ON TABLE garage TO "lore";
325
+
326
+
327
+ --
328
+ -- Name: garage_id_seq; Type: ACL; Schema: public; Owner: lore
329
+ --
330
+
331
+ REVOKE ALL ON SEQUENCE garage_id_seq FROM PUBLIC;
332
+ REVOKE ALL ON SEQUENCE garage_id_seq FROM lore;
333
+ GRANT ALL ON SEQUENCE garage_id_seq TO lore;
334
+ GRANT ALL ON SEQUENCE garage_id_seq TO "lore";
335
+
336
+
337
+ --
338
+ -- Name: manuf_id_seq; Type: ACL; Schema: public; Owner: lore
339
+ --
340
+
341
+ REVOKE ALL ON SEQUENCE manuf_id_seq FROM PUBLIC;
342
+ REVOKE ALL ON SEQUENCE manuf_id_seq FROM lore;
343
+ GRANT ALL ON SEQUENCE manuf_id_seq TO lore;
344
+ GRANT ALL ON SEQUENCE manuf_id_seq TO "lore";
345
+
346
+
347
+ --
348
+ -- Name: manufacturer; Type: ACL; Schema: public; Owner: lore
349
+ --
350
+
351
+ REVOKE ALL ON TABLE manufacturer FROM PUBLIC;
352
+ REVOKE ALL ON TABLE manufacturer FROM lore;
353
+ GRANT ALL ON TABLE manufacturer TO lore;
354
+ GRANT ALL ON TABLE manufacturer TO "lore";
355
+
356
+
357
+ --
358
+ -- Name: trailer; Type: ACL; Schema: public; Owner: lore
359
+ --
360
+
361
+ REVOKE ALL ON TABLE trailer FROM PUBLIC;
362
+ REVOKE ALL ON TABLE trailer FROM lore;
363
+ GRANT ALL ON TABLE trailer TO lore;
364
+ GRANT ALL ON TABLE trailer TO lore;
365
+
366
+
367
+ --
368
+ -- Name: trailer_id_seq; Type: ACL; Schema: public; Owner: lore
369
+ --
370
+
371
+ REVOKE ALL ON SEQUENCE trailer_id_seq FROM PUBLIC;
372
+ REVOKE ALL ON SEQUENCE trailer_id_seq FROM lore;
373
+ GRANT ALL ON SEQUENCE trailer_id_seq TO lore;
374
+ GRANT ALL ON SEQUENCE trailer_id_seq TO lore;
375
+
376
+
377
+ --
378
+ -- Name: vehicle; Type: ACL; Schema: public; Owner: lore
379
+ --
380
+
381
+ REVOKE ALL ON TABLE vehicle FROM PUBLIC;
382
+ REVOKE ALL ON TABLE vehicle FROM lore;
383
+ GRANT ALL ON TABLE vehicle TO lore;
384
+ GRANT ALL ON TABLE vehicle TO "lore";
385
+
386
+
387
+ --
388
+ -- Name: vehicle_id_seq; Type: ACL; Schema: public; Owner: lore
389
+ --
390
+
391
+ REVOKE ALL ON SEQUENCE vehicle_id_seq FROM PUBLIC;
392
+ REVOKE ALL ON SEQUENCE vehicle_id_seq FROM lore;
393
+ GRANT ALL ON SEQUENCE vehicle_id_seq TO lore;
394
+ GRANT ALL ON SEQUENCE vehicle_id_seq TO "lore";
395
+
396
+
397
+ --
398
+ -- PostgreSQL database dump complete
399
+ --
400
+
data/test/ts_lore.rb ADDED
@@ -0,0 +1,49 @@
1
+
2
+ require 'test/unit/testsuite'
3
+
4
+ require('lore')
5
+ Lore.logfile = './lore_test.log'
6
+ require('rubygems')
7
+ require('lore/test/model')
8
+ require('lore/connection')
9
+ require('lore/cache/mmap_entity_cache')
10
+
11
+ require('lore/test/tc_table_accessor')
12
+ require('lore/test/tc_clause')
13
+ require('lore/test/tc_model')
14
+ require('lore/test/tc_form')
15
+ require('lore/test/tc_cache')
16
+ require('lore/test/tc_factory')
17
+ require('lore/test/tc_refined_query')
18
+ require('lore/test/tc_filter')
19
+ require('lore/test/tc_deep_inheritance')
20
+ require('lore/test/tc_prepare')
21
+
22
+ module Lore
23
+
24
+ class Table_Accessor
25
+ # @@cache_impl = Lore::Cache::MMap_Entity_Cache
26
+ end
27
+
28
+ module Unit
29
+
30
+ class TS_Lore
31
+
32
+ def self.suite
33
+ suite = Test::Unit::TestSuite.new()
34
+ suite << TC_Model.suite
35
+ suite << TC_Refined_Query.suite
36
+ suite << TC_Clause.suite
37
+ suite << TC_Table_Accessor.suite
38
+ suite << TC_Form.suite
39
+ suite << TC_Cache.suite
40
+ suite << TC_Factory.suite
41
+ suite << TC_Aspect.suite
42
+ suite << TC_Filter.suite
43
+ suite << TC_Prepare.suite
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+ end
data/types.rb ADDED
@@ -0,0 +1,55 @@
1
+
2
+ module Lore
3
+
4
+ PG_BOOL = 16
5
+ PG_BYTEA = 17
6
+ PG_SMALLINT = 21
7
+ PG_CHAR = 18
8
+ PG_INT = 23
9
+ PG_TEXT = 25
10
+ PG_CHARACTER = 1042
11
+ PG_VARCHAR = 1043
12
+ PG_TIME = 1083
13
+ PG_TIMESTAMP_TIMEZONE = 1184
14
+ PG_TIMESTAMP = 1114
15
+ PG_DATE = 1082
16
+ PG_VCHAR_LIST = 1015
17
+ PG_DECIMAL = 1700
18
+
19
+ TYPE_NAMES = {
20
+ PG_BYTEA => 'bytea',
21
+ PG_BOOL => 'boolean',
22
+ PG_SMALLINT => 'small int',
23
+ PG_CHAR => 'char',
24
+ PG_INT => 'integer',
25
+ PG_TEXT => 'text',
26
+ PG_CHARACTER => 'character',
27
+ PG_VARCHAR => 'character varying(1000)',
28
+ PG_TIME => 'time',
29
+ PG_TIMESTAMP_TIMEZONE => 'timestamp with timezone',
30
+ PG_TIMESTAMP => 'timestamp',
31
+ PG_DATE => 'data',
32
+ PG_VCHAR_LIST => 'character varying[]',
33
+ PG_DECIMAL => 'decimal'
34
+ }
35
+
36
+ class Type
37
+
38
+ def self.integer; 'integer'; end
39
+ def self.boolean; 'boolean'; end
40
+ def self.bytea; 'bytea'; end
41
+ def self.char; 'char'; end
42
+ def self.varchar(length=255); 'character varying(' << length.to_s + ')'; end
43
+ def self.time; 'time'; end
44
+ def self.timestamp; 'timestamp'; end
45
+ def self.date; 'date'; end
46
+ def self.text; 'text'; end
47
+ def self.decimal; 'decimal'; end
48
+
49
+ def self.type_name(int)
50
+ TYPE_NAMES[int]
51
+ end
52
+
53
+ end
54
+
55
+ end # module
@@ -0,0 +1,60 @@
1
+
2
+ module Lore
3
+ module Validation
4
+
5
+ class Message
6
+
7
+ def [](serial_string) # {{{
8
+
9
+ if $cb__message_strings[$lang].include?(serial_string) then
10
+ return nil
11
+ else
12
+ return $cb__message_strings[$lang][serial_string]
13
+ end
14
+
15
+ end # def }}}
16
+
17
+ end # class
18
+
19
+ class Error_Message < Message
20
+
21
+ @logger = Lore.logger
22
+
23
+ def [](serial_string) # {{{
24
+
25
+ if $cb__message_strings[$lang].include?(serial_string) then
26
+ compose_error_message(serial_string)
27
+ else
28
+ return $cb__error_strings[$lang][serial_string]
29
+ end
30
+
31
+ end # def }}}
32
+
33
+ def self.compose_error_message(serial_array) # {{{
34
+
35
+ message = []
36
+ serial_array.uniq!
37
+ serial_array.each { |serial_code|
38
+ # klass--name--given--typecode (from Invalid_Klass_Parameters)
39
+ # to [klass,name,given,typecode]
40
+ # @logger.log('serial code: '+serial_code.to_s)
41
+ invalid_parameter = serial_code.split('--')
42
+
43
+ # try to resolve a human readable name for this parameter:
44
+ if !Lang[invalid_parameter[1]].nil? then inv_param_name = Lang[invalid_parameter[1]]
45
+ else inv_param_name = invalid_parameter[1] end
46
+
47
+ if invalid_parameter[2] == '' then
48
+ message << Lang[:error__specify_value].gsub('{1}', inv_param_name)
49
+ else
50
+ message << Lang[:error__invalid_value].gsub('{1}', inv_param_name)
51
+ end
52
+ }
53
+ return message
54
+
55
+ end # def }}}
56
+
57
+ end # class
58
+
59
+ end # module
60
+ end # module
@@ -0,0 +1,104 @@
1
+
2
+ require('lore/validation/type_validator')
3
+ require('lore/exception/invalid_parameter')
4
+
5
+ module Lore
6
+ module Validation
7
+
8
+ class Parameter_Validator # :nodoc:
9
+
10
+ PG_BOOL = 16
11
+ PG_SMALLINT = 21
12
+ PG_INT = 23
13
+ PG_TEXT = 25
14
+ PG_VARCHAR = 1043
15
+ PG_TIMESTAMP_TIMEZONE = 1184
16
+
17
+ @logger = Lore.logger
18
+
19
+ #############################################################
20
+ # To be used inside Table_Accessor with
21
+ # Validator.invalid_params(this, @attribute_values)
22
+ # or e.g. in a dispatcher with
23
+ # Validator.invalid_params(Some_Klass, parameter_hash)
24
+ #
25
+ def self.invalid_params(klass, value_hash)
26
+
27
+ invalid_params = Hash.new
28
+ explicit_attributes = klass.get_explicit_attributes
29
+ constraints = klass.get_constraints
30
+
31
+ klass.get_attribute_types.each_pair { |table, fields|
32
+ begin
33
+ validate_types(fields, value_hash[table], explicit_attributes[table])
34
+ rescue Exception::Invalid_Types => ip
35
+ invalid_params[table] = ip
36
+ end
37
+ }
38
+
39
+ klass.get_constraints.each_pair { |table, fields|
40
+ begin
41
+ validate_constraints(fields, value_hash[table])
42
+ rescue Exception::Unmet_Constraints => ip
43
+ invalid_params[table] = ip
44
+ end
45
+ }
46
+ if invalid_params.length == 0 then return true end
47
+
48
+ raise Lore::Exception::Invalid_Klass_Parameters.new(klass, invalid_params)
49
+
50
+ end
51
+
52
+ def self.validate_types(type_codes, table_value_hash, table_explicit_attributes)
53
+ invalid_types = {}
54
+ value = false
55
+ type_validator = Type_Validator.new()
56
+ type_codes.each_pair { |field, type|
57
+
58
+ nil_allowed = table_explicit_attributes.nil? ||
59
+ !table_explicit_attributes.include?(field)
60
+
61
+ value = table_value_hash[field]
62
+ # Replace whitespaces and array delimiters to check for real value length
63
+ value_nil = (value.nil? || value.to_s.gsub(/\s/,'').gsub(/[{}]/,'').length == 0)
64
+ # Is value missing?
65
+ if (!nil_allowed && value_nil) then
66
+ invalid_types[field] = :missing
67
+ # If so: Is value of valid type?
68
+ elsif !type_validator.typecheck(type, value, nil_allowed) then
69
+ invalid_types[field] = type
70
+ end
71
+
72
+ }
73
+ if invalid_types.keys.length > 0 then
74
+ raise Lore::Exception::Invalid_Types.new(invalid_types)
75
+ end
76
+ return true
77
+ end
78
+
79
+ def self.validate_constraints(table_constraints, table_value_hash)
80
+ unmet_constraints = {}
81
+ table_constraints.each_pair { |attrib, rules|
82
+ value = table_value_hash[attrib.to_s]
83
+ rules.each_pair { |rule, rule_value|
84
+ if rule == :minlength && value.to_s.length < rule_value then
85
+ unmet_constraints[attrib] = :minlength
86
+ end
87
+ if rule == :maxlength && value.to_s.length > rule_value then
88
+ unmet_constraints[attrib] = :maxlength
89
+ end
90
+ if rule == :format && rule_value.match(value).nil? then
91
+ unmet_constraints[attrib] = :format
92
+ end
93
+ }
94
+ }
95
+ if unmet_constraints.length > 0 then
96
+ raise Lore::Exception::Unmet_Constraints.new(unmet_constraints)
97
+ end
98
+ return true
99
+ end
100
+
101
+ end
102
+
103
+ end # module
104
+ end # module
@@ -0,0 +1,54 @@
1
+
2
+ require('lore/validation/message')
3
+ require('htmlentities')
4
+
5
+ module Lore
6
+ module Validation
7
+
8
+ class Reason # :nodoc:
9
+
10
+ @logger = Lore.logger
11
+
12
+ attr_reader :options
13
+
14
+ def message()
15
+ # polish message for html output:
16
+ return @message.map { |m| HTMLEntities.new.decode(m) }
17
+ end
18
+
19
+ def initialize(message, options) # {{{
20
+ @message = message
21
+ @options = options
22
+ end # def }}}
23
+
24
+ # Parameter validation failed:
25
+ def self.of_invalid_parameters(ikp) # {{{
26
+
27
+ message = Lore::Validation::Error_Message.compose_error_message(ikp.serialize())
28
+ @logger.debug('Reason message: '+message.inspect)
29
+ return self.new(message, @options)
30
+
31
+ end # def }}}
32
+
33
+ # System exception:
34
+ def self.of_user_runtime_error(excep) # {{{
35
+
36
+ options = [:choice_critical, :choice_recommended]
37
+ message = Lang[excep.message]
38
+ return self.new(message, options)
39
+
40
+ end # def }}}
41
+
42
+ # System exception:
43
+ def self.of_exception(excep) # {{{
44
+
45
+ options = [:choice_critical, :choice_recommended]
46
+ message = excep.message + ': ' + excep.backtrace.join('<br />')
47
+ return self.new(message, options)
48
+
49
+ end # def }}}
50
+
51
+ end # class
52
+
53
+ end # module
54
+ end # module