Class: Intersys::Object
- Inherits:
-
Object
- Object
- Intersys::Object
- Extended by:
- Callable
- Includes:
- Callable
- Defined in:
- lib/intersys.rb
Overview
Basic class for all classes, through which is performed access to Cache classes For each Cache class must be created ruby class, inherited from Intersys::Object
By default prefix “User” is selected. If Cache class has another prefix, it must be provided explicitly via method “prefix”:
class List < Intersys::Object
prefix "%Library"
end
By default name of Cache class is taken the same as name of ruby class. Thus in this example this class List will be marshalled to Cache class %Library.List
Direct Known Subclasses
Reflection::ClassDefinition, Reflection::MethodDefinition, Reflection::PropertyDefinition, Reflection::RelationshipObject, Person
Class Method Summary collapse
-
.class_name(name = nil) ⇒ Object
Returns Cache class name, if called without parameters, or sets one, if passed.
-
.common_get_or_set(name, default_value = nil) ⇒ Object
Help to work with instance variables of Intersys::Object class required, because list of registered descendants of Intersys::Object, database connection etc.
-
.concurrency ⇒ Object
Look into Cache documentation for what is concurrency.
-
.database(db_options = {}) ⇒ Object
Returns database, if called without parameters, or sets one, if passed Once established, it is not possible now to connect to another database.
-
.delete_all ⇒ Object
Nice method, that deletes all instances of class.
-
.inherited(klass) ⇒ Object
:nodoc.
-
.intersys_description ⇒ Object
Nice function, that generates description of Cache class, looking just as C++ one Maybe, later, it will be possible even to generate IDL, using this code.
-
.lookup(class_name) ⇒ Object
Takes Cache class name and try to resolve it to Ruby class.
-
.prefix(name = nil) ⇒ Object
Each Cache class has prefix before it’s name: namespace.
-
.timeout ⇒ Object
timeout for connection.
-
.transaction ⇒ Object
This method takes block and executes it between START TRANSACTION and COMMIT TRANSACTION.
Instance Method Summary collapse
-
#class_name ⇒ Object
You can ask from instance it’s Cache class name.
-
#database ⇒ Object
You can ask for database from instance.
-
#destroy ⇒ Object
Destroys current object.
-
#id ⇒ Object
Returns id of current object.
Methods included from Callable
intersys_call, intersys_get, intersys_has_method?, intersys_has_property?, intersys_method, intersys_methods, intersys_properties, intersys_property, intersys_reflector, intersys_set, method_missing
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Intersys::Callable
Class Method Details
.class_name(name = nil) ⇒ Object
Returns Cache class name, if called without parameters, or sets one, if passed
194 195 196 197 198 |
# File 'lib/intersys.rb', line 194 def class_name(name = nil) self.class_name = name if name self.class_name = (prefix + "." + to_s) unless @class_name @class_name end |
.common_get_or_set(name, default_value = nil) ⇒ Object
Help to work with instance variables of Intersys::Object class required, because list of registered descendants of Intersys::Object, database connection etc. should be in one place
172 173 174 175 176 177 178 |
# File 'lib/intersys.rb', line 172 def common_get_or_set(name, default_value = nil) unless var = Intersys::Object.instance_variable_get(name) default = block_given? ? yield : default_value var = Intersys::Object.instance_variable_set(name, default) end var end |
.concurrency ⇒ Object
Look into Cache documentation for what is concurrency. I don’t know
230 231 232 |
# File 'lib/intersys.rb', line 230 def concurrency 1 end |
.database(db_options = {}) ⇒ Object
Returns database, if called without parameters, or sets one, if passed Once established, it is not possible now to connect to another database
202 203 204 205 206 |
# File 'lib/intersys.rb', line 202 def database( = {}) common_get_or_set("@database") do Intersys::Database.new({:user => "_SYSTEM", :password => "SYS", :namespace => "User"}.merge()) end end |
.delete_all ⇒ Object
Nice method, that deletes all instances of class. You can just Person.delete_extent, but Person.delete_all looks more like ActiveRecord
241 242 243 |
# File 'lib/intersys.rb', line 241 def delete_all intersys_call("%DeleteExtent") end |
.inherited(klass) ⇒ Object
:nodoc
225 226 227 |
# File 'lib/intersys.rb', line 225 def inherited(klass) class_names[klass.class_name] = klass end |
.intersys_description ⇒ Object
Nice function, that generates description of Cache class, looking just as C++ one Maybe, later, it will be possible even to generate IDL, using this code
159 160 161 162 163 164 165 166 167 |
# File 'lib/intersys.rb', line 159 def intersys_description "class #{class_name} { \n" + intersys_reflector.all_methods.map do |mtd| begin "\t"+intersys_method(mtd).description+";\n" rescue "\tundefined #{mtd}\n" end end.join("") + "};" end |
.lookup(class_name) ⇒ Object
Takes Cache class name and try to resolve it to Ruby class
181 182 183 |
# File 'lib/intersys.rb', line 181 def lookup(class_name) class_names[class_name] || raise(UnMarshallError, "Couldn't find registered class with Cache name '#{class_name}'") end |
.prefix(name = nil) ⇒ Object
Each Cache class has prefix before it’s name: namespace. this method set’s prefix for current class is provided, or just returns current prefix
188 189 190 191 |
# File 'lib/intersys.rb', line 188 def prefix(name = nil) self.prefix = name if name @prefix ||= "User" end |
.timeout ⇒ Object
timeout for connection
235 236 237 |
# File 'lib/intersys.rb', line 235 def timeout 5 end |
.transaction ⇒ Object
This method takes block and executes it between START TRANSACTION and COMMIT TRANSACTION
In case of exception ROLLBACK TRANSACTION is called
212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/intersys.rb', line 212 def transaction return unless block_given? database.start begin yield database.commit rescue StandardError => e database.rollback raise e end end |
Instance Method Details
#class_name ⇒ Object
You can ask from instance it’s Cache class name
253 254 255 |
# File 'lib/intersys.rb', line 253 def class_name self.class.class_name end |
#database ⇒ Object
You can ask for database from instance
248 249 250 |
# File 'lib/intersys.rb', line 248 def database self.class.database end |
#destroy ⇒ Object
Destroys current object
266 267 268 |
# File 'lib/intersys.rb', line 266 def destroy self.class.intersys_call("%DeleteId", id) end |
#id ⇒ Object
Returns id of current object. You can remove this method and You will get string ID, so leave it here However, if You ask reflector for id, it will give incorrect answer, because Cache allows id to be string
261 262 263 |
# File 'lib/intersys.rb', line 261 def id intersys_call("%Id").to_i end |