lore 0.4.8 → 0.9.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 (111) hide show
  1. data/Manifest.txt +16 -7
  2. data/README.rdoc +91 -0
  3. data/benchmark/benchmark.sql +11 -0
  4. data/benchmark/results.txt +28 -0
  5. data/benchmark/select.rb +352 -0
  6. data/lib/lore.rb +22 -8
  7. data/lib/lore/adapters/context.rb +64 -0
  8. data/lib/lore/adapters/postgres-pr.rb +6 -0
  9. data/lib/lore/adapters/postgres-pr/connection.rb +93 -0
  10. data/lib/lore/adapters/postgres-pr/result.rb +63 -0
  11. data/lib/lore/{types.rb → adapters/postgres-pr/types.rb} +36 -0
  12. data/lib/lore/adapters/postgres.rb +24 -0
  13. data/lib/lore/adapters/postgres/connection.rb +81 -0
  14. data/lib/lore/adapters/postgres/result.rb +82 -0
  15. data/lib/lore/adapters/postgres/types.rb +91 -0
  16. data/lib/lore/bits.rb +18 -0
  17. data/lib/lore/cache/abstract_entity_cache.rb +2 -1
  18. data/lib/lore/cache/cacheable.rb +12 -177
  19. data/lib/lore/cache/memcache_entity_cache.rb +89 -0
  20. data/lib/lore/cache/memory_entity_cache.rb +77 -0
  21. data/lib/lore/cache/mmap_entity_cache.rb +2 -2
  22. data/lib/lore/cache/mmap_entity_cache_bork.rb +86 -0
  23. data/lib/lore/clause.rb +107 -35
  24. data/lib/lore/{exception → exceptions}/ambiguous_attribute.rb +2 -2
  25. data/lib/lore/{exception → exceptions}/cache_exception.rb +1 -1
  26. data/lib/lore/exceptions/database_exception.rb +16 -0
  27. data/lib/lore/{exception/invalid_parameter.rb → exceptions/invalid_field.rb} +7 -4
  28. data/lib/lore/exceptions/unknown_type.rb +18 -0
  29. data/lib/lore/exceptions/validation_failure.rb +71 -0
  30. data/lib/lore/gui/form_generator.rb +109 -60
  31. data/lib/lore/gui/lore_model_select_field.rb +1 -0
  32. data/lib/lore/migration.rb +84 -25
  33. data/lib/lore/model.rb +3 -18
  34. data/lib/lore/{aspect.rb → model/aspect.rb} +0 -0
  35. data/lib/lore/model/associations.rb +225 -0
  36. data/lib/lore/model/attribute_settings.rb +233 -0
  37. data/lib/lore/model/filters.rb +34 -0
  38. data/lib/lore/model/mockable.rb +62 -0
  39. data/lib/lore/{model_factory.rb → model/model_factory.rb} +68 -39
  40. data/lib/lore/model/model_instance.rb +382 -0
  41. data/lib/lore/{model_shortcuts.rb → model/model_shortcuts.rb} +7 -0
  42. data/lib/lore/model/polymorphic.rb +53 -0
  43. data/lib/lore/model/prepare.rb +97 -0
  44. data/lib/lore/model/table_accessor.rb +1016 -0
  45. data/lib/lore/query.rb +71 -0
  46. data/lib/lore/query_shortcuts.rb +43 -11
  47. data/lib/lore/strategies/table_delete.rb +115 -0
  48. data/lib/lore/strategies/table_insert.rb +146 -0
  49. data/lib/lore/strategies/table_select.rb +299 -0
  50. data/lib/lore/strategies/table_update.rb +155 -0
  51. data/lib/lore/validation/parameter_validator.rb +85 -26
  52. data/lib/lore/validation/type_validator.rb +34 -78
  53. data/{custom_models.rb → lore-0.9.2.gem} +0 -0
  54. data/lore.gemspec +26 -17
  55. data/spec/clause.rb +37 -0
  56. data/spec/fixtures/blank_models.rb +37 -0
  57. data/{test/model.rb → spec/fixtures/models.rb} +64 -41
  58. data/spec/fixtures/polymorphic_models.rb +68 -0
  59. data/spec/model_associations.rb +86 -0
  60. data/spec/model_create.rb +47 -0
  61. data/spec/model_definition.rb +151 -0
  62. data/spec/model_delete.rb +31 -0
  63. data/spec/model_inheritance.rb +50 -0
  64. data/spec/model_polymorphic.rb +85 -0
  65. data/spec/model_select.rb +101 -0
  66. data/spec/model_select_eager.rb +42 -0
  67. data/spec/model_union_select.rb +33 -0
  68. data/spec/model_update.rb +45 -0
  69. data/spec/model_validation.rb +20 -0
  70. data/spec/spec_db.sql +808 -0
  71. data/spec/spec_env.rb +19 -0
  72. data/spec/spec_helpers.rb +77 -0
  73. metadata +93 -82
  74. data/lib/lore/README.txt +0 -84
  75. data/lib/lore/behaviours/lockable.rb +0 -55
  76. data/lib/lore/behaviours/movable.rb +0 -72
  77. data/lib/lore/behaviours/paginated.rb +0 -31
  78. data/lib/lore/behaviours/versioned.rb +0 -36
  79. data/lib/lore/connection.rb +0 -152
  80. data/lib/lore/exception/invalid_klass_parameters.rb +0 -63
  81. data/lib/lore/exception/unknown_typecode.rb +0 -19
  82. data/lib/lore/result.rb +0 -119
  83. data/lib/lore/symbol.rb +0 -58
  84. data/lib/lore/table_accessor.rb +0 -1790
  85. data/lib/lore/table_deleter.rb +0 -116
  86. data/lib/lore/table_inserter.rb +0 -170
  87. data/lib/lore/table_instance.rb +0 -389
  88. data/lib/lore/table_selector.rb +0 -285
  89. data/lib/lore/table_updater.rb +0 -157
  90. data/lib/lore/validation.rb +0 -65
  91. data/lib/lore/validation/message.rb +0 -60
  92. data/lib/lore/validation/reason.rb +0 -52
  93. data/lore_test.log +0 -2366
  94. data/test/README +0 -31
  95. data/test/custom_models.rb +0 -18
  96. data/test/env.rb +0 -5
  97. data/test/prepare.rb +0 -37
  98. data/test/tc_aspect.rb +0 -58
  99. data/test/tc_cache.rb +0 -83
  100. data/test/tc_clause.rb +0 -104
  101. data/test/tc_deep_inheritance.rb +0 -49
  102. data/test/tc_factory.rb +0 -57
  103. data/test/tc_filter.rb +0 -37
  104. data/test/tc_form.rb +0 -32
  105. data/test/tc_model.rb +0 -140
  106. data/test/tc_prepare.rb +0 -44
  107. data/test/tc_refined_query.rb +0 -88
  108. data/test/tc_table_accessor.rb +0 -267
  109. data/test/tc_thread.rb +0 -100
  110. data/test/test_db.sql +0 -400
  111. data/test/test_lore.rb +0 -50
@@ -0,0 +1,19 @@
1
+
2
+ require 'rubygems'
3
+ require 'lore'
4
+ require 'lore/model'
5
+
6
+
7
+ Lore.logfile = STDERR
8
+ Lore.enable_query_log
9
+ Lore.logger.level = Logger::DEBUG
10
+ Lore.query_logger.level = Logger::DEBUG
11
+ # Lore.add_login_data 'test' => [ 'paracelsus', nil ]
12
+ Lore.add_login_data 'test' => [ 'cuba', 'cuba23' ]
13
+ Lore::Context.enter :test
14
+
15
+ require './fixtures/models'
16
+ require './fixtures/blank_models'
17
+ require './fixtures/polymorphic_models'
18
+ require './spec_helpers'
19
+
@@ -0,0 +1,77 @@
1
+
2
+ class Array
3
+ def should_be(other)
4
+ other.length.should == self.length
5
+ self.each_with_index { |value, idx|
6
+ other[idx].should == value
7
+ }
8
+ end
9
+
10
+ def should_include(value)
11
+ self.include?(value).should == true
12
+ end
13
+ end
14
+
15
+ class Hash
16
+
17
+ def should_be(other)
18
+ num_keys = keys.length
19
+ num_keys.should == other.keys.length
20
+
21
+ self.each_pair { |key, value|
22
+ other.keys.should_include key
23
+ if value.is_a?(Hash) then
24
+ value.should_be(other[key])
25
+ elsif value.is_a?(Array) then
26
+ value.should_be(other[key])
27
+ else
28
+ other[key].should == value
29
+ end
30
+ }
31
+ end
32
+
33
+ end
34
+
35
+ def flush_test_data()
36
+ require './fixtures/models'
37
+ Lore.query_logger.debug { '-------- BEGIN FLUSH --------' }
38
+ Lore::Spec_Fixtures::Models::Vehicle.delete_all
39
+ Lore::Spec_Fixtures::Models::Motorized_Vehicle.delete_all
40
+ Lore::Spec_Fixtures::Models::Car.delete_all
41
+ Lore::Spec_Fixtures::Models::Motorbike.delete_all
42
+ Lore::Spec_Fixtures::Models::Garage.delete_all
43
+ Lore::Spec_Fixtures::Models::Owner.delete_all
44
+ Lore::Spec_Fixtures::Models::Vehicle_Owner.delete_all
45
+ Lore::Spec_Fixtures::Polymorphic_Models::Asset.delete_all
46
+ Lore::Spec_Fixtures::Polymorphic_Models::Media_Asset.delete_all
47
+ Lore::Spec_Fixtures::Polymorphic_Models::Document_Asset.delete_all
48
+ Lore::Spec_Fixtures::Polymorphic_Models::Media_Asset_Info.delete_all
49
+ Lore::Spec_Fixtures::Polymorphic_Models::Document_Asset_Info.delete_all
50
+ Lore.query_logger.debug { '-------- END FLUSH ----------' }
51
+ end
52
+
53
+ module Spec_Model_Select_Helpers
54
+ OWNER_ID = 12
55
+ MANUF_ID = 23
56
+ MOTOR_ID = 42
57
+
58
+ def mock_car_type
59
+ Car_Type.create(:type_name => 'Mock Type').pkey
60
+ end
61
+ def mock_motor
62
+ Motor.create(:motor_name => 'Mock Motor', :kw => 200).pkey
63
+ end
64
+
65
+ def car_create_values(replacements={})
66
+ {
67
+ :name => 'Some Car',
68
+ :maxspeed => 123,
69
+ :num_doors => 5,
70
+ :num_seats => 4,
71
+ :owner_id => OWNER_ID,
72
+ :manuf_id => MANUF_ID,
73
+ :motor_id => mock_motor(),
74
+ :car_type_id => mock_car_type()
75
+ }.update(replacements)
76
+ end
77
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Fuchs
@@ -9,29 +9,21 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-01-08 00:00:00 +01:00
12
+ date: 2009-08-24 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: postgres
17
- version_requirement:
18
- version_requirements: !ruby/object:Gem::Requirement
19
- requirements:
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: "0.1"
23
- version:
24
15
  - !ruby/object:Gem::Dependency
25
16
  name: aurita-gui
17
+ type: :runtime
26
18
  version_requirement:
27
19
  version_requirements: !ruby/object:Gem::Requirement
28
20
  requirements:
29
21
  - - ">="
30
22
  - !ruby/object:Gem::Version
31
- version: "0.1"
23
+ version: "0.2"
32
24
  version:
33
- description: Lore is an object-relational mapping (ORM) implementation providing many features like prepared statements, (multiple) inheritance, a comfortable query syntax, highly customizable automated form generation, and result caching using memory mapping (MMap). It aims at performance, usability and - unlike most ORMs - high coverage of native SQL functions and features. Lore is currently using PostgreSQL as database backend.
34
- email: fuchs@atomnode.net
25
+ description: Lore is an object-relational mapping (ORM) implementation providing many features like prepared statements, (multiple) inheritance, true polymorphism, a comfortable query syntax, highly customizable automated form generation, and result caching. It aims at performance, usability and - unlike most ORMs - high coverage of object oriented paradigms. Lore is currently using PostgreSQL as database backend.
26
+ email: twh.fuchs@gmail.com
35
27
  executables: []
36
28
 
37
29
  extensions: []
@@ -39,87 +31,106 @@ extensions: []
39
31
  extra_rdoc_files: []
40
32
 
41
33
  files:
34
+ - lore.gemspec
35
+ - lore-0.9.2.gem
36
+ - test
37
+ - doc
38
+ - benchmark
42
39
  - History.txt
43
- - custom_models.rb
44
- - lib
40
+ - README.rdoc
45
41
  - Manifest.txt
42
+ - spec
43
+ - lib
46
44
  - bin
47
- - test
48
45
  - Rakefile
49
- - lore_test.log
50
- - lore.gemspec
51
46
  - LICENSE
52
- - lib/lore
47
+ - benchmark/select.rb
48
+ - benchmark/benchmark.sql
49
+ - benchmark/results.txt
50
+ - spec/model_union_select.rb
51
+ - spec/model_associations.rb
52
+ - spec/fixtures
53
+ - spec/model_delete.rb
54
+ - spec/clause.rb
55
+ - spec/model_select_eager.rb
56
+ - spec/model_definition.rb
57
+ - spec/spec_helpers.rb
58
+ - spec/model_select.rb
59
+ - spec/model_create.rb
60
+ - spec/model_polymorphic.rb
61
+ - spec/spec_db.sql
62
+ - spec/model_inheritance.rb
63
+ - spec/model_validation.rb
64
+ - spec/model_update.rb
65
+ - spec/spec_env.rb
66
+ - spec/fixtures/models.rb
67
+ - spec/fixtures/blank_models.rb
68
+ - spec/fixtures/polymorphic_models.rb
53
69
  - lib/lore.rb
54
- - lib/lore/table_updater.rb
55
- - lib/lore/exception
56
- - lib/lore/table_deleter.rb
57
- - lib/lore/model_factory.rb
70
+ - lib/lore
71
+ - lib/lore/strategies
72
+ - lib/lore/migration.rb
73
+ - lib/lore/exceptions
74
+ - lib/lore/model
75
+ - lib/lore/validation
58
76
  - lib/lore/clause.rb
59
- - lib/lore/connection.rb
60
- - lib/lore/behaviours
61
- - lib/lore/symbol.rb
62
- - lib/lore/table_accessor.rb
63
- - lib/lore/table_inserter.rb
64
- - lib/lore/model.rb
65
- - lib/lore/table_instance.rb
66
- - lib/lore/types.rb
67
- - lib/lore/result.rb
68
- - lib/lore/validation.rb
69
- - lib/lore/table_selector.rb
70
- - lib/lore/aspect.rb
77
+ - lib/lore/gui
78
+ - lib/lore/query_shortcuts.rb
71
79
  - lib/lore/cache
72
- - lib/lore/validation
73
- - lib/lore/migration.rb
74
- - lib/lore/model_shortcuts.rb
75
- - lib/lore/README.txt
76
80
  - lib/lore/bits.rb
77
- - lib/lore/query_shortcuts.rb
78
- - lib/lore/gui
79
- - lib/lore/behaviours/paginated.rb
80
- - lib/lore/behaviours/movable.rb
81
- - lib/lore/behaviours/versioned.rb
82
- - lib/lore/behaviours/lockable.rb
81
+ - lib/lore/model.rb
82
+ - lib/lore/query.rb
83
+ - lib/lore/adapters
84
+ - lib/lore/adapters/context.rb
85
+ - lib/lore/adapters/postgres-pr.rb
86
+ - lib/lore/adapters/postgres
87
+ - lib/lore/adapters/postgres.rb
88
+ - lib/lore/adapters/postgres-pr
89
+ - lib/lore/adapters/postgres/connection.rb
90
+ - lib/lore/adapters/postgres/types.rb
91
+ - lib/lore/adapters/postgres/result.rb
92
+ - lib/lore/adapters/postgres-pr/connection.rb
93
+ - lib/lore/adapters/postgres-pr/types.rb
94
+ - lib/lore/adapters/postgres-pr/result.rb
95
+ - lib/lore/cache/mmap_entity_cache.rb
83
96
  - lib/lore/cache/file_index.rb
97
+ - lib/lore/cache/memory_entity_cache.rb
84
98
  - lib/lore/cache/abstract_entity_cache.rb
85
- - lib/lore/cache/mmap_entity_cache.rb
86
- - lib/lore/cache/cacheable.rb
87
- - lib/lore/cache/cached_entities.rb
88
99
  - lib/lore/cache/bits.rb
89
- - lib/lore/validation/message.rb
100
+ - lib/lore/cache/mmap_entity_cache_bork.rb
101
+ - lib/lore/cache/cached_entities.rb
102
+ - lib/lore/cache/memcache_entity_cache.rb
103
+ - lib/lore/cache/cacheable.rb
104
+ - lib/lore/exceptions/unknown_type.rb
105
+ - lib/lore/exceptions/invalid_field.rb
106
+ - lib/lore/exceptions/validation_failure.rb
107
+ - lib/lore/exceptions/cache_exception.rb
108
+ - lib/lore/exceptions/database_exception.rb
109
+ - lib/lore/exceptions/ambiguous_attribute.rb
110
+ - lib/lore/gui/form_generator.rb
111
+ - lib/lore/gui/lore_model_select_field.rb
112
+ - lib/lore/model/mockable.rb
113
+ - lib/lore/model/filters.rb
114
+ - lib/lore/model/attribute_settings.rb
115
+ - lib/lore/model/model_instance.rb
116
+ - lib/lore/model/model_shortcuts.rb
117
+ - lib/lore/model/polymorphic.rb
118
+ - lib/lore/model/model_factory.rb
119
+ - lib/lore/model/aspect.rb
120
+ - lib/lore/model/prepare.rb
121
+ - lib/lore/model/table_accessor.rb
122
+ - lib/lore/model/behaviours
123
+ - lib/lore/model/associations.rb
124
+ - lib/lore/strategies/table_select.rb
125
+ - lib/lore/strategies/table_delete.rb
126
+ - lib/lore/strategies/table_update.rb
127
+ - lib/lore/strategies/table_insert.rb
90
128
  - lib/lore/validation/parameter_validator.rb
91
- - lib/lore/validation/reason.rb
92
129
  - lib/lore/validation/type_validator.rb
93
- - lib/lore/gui/lore_model_select_field.rb
94
- - lib/lore/gui/form_generator.rb
95
- - lib/lore/exception/invalid_klass_parameters.rb
96
- - lib/lore/exception/invalid_parameter.rb
97
- - lib/lore/exception/ambiguous_attribute.rb
98
- - lib/lore/exception/cache_exception.rb
99
- - lib/lore/exception/unknown_typecode.rb
100
- - bin/custom_functions.sql
101
130
  - bin/setup_db.rb
102
- - test/tc_cache.rb
103
- - test/test_db.sql
104
- - test/custom_models.rb
105
- - test/tc_refined_query.rb
106
- - test/tc_deep_inheritance.rb
107
- - test/prepare.rb
108
- - test/tc_thread.rb
109
- - test/tc_model.rb
110
- - test/README
111
- - test/model.rb
112
- - test/test_lore.rb
113
- - test/tc_clause.rb
114
- - test/tc_table_accessor.rb
115
- - test/tc_aspect.rb
116
- - test/tc_filter.rb
117
- - test/env.rb
118
- - test/tc_factory.rb
119
- - test/tc_prepare.rb
120
- - test/tc_form.rb
131
+ - bin/custom_functions.sql
121
132
  has_rdoc: true
122
- homepage: http://lore.rubyforge.org
133
+ homepage: http://github.com/fuchsto/lore/
123
134
  post_install_message:
124
135
  rdoc_options:
125
136
  - --title
@@ -141,10 +152,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
152
  - !ruby/object:Gem::Version
142
153
  version: "0"
143
154
  version:
144
- requirements: []
145
-
155
+ requirements:
156
+ - "A ruby binding for PostgreSQL, such as postgres or postgres-pr. "
146
157
  rubyforge_project: lore
147
- rubygems_version: 1.1.1
158
+ rubygems_version: 1.3.1
148
159
  signing_key:
149
160
  specification_version: 2
150
161
  summary: A flexible ORM based on PostgreSQL
@@ -1,84 +0,0 @@
1
-
2
- Q: Are there adapters for other DBMS than PostgreSQL?
3
- A: PostgreSQL is - to me and everyone using Lore i know of -
4
- the best (free) choice for sophisticated database-driven
5
- apps, so frankly said: Implementing adapters is not on my
6
- top priority list.
7
- So far, Lore supports PostgreSQL (7.4 to 8.3 tested).
8
- Adapters are planned for oracle mysql and sqlite though.
9
- Lore is SQL 92 compatible and not using any exotic
10
- Postgres features, so it *might* work fine on e.g. mysql
11
- and sqlite with just minor modifications. Lore is caring
12
- about cascading dependencies etc itself, so you don't even
13
- need foreign keys or table inheritance.
14
- You will have to change the code establishing DB
15
- connections (see connection.rb), but as those are
16
- abstracted, just a couple of lines of code in connection.rb
17
- had to be changed.
18
-
19
- Q: How do i establish a DB connection at all?
20
- A: First provide login data for a database (aka Context):
21
-
22
- Lore.add_login_data('dbname' => ['user', 'pass'])
23
- Lore.add_login_data('other_dbname' => ['user', 'pass'])
24
-
25
- Now, activate a context. You can stack them, too:
26
-
27
- Lore::Context.enter :dbname
28
- # Operate in database dbname
29
- Lore::Context.enter :other_dbname
30
- # Operate in database other_dbname
31
- Lore::Context.leave
32
- # Operate in database dbname
33
- Lore::Context.enter :other_dbname
34
-
35
- Q: What about connection pooling?
36
- A: Lore re-uses connections per-process, that is: There is
37
- one connection for every context you entered in every
38
- process Lore is running in.
39
- In case you need connections shared over multiple
40
- processes, use PGPool for that, it's way better than any
41
- implementation of connection pooling in ruby.
42
- Install PGPool and tell lore to connect to PGPool's port
43
- instead of PostgreSQL's one.
44
- Example:
45
-
46
- Lore.server = 'localhost:9999'
47
-
48
- That's it!
49
-
50
- Q: Which solution do you recommend for query result caching?
51
- A: There are many possibilities: Tempfiles, Mmap and Memcached
52
- are the most widespread solutions known to me.
53
- Many will agree that MMap is the best solution in matters
54
- of performance on a single server, and memcached as soon as
55
- more than one server is involved in your application.
56
- To enable caching for all models:
57
-
58
- Lore::Model.use_entity_cache Lore::Cache::Mmap_Entity_Cache
59
- or
60
- Lore::Model.use_entity_cache Lore::Cache::Memcached_Entity_Cache
61
-
62
- Q: After creating a model via Model_Factory: How do i change
63
- it?
64
- A: At the moment, this is not implemented, but tracked as
65
- 'missing feature'. This will be possible in version 1.0 at
66
- the latest.
67
-
68
- Q: Where to look for documentation and examples?
69
- A: Have a look at the wiki. I'm updating it quite often, and
70
- new features are explained in the wiki first:
71
- http://infranode.com/wiki/
72
-
73
- Q: I found a bug!! What now?
74
- A: In case you're registered at rubyforge, visit
75
- http://lore.rubyforge.org and submit a bug report.
76
- Otherwise, just send me a mail (fuchs@atomnode.net).
77
- If you're using Lore and are your progress is blocked by a
78
- bug, i'll fix it almost instantly. I'm checking my mails
79
- more often than the tickets at rubyforge, though.
80
-
81
- Q: I want to join the dev team.
82
- A: Great! Just send a mail to fuchs@wortundform.de, i will add
83
- you on Rubyforge if you got some code to share.
84
-
@@ -1,55 +0,0 @@
1
-
2
- module Lore
3
- module Behaviours
4
-
5
- module Lockable
6
-
7
- # Defines which attribute to use for locking.
8
- # Usage:
9
- #
10
- # class My_Model < Lore::Model
11
- # extend Lockable
12
- # include Lockable_Entity
13
- #
14
- # # ...
15
- # lock_by(:lock_field)
16
- #
17
- # end
18
- #
19
- # my_model_entity.lock!
20
- # # same as
21
- # My_Model.lock!(my_model_entity)
22
- #
23
- def lock_by(attrib)
24
- @lock_attr = attrib
25
- @lock_attr_name = attrib.to_s.split('.')[-1].intern
26
- end
27
-
28
- def lock!(inst)
29
- inst.attr[@lock_attr] = true
30
- commit
31
- end # def
32
- def release!(inst)
33
- inst.attr[@lock_attr] = false
34
- commit
35
- end # def
36
- def locked?(inst)
37
- (inst.attr[@lock_attr] == true) || (inst.attr[@lock_attr] == 't')
38
- end # def
39
-
40
- end # module
41
-
42
- module Lockable_Entity
43
- def lock!
44
- self.class.lock!(self)
45
- end
46
- def release!
47
- self.class.release!(self)
48
- end
49
- def locked?
50
- self.class.locked?(self)
51
- end
52
- end
53
-
54
- end # module
55
- end # module