Module: SPQR::Manageable
- Defined in:
- lib/spqr/manageable.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#fail(*args) ⇒ Object
fail takes either (up to) three arguments or a hash the three arguments are: * =status= (an integer failure code) * =message= (a descriptive failure message, defaults to nil) * =result= (a value to return, defaults to nil; currently ignored by QMF) the hash simply maps from keys =:status=, =:message=, and =:result= to their respective values.
- #log ⇒ Object
-
#qmf_context ⇒ Object
Returns QMF context of the current method invocation.
- #qmf_id ⇒ Object
- #qmf_oid ⇒ Object
-
#qmf_user_id ⇒ Object
Returns the user ID of the QMF user invoking this method.
Class Method Details
.included(other) ⇒ Object
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/spqr/manageable.rb', line 330 def self.included(other) class << other include ManageableClassMixins alias_method :qmf_singleton, :is_singleton end unless other.respond_to? :find_by_id def other.find_by_id(id) raise "#{self} must define find_by_id(id)" end end unless other.respond_to? :find_all def other.find_all raise "#{self} must define find_all" end end unless other.respond_to? :class_id def other.class_id package_list = .package.to_s.split(".") cls = .classname.to_s or self.name.to_s # XXX: this foolishly assumes that we are running on a 64-bit machine or a 32-bit machine ((package_list.map {|pkg| pkg.capitalize} << cls).join("::")).hash & (0.size == 8 ? 0x7fffffff : 0x3fffffff) end end name_components = other.name.to_s.split("::") other.qmf_class_name name_components.pop other.qmf_package_name name_components.join(".").downcase end |
Instance Method Details
#fail(*args) ⇒ Object
fail takes either (up to) three arguments or a hash the three arguments are:
* =status= (an integer failure code)
* =message= (a descriptive failure message, defaults to nil)
* =result= (a value to return, defaults to nil; currently ignored by QMF)
the hash simply maps from keys =:status=, =:message=, and =:result= to their respective values. Only =:status= is required.
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/spqr/manageable.rb', line 280 def fail(*args) unless args.size <= 3 && args.size >= 1 raise RuntimeError.new("SPQR::Manageable#fail takes at least one parameter but not more than three; received #{args.inspect}") end if args.size == 1 and args[0].class = Hash failhash = args[0] unless failhash[:status] && failhash[:status].is_a?(Fixnum) raise RuntimeError.new("SPQR::Manageable#fail requires a Fixnum-valued :status parameter when called with keyword arguments; received #{failhash[:status].inspect}") end raise ManageableObjectError.new(failhash[:status], failhash[:message], failhash[:result]) end raise ManageableObjectError.new(*args) end |
#log ⇒ Object
326 327 328 |
# File 'lib/spqr/manageable.rb', line 326 def log self.class.log end |
#qmf_context ⇒ Object
Returns QMF context of the current method invocation
304 305 306 |
# File 'lib/spqr/manageable.rb', line 304 def qmf_context Thread.current[:qmf_context] end |
#qmf_id ⇒ Object
322 323 324 |
# File 'lib/spqr/manageable.rb', line 322 def qmf_id [qmf_oid, self.class.class_id] end |
#qmf_oid ⇒ Object
308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/spqr/manageable.rb', line 308 def qmf_oid result = 0 if self.respond_to? :spqr_object_id result = spqr_object_id elsif self.respond_to? :row_id result = row_id else result = object_id end # XXX: this foolishly assumes that we are running on a 64-bit machine or a 32-bit machine result & (0.size == 8 ? 0x7fffffff : 0x3fffffff) end |
#qmf_user_id ⇒ Object
Returns the user ID of the QMF user invoking this method
299 300 301 |
# File 'lib/spqr/manageable.rb', line 299 def qmf_user_id Thread.current[:qmf_user_id] end |