Class: Intersys::Object
- Inherits:
-
Object
- Object
- Intersys::Object
- Extended by:
- Callable
- Includes:
- Callable
- Defined in:
- lib/object.rb,
lib/callable.rb
Overview
%Library.List
Direct Known Subclasses
Reflection::ClassDefinition, Reflection::MethodDefinition, Reflection::PropertyDefinition, Reflection::RelationshipObject
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
86 87 88 89 90 |
# File 'lib/object.rb', line 86 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
64 65 66 67 68 69 70 |
# File 'lib/object.rb', line 64 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
122 123 124 |
# File 'lib/object.rb', line 122 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
94 95 96 97 98 |
# File 'lib/object.rb', line 94 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
133 134 135 |
# File 'lib/object.rb', line 133 def delete_all intersys_call("%DeleteExtent") end |
.inherited(klass) ⇒ Object
:nodoc
117 118 119 |
# File 'lib/object.rb', line 117 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
51 52 53 54 55 56 57 58 59 |
# File 'lib/object.rb', line 51 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
73 74 75 |
# File 'lib/object.rb', line 73 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
80 81 82 83 |
# File 'lib/object.rb', line 80 def prefix(name = nil) self.prefix = name if name @prefix ||= "User" end |
.timeout ⇒ Object
timeout for connection
127 128 129 |
# File 'lib/object.rb', line 127 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
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/object.rb', line 104 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
145 146 147 |
# File 'lib/object.rb', line 145 def class_name self.class.class_name end |
#database ⇒ Object
You can ask for database from instance
140 141 142 |
# File 'lib/object.rb', line 140 def database self.class.database end |
#destroy ⇒ Object
Destroys current object
158 159 160 |
# File 'lib/object.rb', line 158 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
153 154 155 |
# File 'lib/object.rb', line 153 def id intersys_call("%Id").to_i end |