Module: Inform

Defined in:
lib/story_teller/tree.rb,
lib/story_teller/events.rb,
lib/story_teller/events.rb,
lib/story_teller/events.rb,
lib/story_teller/stdlib.rb,
lib/story_teller/context.rb,
lib/story_teller/helpers.rb,
lib/story_teller/helpers.rb,
lib/story_teller/helpers.rb,
lib/story_teller/helpers.rb,
lib/story_teller/history.rb,
lib/story_teller/session.rb,
lib/story_teller/version.rb,
lib/story_teller/articles.rb,
lib/story_teller/prototype.rb,
lib/story_teller/world_tree.rb,
lib/story_teller/inform/base.rb,
lib/story_teller/grammar_parser.rb,
lib/story_teller/grammar_parser.rb,
lib/story_teller/grammar_parser.rb,
lib/story_teller/grammar_parser.rb,
lib/story_teller/inform/ephemeral/tag.rb,
lib/story_teller/inform/ephemeral/tag.rb,
lib/story_teller/inform/ephemeral/tag.rb,
lib/story_teller/inform/ephemeral/tag.rb,
lib/story_teller/inform/ephemeral/tag.rb,
lib/story_teller/inform/ephemeral/tag.rb,
lib/story_teller/inform/ephemeral/link.rb,
lib/story_teller/inform/ephemeral/link.rb,
lib/story_teller/inform/ephemeral/module.rb,
lib/story_teller/inform/ephemeral/module.rb,
lib/story_teller/inform/ephemeral/module.rb,
lib/story_teller/inform/ephemeral/object.rb,
lib/story_teller/inform/ephemeral/object.rb,
lib/story_teller/experimental/handler_dsl.rb

Overview

The Inform module

Defined Under Namespace

Modules: AdapterClassDelegation, Behavior, BuilderInstanceMethods, Context, Ephemeral, Events, Genealogical, Grammar, History, IO, Linkable, Matchers, Modular, NilClassObjectHelpers, NilClassSetHelpers, ObjectHelpers, Parser, Prototypical, SetHelpers, StdLib, TagHelpers, Taggable, Verbs Classes: BehaviorError, DuplicateVerb, Event, EventCauseRecordNotFoundError, Link, Modularized, Module, Object, Tag, TagRegistry, Tagged, UnexpectedToken, Verb

Constant Summary collapse

VERSION =
StoryTeller::Engine::VERSION
VN_1610 =
'1610'.freeze
Dictionary =
Set.new
EphemeralObjects =
if defined?(Java)
  java.util.concurrent.ConcurrentHashMap.new
else
  {}
end
EphemeralObjectsChildren =
if defined?(Java)
  java.util.concurrent.ConcurrentHashMap.new
else
  {}
end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.attributesObject



125
126
127
# File 'lib/story_teller/inform/ephemeral/tag.rb', line 125

def self.attributes
  TagRegistry::SINGLETON.memo ||= TagRegistry.new
end

.Grammar(src) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/story_teller/grammar_parser.rb', line 32

def Grammar(src)
  source_location = caller_locations(1, 1).first
  mod_name = File.basename(source_location.path, '.*').gsub(/\W+/, '_').to_sym
  Inform::Grammar::Parser.new.parse_grammar(mod_name, src.each_line,
    origin_path: source_location.path, origin_line: source_location.lineno)
  self
end

Instance Method Details

#builder(target, behavior, context) ⇒ Object



155
156
157
158
159
160
161
162
# File 'lib/story_teller/experimental/handler_dsl.rb', line 155

def builder(target, behavior, context)
  Class.new do
    def initialize(target, behavior, context)
      @target, @behavior, @context = target, behavior, context
      self.extend(BuilderInstanceMethods)
    end
  end.new(target, behavior, context)
end

#context_proxy(target, context, proxy = Object.new) ⇒ Object

rubocop: disable Metrics/MethodLength



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/story_teller/experimental/handler_dsl.rb', line 97

def context_proxy(target, context, proxy = Object.new)
  return target if context.nil?

  proxy.define_singleton_method(:method_missing) do |method_name, *args, &block|
    if context.local_variable_defined?(method_name)
      context.local_variable_get(method_name)
    elsif target.respond_to?(method_name)
      target.public_send(method_name, *args, &block)
    else
      super(method_name, *args, &block)
    end
  end

  proxy.define_singleton_method(:respond_to_missing?) do |method_name, include_private = false|
    context.local_variable_defined?(method_name) || target.respond_to?(method_name, include_private)
  end

  proxy
end

#ensure_behavior_module!(key, behavior) ⇒ Object

Raises:



124
125
126
# File 'lib/story_teller/experimental/handler_dsl.rb', line 124

def ensure_behavior_module!(key, behavior)
  raise BehaviorError.new(key, behavior) unless behavior.is_a?(::Module)
end

#extend_and_persist(behavior) ⇒ Object

rubocop: enable Metrics/MethodLength



118
119
120
121
122
# File 'lib/story_teller/experimental/handler_dsl.rb', line 118

def extend_and_persist(behavior)
  self.extend(behavior)
  self.save_changes if self.respond_to?(:save_changes)
  self
end

#with(context = nil, key = Inform::Behavior.key_for(self), &block) ⇒ Object

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



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/story_teller/experimental/handler_dsl.rb', line 72

def with(context = nil, key = Inform::Behavior.key_for(self), &block)
  log.debug "with.self=#{self.inspect} (#{self.identity})"
  behavior = Inform::Behavior::REGISTRY[key] ||= ::Module.new
  ensure_behavior_module!(key, behavior)

  unless block.nil?
    proxy = context_proxy(context || self, block.binding)
    b = builder(self, behavior, proxy)
    klass = b.class
    before = klass.instance_methods(false)

    b.instance_exec(proxy, &block)

    added = klass.instance_methods(false) - before
    added.each do |m|
      behavior.define_method(m, klass.instance_method(m))
    end
  end

  extend_and_persist(behavior)
end