Class: DIY::ObjectDef
- Inherits:
-
Object
- Object
- DIY::ObjectDef
- Defined in:
- lib/diy.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#class_name ⇒ Object
Returns the value of attribute class_name.
-
#components ⇒ Object
Returns the value of attribute components.
-
#library ⇒ Object
Returns the value of attribute library.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(opts) ⇒ ObjectDef
constructor
A new instance of ObjectDef.
- #singleton? ⇒ Boolean
- #use_class_directly? ⇒ Boolean
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_name ⇒ Object
Returns the value of attribute class_name.
305 306 307 |
# File 'lib/diy.rb', line 305 def class_name @class_name end |
#components ⇒ Object
Returns the value of attribute components.
305 306 307 |
# File 'lib/diy.rb', line 305 def components @components end |
#library ⇒ Object
Returns the value of attribute library.
305 306 307 |
# File 'lib/diy.rb', line 305 def library @library end |
#name ⇒ Object
Returns the value of attribute name.
305 306 307 |
# File 'lib/diy.rb', line 305 def name @name end |
Instance Method Details
#singleton? ⇒ Boolean
368 369 370 |
# File 'lib/diy.rb', line 368 def singleton? @singleton end |
#use_class_directly? ⇒ Boolean
372 373 374 |
# File 'lib/diy.rb', line 372 def use_class_directly? @use_class_directly == true end |