Module: SPQR::ManageableClassMixins
- Defined in:
- lib/spqr/manageable.rb
Class Method Summary collapse
- .delete(instance) ⇒ Object
- .find_all ⇒ Object
- .find_by_id(id) ⇒ Object
- .instances ⇒ Object
-
.new(*args) ⇒ Object
XXX: would it make more sense to call allocate and initialize explicitly?.
Instance Method Summary collapse
- #app ⇒ Object
- #app=(app) ⇒ Object
-
#expose(name, description = nil, options = nil, &blk) ⇒ Object
Exposes a method to QMF.
-
#is_singleton ⇒ Object
Declares that this class is a singleton class; that is, only one instance will be published over QMF.
-
#is_tracked ⇒ Object
Declares that instances of this class will automatically be tracked (and find_all and find_by_id methods generated).
- #log ⇒ Object
- #log=(logger) ⇒ Object
- #qmf_class_name(nm) ⇒ Object
- #qmf_description(d) ⇒ Object
- #qmf_options(opts) ⇒ Object
- #qmf_package_name(nm) ⇒ Object
- #qmf_property(name, kind, options = nil) ⇒ Object
- #qmf_statistic(name, kind, options = nil) ⇒ Object
- #spqr_meta ⇒ Object
Class Method Details
.delete(instance) ⇒ Object
207 208 209 |
# File 'lib/spqr/manageable.rb', line 207 def self.delete(instance) instances.delete(instance.qmf_oid) end |
.find_all ⇒ Object
169 170 171 |
# File 'lib/spqr/manageable.rb', line 169 def self.find_all instances end |
.find_by_id(id) ⇒ Object
173 174 175 |
# File 'lib/spqr/manageable.rb', line 173 def self.find_by_id(id) instances[0] end |
.instances ⇒ Object
165 166 167 |
# File 'lib/spqr/manageable.rb', line 165 def self.instances @instances ||= [self.new] end |
.new(*args) ⇒ Object
XXX: would it make more sense to call allocate and initialize explicitly?
201 202 203 204 205 |
# File 'lib/spqr/manageable.rb', line 201 def self.new(*args) result = old_new(*args) instances[result.qmf_oid] = result result end |
Instance Method Details
#app ⇒ Object
153 154 155 |
# File 'lib/spqr/manageable.rb', line 153 def app @spqr_app end |
#app=(app) ⇒ Object
149 150 151 |
# File 'lib/spqr/manageable.rb', line 149 def app=(app) @spqr_app = app end |
#expose(name, description = nil, options = nil, &blk) ⇒ Object
Exposes a method to QMF
158 159 160 |
# File 'lib/spqr/manageable.rb', line 158 def expose(name, description=nil, =nil, &blk) .declare_method(name, description, , blk) end |
#is_singleton ⇒ Object
Declares that this class is a singleton class; that is, only one instance will be published over QMF
164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/spqr/manageable.rb', line 164 def is_singleton def self.instances @instances ||= [self.new] end def self.find_all instances end def self.find_by_id(id) instances[0] end end |
#is_tracked ⇒ Object
Declares that instances of this class will automatically be tracked (and find_all and find_by_id methods generated). Instances of automatically-tracked classes must be explicitly deleted (with the delete class method). Do not use automatic tracking with Rhubarb, which automatically tracks instances for you.
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/spqr/manageable.rb', line 184 def is_tracked # no pun intended, I promise alias_method :old_new, :new def self.instances @instances ||= {} end def self.find_all instances.values end def self.find_by_id(id) instances[id] end # XXX: would it make more sense to call allocate and initialize explicitly? def self.new(*args) result = old_new(*args) instances[result.qmf_oid] = result result end def self.delete(instance) instances.delete(instance.qmf_oid) end end |
#log ⇒ Object
145 146 147 |
# File 'lib/spqr/manageable.rb', line 145 def log @spqr_log || ::SPQR::Sink.new end |
#log=(logger) ⇒ Object
141 142 143 |
# File 'lib/spqr/manageable.rb', line 141 def log=(logger) @spqr_log = logger end |
#qmf_class_name(nm) ⇒ Object
216 217 218 |
# File 'lib/spqr/manageable.rb', line 216 def qmf_class_name(nm) .classname = nm end |
#qmf_description(d) ⇒ Object
220 221 222 |
# File 'lib/spqr/manageable.rb', line 220 def qmf_description(d) .description = d end |
#qmf_options(opts) ⇒ Object
224 225 226 |
# File 'lib/spqr/manageable.rb', line 224 def (opts) . = opts.dup end |
#qmf_package_name(nm) ⇒ Object
212 213 214 |
# File 'lib/spqr/manageable.rb', line 212 def qmf_package_name(nm) .package = nm end |
#qmf_property(name, kind, options = nil) ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/spqr/manageable.rb', line 244 def qmf_property(name, kind, =nil) .declare_property(name, kind, ) # add a property accessor to instances of other self.class_eval do # XXX: should cons up a "safe_attr_accessor" method that works like this: attr_reader name.to_sym unless method_defined? "#{name}" attr_writer name.to_sym unless method_defined? "#{name}=" end if and [:index] # if this is an index property, add a find-by method if one # does not already exist spqr_define_index_find(name) end end |
#qmf_statistic(name, kind, options = nil) ⇒ Object
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/spqr/manageable.rb', line 228 def qmf_statistic(name, kind, =nil) .declare_statistic(name, kind, ) self.class_eval do # XXX: are we only interested in declaring a reader for # statistics? Doesn't it really makes more sense for the managed # class to declare a method with the same name as the # statistic so we aren't declaring anything at all here? # XXX: should cons up a "safe_attr_reader" method that works # like this: attr_reader name.to_sym unless method_defined? "#{name}" attr_writer name.to_sym unless method_defined? "#{name}=" end end |
#spqr_meta ⇒ Object
137 138 139 |
# File 'lib/spqr/manageable.rb', line 137 def @spqr_meta ||= ::SPQR::ManageableMeta.new end |