Class: DIY::ObjectDef

Inherits:
Object
  • Object
show all
Defined in:
lib/diy.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ ObjectDef

Returns a new instance of ObjectDef.



306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
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
362
363
364
365
366
# File 'lib/diy.rb', line 306

def initialize(opts)
  name = opts[:name]
  raise "Can't make an ObjectDef without a name" if name.nil?

  info = opts[:info] || {}
  info = info.clone

  @components = {}

  # Object name
  @name = name

  # Class name
  @class_name = info.delete 'class'
  @class_name ||= info.delete 'type'
  @class_name ||= Infl.camelize(@name)

  # Auto Require
  @auto_require = info.delete 'auto_require'

  # Library
  @library = info.delete 'library'
  @library ||= info.delete 'lib'
  @library ||= Infl.underscore(@class_name) if @auto_require

  # Use Class Directly
  @use_class_directly = info.delete 'use_class_directly'
  
  # Auto-compose
  compose = info.delete 'compose'
  if compose
    case compose
    when Array
      auto_names = compose.map { |x| x.to_s }
    when String
      auto_names = compose.split(',').map { |x| x.to_s.strip }
    when Symbol
      auto_names = [ compose.to_s ]
    else
      raise "Cannot auto compose object #{@name}, bad 'compose' format: #{compose.inspect}"
    end
  end
  auto_names ||= []
  auto_names.each do |cname|
    @components[cname] = Lookup.new(cname)
  end

  # Singleton status
  if info['singleton'].nil?
    @singleton = true
  else
    @singleton = info['singleton']
  end
  info.delete 'singleton'

  # Remaining keys
  info.each do |key,val|
    @components[key.to_s] = Lookup.new(val.to_s)
  end

end

Instance Attribute Details

#class_nameObject

Returns the value of attribute class_name.



305
306
307
# File 'lib/diy.rb', line 305

def class_name
  @class_name
end

#componentsObject

Returns the value of attribute components.



305
306
307
# File 'lib/diy.rb', line 305

def components
  @components
end

#libraryObject

Returns the value of attribute library.



305
306
307
# File 'lib/diy.rb', line 305

def library
  @library
end

#nameObject

Returns the value of attribute name.



305
306
307
# File 'lib/diy.rb', line 305

def name
  @name
end

Instance Method Details

#singleton?Boolean

Returns:

  • (Boolean)


368
369
370
# File 'lib/diy.rb', line 368

def singleton?
  @singleton
end

#use_class_directly?Boolean

Returns:

  • (Boolean)


372
373
374
# File 'lib/diy.rb', line 372

def use_class_directly?
  @use_class_directly == true
end