Module: SPQR::ManageableClassMixins

Defined in:
lib/spqr/manageable.rb

Instance Method Summary collapse

Instance Method Details

#expose(name, description = nil, options = nil, &blk) ⇒ Object

Exposes a method to QMF



140
141
142
# File 'lib/spqr/manageable.rb', line 140

def expose(name, description=nil, options=nil, &blk)
  spqr_meta.declare_method(name, description, options, blk)
end

#logObject



135
136
137
# File 'lib/spqr/manageable.rb', line 135

def log
  @spqr_log || ::SPQR::Sink.new
end

#log=(logger) ⇒ Object



131
132
133
# File 'lib/spqr/manageable.rb', line 131

def log=(logger)
  @spqr_log = logger
end

#qmf_class_name(nm) ⇒ Object



148
149
150
# File 'lib/spqr/manageable.rb', line 148

def qmf_class_name(nm)
  spqr_meta.classname = nm
end

#qmf_description(d) ⇒ Object



152
153
154
# File 'lib/spqr/manageable.rb', line 152

def qmf_description(d)
  spqr_meta.description = d
end

#qmf_options(opts) ⇒ Object



156
157
158
# File 'lib/spqr/manageable.rb', line 156

def qmf_options(opts)
  spqr_meta.options = opts.dup
end

#qmf_package_name(nm) ⇒ Object



144
145
146
# File 'lib/spqr/manageable.rb', line 144

def qmf_package_name(nm)
  spqr_meta.package = nm
end

#qmf_property(name, kind, options = nil) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/spqr/manageable.rb', line 176

def qmf_property(name, kind, options=nil)
  spqr_meta.declare_property(name, kind, options)
  
  # 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 instance_methods.include? "#{name}"
    attr_writer name.to_sym unless instance_methods.include? "#{name}="
  end
  
  if options and options[: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



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/spqr/manageable.rb', line 160

def qmf_statistic(name, kind, options=nil)
  spqr_meta.declare_statistic(name, kind, options)
  
  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 instance_methods.include? "#{name}"
    attr_writer name.to_sym unless instance_methods.include? "#{name}="
  end
end

#spqr_metaObject



127
128
129
# File 'lib/spqr/manageable.rb', line 127

def spqr_meta
  @spqr_meta ||= ::SPQR::ManageableMeta.new
end