Class: Inform::System::Object

Inherits:
Object
  • Object
show all
Includes:
Inform, Daemons, Events, Genealogical, IO, Linkable, Prototypical, Publisher, Taggable
Defined in:
lib/runtime/tag.rb,
lib/runtime/object.rb,
lib/runtime/world_tree.rb

Overview

The Inform::System::Object functionality

Direct Known Subclasses

Daemons::Entheogen

Constant Summary collapse

Instances =
Struct.new(:memo).new(defined?(Java) ? java.util.concurrent.CopyOnWriteArrayList.new : [])

Constants included from Daemons

Daemons::DaemonExecutionElapsedMessage, Daemons::DaemonScanElapsedMessage, Daemons::RecordNotFoundPattern

Constants included from Prototypical

Prototypical::AccessorMethodTemplate, Prototypical::LinkPattern, Prototypical::MISSING_PROPERTIES_MESSAGE, Prototypical::MethodBooleanOrBangPattern, Prototypical::MethodWriterPattern, Prototypical::MethodWriterTemplate, Prototypical::VariableTemplate, Prototypical::WriterMethodTemplate

Constants included from Inform::Subscribers

Inform::Subscribers::REGISTRY

Constants included from Events

Events::DEFAULT_ADD_EVENT_PARAMS, Events::REGISTRY, Events::THREADS_PER_PROCESSOR

Constants included from IO

IO::ItemPaddingString, IO::MinimumCellPadding, IO::MinimumColumnPadding, IO::MinimumLineLength

Constants included from Inform

Dictionary, INFORM_DIR_PATH, LIB_DIR_PATH, MethodDefinitionPattern, MethodTerminationPattern, NOUN, PLURAL, PREPOSITION, PROJECT_DIR_PATH, RUNTIME_DIR_PATH, Inform::SystemObjects, VERB, VERSION, VN_1610

Constants included from Color

Color::BackgroundColorCodes, Color::ColorCodes, Color::NearestColor, Color::StyleCodes

Constants included from Articles

Articles::LowercaseASpaceString, Articles::LowercaseSomeSpaceString, Articles::LowercaseTheSpaceString

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Daemons

#StartDaemon, #StartTimer, #StopDaemon, #StopTimer, #before_destroy, #daemonic?, #daemonize, daemons, ensure_inform_library, execute, execute_daemon, execute_each_turn, #ghost, #heart, #init_heart, #occasionally, #on?, refresh_or_remove, #rescan, scan_objects, #schedules, #spawn, start, stop

Methods included from Genealogical

#>, #all?, #any?, #branch, #child, #collect, #concat, #count, #delete_if, #each, #each_with_object, #find, #find_all, #having, #in?, #include?, #map, #notin?, #reject, #select, #sibling, #siblings, #within?

Methods included from Taggable

#nil_safe_tags, #tag_names, #tagged_with?, #tagged_with_all?, #tagged_with_any?, #tagged_with_none?

Methods included from TagHelpers

#attributes, #has, #has?, #hasany?, #hasnt, #hasnt?

Methods included from Prototypical

#&, #_assign, #_get, #_set, #accessor_and_writer, #context_event, #ensure_properties_attribute!, #instance_variables_map, #key_refers_to_link?, #method_missing, #prototype, #string?, #|

Methods included from Publisher

#muted?, #publish, #publish_except, #publish_only, #publish_system_message, #subscribers

Methods included from Inform::Subscribers

#explicit_subscribers, #subscribe, #subscribers, #unsubscribe, #unsubscribe_all

Methods included from Events

#active?, active_objects, #add_event, available_processors, #contextualize, #delay, each, #elementally, #event, #events, #immediately, init_java_pool, init_java_pooled_executor, init_java_scheduled_executor, init_java_scheduler, init_pool, init_scheduled_executor, init_scheduler, #interrupt, object_events, pool, pooled_executor, possibilities, #register_callback, scheduled_executor, scheduler

Methods included from IO

#connections, #flush_io, #inform, #many_per_line, #new_line, #noop, #out, #output_stream, #print, #println, #prompt, #read, #reset_prompt, #session, #spaces, #tidy_output

Methods included from Inform

Grammar, #apply_instance_behavior!, attributes, #builder, #classification, #compass, #content, context, context_class, #context_proxy, #current_word, #deadflag, #deadflag=, #dict_par1, #dictionary, #disrobe, #drop, #emote, #ensure_behavior_module!, #extend_and_persist, #findobject, #getobject, #go, #initial, initialize_persistence_layer, #language_descriptors, #language_pronouns, #library_method?, #life?, #light_adjusted, load_grammar, load_grammar_by_path, #method_source, #nothing, #num_words, #number, #objectloop, #ofclass, #pause, prime_dictionary, #provides?, #quit, #randomly, #react_after?, #react_before?, #remaining_words, #resembles_method?, #run_daemons, #say, #score, #score=, #search, #special, #the_time, #the_time=, #things_score, #things_score=, #topic, unload_grammars!, #visibility_ceiling=, #with, #workflags

Methods included from Plurals

#apply_inflections, #plural?, #pluralize, #singular?, #singularize

Methods included from Color

#background_color, #color, #nearest_color, #style, #un_background_color, #un_color, #un_style

Methods included from Articles

#A, #Cthatorthose, #Ctheyreorthats, #The, #a, #cthatorthose, #ctheyreorthats, #defart, #indefart, #isorare, #itorthem, #thatorthose, #the

Constructor Details

#initialize(textual_name = nil, *args, &block) ⇒ Object

rubocop: disable Metrics/AbcSize rubocop: disable Metrics/MethodLength



474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'lib/runtime/object.rb', line 474

def initialize(textual_name = nil, *args, &block)
  super(*args)
  @name = textual_name || self.class.name
  @short_name = textual_name || format('(%<short_name>s)', short_name: self.class.name)
  @display_name = textual_name
  @description = nil
  @adjectives = []
  @properties = {}
  @links = []
  @modules = []
  @tags = []
  @children = []
  @visited = []
  @created_at = @modified_at = Time.now
  index_words if respond_to?(:index_words)
  index_obj(self)
  self.with(&block) if block_given?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Inform::Prototypical

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



465
466
467
# File 'lib/runtime/object.rb', line 465

def created_at
  @created_at
end

#description(*args) ⇒ Object



554
555
556
557
558
# File 'lib/runtime/object.rb', line 554

def description(*args)
  return @description if args.nil? || args.empty?
  @description = args.length > 1 ? args.join(' ') : args
  @description
end

#display_nameObject

Returns the value of attribute display_name.



465
466
467
# File 'lib/runtime/object.rb', line 465

def display_name
  @display_name
end

#inflibObject

Returns the value of attribute inflib.



465
466
467
# File 'lib/runtime/object.rb', line 465

def inflib
  @inflib
end

Returns the value of attribute links.



465
466
467
# File 'lib/runtime/object.rb', line 465

def links
  @links
end

#modified_atObject

Returns the value of attribute modified_at.



465
466
467
# File 'lib/runtime/object.rb', line 465

def modified_at
  @modified_at
end

#modulesObject

Returns the value of attribute modules.



465
466
467
# File 'lib/runtime/object.rb', line 465

def modules
  @modules
end

#propertiesObject Also known as: values

Returns the value of attribute properties.



465
466
467
# File 'lib/runtime/object.rb', line 465

def properties
  @properties
end

#short_nameObject

Returns the value of attribute short_name.



465
466
467
# File 'lib/runtime/object.rb', line 465

def short_name
  @short_name
end

#tagsObject

Returns the value of attribute tags.



282
283
284
# File 'lib/runtime/tag.rb', line 282

def tags
  @tags ||= []
end

#visitedObject

Returns the value of attribute visited.



465
466
467
# File 'lib/runtime/object.rb', line 465

def visited
  @visited
end

Class Method Details

.allObject



503
504
505
# File 'lib/runtime/object.rb', line 503

def self.all
  Instances.memo.dup
end

.clearObject



507
508
509
# File 'lib/runtime/object.rb', line 507

def self.clear
  Instances.memo.clear
end

Instance Method Details

#<<(o) ⇒ Object



568
569
570
571
572
573
# File 'lib/runtime/object.rb', line 568

def <<(o)
  return if self == o
  return unless o.object?
  o.parent = self
  @children << o
end

#<=>(other) ⇒ Object



527
528
529
# File 'lib/runtime/object.rb', line 527

def <=>(other)
  self.name <=> other.name
end

#[](property) ⇒ Object



511
512
513
514
515
516
# File 'lib/runtime/object.rb', line 511

def [](property)
  return description if property == :description
  return name if property == :name
  return short_name if property == :short_name
  properties[property]
end

#_get_object(link_name) ⇒ Object



631
632
633
# File 'lib/runtime/object.rb', line 631

def _get_object(link_name)
  find_link(link_name)&.to
end

#_set_object(link_name, obj = nil) ⇒ Object

rubocop: enable Style/TrivialAccessors



627
628
629
# File 'lib/runtime/object.rb', line 627

def _set_object(link_name, obj = nil)
  link(link_name, obj).to
end

#ancestorsObject



599
600
601
# File 'lib/runtime/object.rb', line 599

def ancestors
  self.parent.nil? ? [] : self.parent.ancestors + [self.parent]
end

#children(o = nil, prop = :@children) ⇒ Object



584
585
586
587
588
# File 'lib/runtime/object.rb', line 584

def children(o = nil, prop = :@children)
  return @children if o.nil?
  return o.instance_variable_get(prop).length if o.instance_variable_defined?(prop)
  o.children.length
end

#descendantsObject



603
604
605
# File 'lib/runtime/object.rb', line 603

def descendants
  @children + @children.map(&:descendants).flatten
end

#empty?(*args, &block) ⇒ Boolean

Returns:

  • (Boolean)


580
581
582
# File 'lib/runtime/object.rb', line 580

def empty?(*args, &block)
  self.children.empty?(*args, &block)
end


635
636
637
# File 'lib/runtime/object.rb', line 635

def find_link(link_name)
  links.find { |x| x.name == link_name }
end

#idObject



538
539
540
# File 'lib/runtime/object.rb', line 538

def id
  self.object_id
end

#index_obj(obj) ⇒ Object

rubocop: enable Metrics/AbcSize rubocop: enable Metrics/MethodLength



495
496
497
498
499
500
501
# File 'lib/runtime/object.rb', line 495

def index_obj(obj)
  if Instances.memo.respond_to?(:add)
    Instances.memo.add(obj)
  else
    Instances.memo << obj
  end
end

#initObject Also known as: safe_init



667
668
669
# File 'lib/runtime/object.rb', line 667

def init
  self
end

#inspectObject



686
687
688
# File 'lib/runtime/object.rb', line 686

def inspect
  identity
end


639
640
641
642
643
# File 'lib/runtime/object.rb', line 639

def link(link_name, obj = nil)
  link = Inform::System::Link.new(name: link_name, to: obj, from: self)
  links << link
  link
end

#linked?(link_name) ⇒ Boolean Also known as: _key?

Returns:

  • (Boolean)


645
646
647
# File 'lib/runtime/object.rb', line 645

def linked?(link_name)
  links.count { |x| x.name == link_name } > 0
end

#linksfrom(link_name = nil) ⇒ Object



659
660
661
662
663
664
665
# File 'lib/runtime/object.rb', line 659

def linksfrom(link_name = nil)
  if link_name.nil?
    links.select { |x| x.to == self }.map(&:from)
  else
    links.select { |x| x.name == link_name && x.to == self }.map(&:from)
  end
end

#linkto(link_name) ⇒ Object



655
656
657
# File 'lib/runtime/object.rb', line 655

def linkto(link_name)
  _get_object(link_name)
end

#list_togetherObject



595
596
597
# File 'lib/runtime/object.rb', line 595

def list_together
  linkto :list_together
end

#locationObject

TODO: Remove if possible after unit test implementation



591
592
593
# File 'lib/runtime/object.rb', line 591

def location
  self.parent
end

#name(*args) ⇒ Object



546
547
548
549
550
551
552
# File 'lib/runtime/object.rb', line 546

def name(*args)
  return args.first.object_name if args.first.respond_to?(:object_name)
  return @name if args.empty?
  @name = ([@name] | args).flatten.uniq
  index_words if respond_to?(:index_words)
  @name
end

#name_wordsObject



564
565
566
# File 'lib/runtime/object.rb', line 564

def name_words
  @name.split(/[,\s]+/).join(', ')
end

#object_nameObject



560
561
562
# File 'lib/runtime/object.rb', line 560

def object_name
  @display_name || @short_name || @name
end

#object_typeObject



542
543
544
# File 'lib/runtime/object.rb', line 542

def object_type
  self.class
end

#parent(o = nil, &block) ⇒ Object



611
612
613
614
615
616
617
618
619
# File 'lib/runtime/object.rb', line 611

def parent(o = nil, &block)
  return @parent if o.nil?
  o.safe_refresh if o.respond_to? :safe_refresh
  return unless o.respond_to? :parent
  obj_parent = block_given? ? parent_selector(o, &block) : o.parent
  return nil if obj_parent.nil?
  obj_parent.safe_refresh if obj_parent.respond_to? :safe_refresh
  obj_parent
end

#parent=(o) ⇒ Object

rubocop: disable Style/TrivialAccessors



622
623
624
# File 'lib/runtime/object.rb', line 622

def parent=(o)
  @parent = o
end

#parse(s) ⇒ Object



531
532
533
534
535
536
# File 'lib/runtime/object.rb', line 531

def parse(s)
  return if inflib.nil?
  inflib.semaphore.synchronize do
    inflib.println(inflib.parse(s))
  end
end

#refreshObject Also known as: safe_refresh



672
673
674
# File 'lib/runtime/object.rb', line 672

def refresh
  self
end

#removeObject



575
576
577
578
# File 'lib/runtime/object.rb', line 575

def remove
  @children.clear
  @parent = nil
end

#rootObject



607
608
609
# File 'lib/runtime/object.rb', line 607

def root
  self.parent.nil? ? self : self.parent.root
end

#save(*_args) ⇒ Object Also known as: safe_save



677
678
679
# File 'lib/runtime/object.rb', line 677

def save(*_args)
  self
end

#tag(*args) ⇒ Object



266
267
268
269
270
271
272
# File 'lib/runtime/tag.rb', line 266

def tag(*args)
  workflags.add self.identity if args.delete :workflag
  tag_names(args).each do |tag|
    tags << tag.to_sym
  end
  self
end

#to_hashObject



518
519
520
521
522
523
524
525
# File 'lib/runtime/object.rb', line 518

def to_hash
  properties.merge(
    id: id,
    name: name,
    short_name: short_name,
    description: description
  )
end

#to_sObject



682
683
684
# File 'lib/runtime/object.rb', line 682

def to_s
  self.name
end


650
651
652
# File 'lib/runtime/object.rb', line 650

def unlink(link_name)
  links.delete_at(links.index { |x| x.name == link_name })
end

#untag(*args) ⇒ Object



274
275
276
277
278
279
280
# File 'lib/runtime/tag.rb', line 274

def untag(*args)
  workflags.delete self.identity if args.delete :workflag
  (nil_safe_tags & tag_names(args)).each do |tag|
    tags.delete tag
  end
  self
end