inform-runtime 1.2.3 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +33 -41
- data/lib/story_teller/articles.rb +2 -1
- data/lib/story_teller/builtins.rb +63 -10
- data/lib/story_teller/color.rb +2 -1
- data/lib/story_teller/command.rb +2 -1
- data/lib/story_teller/context.rb +23 -27
- data/lib/story_teller/daemon.rb +2 -2
- data/lib/story_teller/engine.rb +45 -10
- data/lib/story_teller/events.rb +1 -1
- data/lib/story_teller/experimental/handler_dsl.rb +1 -16
- data/lib/story_teller/experimental/reverse_engineer_class.rb +1 -1
- data/lib/story_teller/grammar_parser.rb +60 -13
- data/lib/story_teller/helpers.rb +8 -4
- data/lib/story_teller/history.rb +1 -1
- data/lib/story_teller/inflector.rb +4 -2
- data/lib/story_teller/inform/ephemeral/link.rb +63 -31
- data/lib/story_teller/inform/ephemeral/module.rb +6 -5
- data/lib/story_teller/inform/ephemeral/object.rb +223 -236
- data/lib/story_teller/inform/ephemeral/tag.rb +27 -14
- data/lib/story_teller/io.rb +99 -49
- data/lib/story_teller/kernel.rb +2 -2
- data/lib/story_teller/library/bootstrap.rb +2 -2
- data/lib/story_teller/library/declarations.rb +1 -1
- data/lib/story_teller/library/directives.rb +1 -1
- data/lib/story_teller/library/loader.rb +3 -20
- data/lib/story_teller/library/location.rb +9 -3
- data/lib/story_teller/library.rb +1 -1
- data/lib/story_teller/logging.rb +1 -1
- data/lib/story_teller/mixins.rb +11 -4
- data/lib/story_teller/plurals.rb +2 -1
- data/lib/story_teller/privileges.rb +89 -6
- data/lib/story_teller/prototype.rb +150 -32
- data/lib/story_teller/publication.rb +2 -1
- data/lib/story_teller/session.rb +115 -25
- data/lib/story_teller/stdlib.rb +231 -1
- data/lib/story_teller/subscription.rb +2 -1
- data/lib/story_teller/tree.rb +2 -1
- data/lib/story_teller/version.rb +2 -2
- data/lib/story_teller/world_tree.rb +21 -23
- data/lib/story_teller.rb +18 -5
- metadata +6 -10
- data/lib/story_teller/core.rb +0 -39
- data/lib/story_teller/ephemeral_adapter.rb +0 -40
- data/lib/story_teller/inform/base.rb +0 -160
- data/lib/story_teller/model_adapter.rb +0 -132
data/lib/story_teller/helpers.rb
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
# lib/story_teller/helpers.rb
|
|
1
2
|
# encoding: utf-8
|
|
2
3
|
# frozen_string_literal: false
|
|
3
4
|
|
|
4
|
-
# Copyright Nels Nelson 2008-
|
|
5
|
+
# Copyright Nels Nelson 2008-2026 but freely usable (see license)
|
|
5
6
|
#
|
|
6
7
|
# This file is part of StoryTeller.
|
|
7
8
|
#
|
|
@@ -138,11 +139,14 @@ end
|
|
|
138
139
|
module Inform
|
|
139
140
|
# The ObjectHelpers module functionality
|
|
140
141
|
module ObjectHelpers
|
|
142
|
+
# rubocop: disable Style/CaseEquality
|
|
141
143
|
def object?(obj = self)
|
|
142
|
-
Inform::Object === obj
|
|
144
|
+
defined?(Inform::Ephemeral::Object) && Inform::Ephemeral::Object === obj ||
|
|
145
|
+
defined?(Inform::Object) && Inform::Object === obj
|
|
143
146
|
end
|
|
147
|
+
# rubocop: enable Style/CaseEquality
|
|
144
148
|
|
|
145
|
-
def
|
|
149
|
+
def ephemeral?(obj = self)
|
|
146
150
|
defined?(Inform::Ephemeral::Object) && obj.is_a?(Inform::Ephemeral::Object)
|
|
147
151
|
end
|
|
148
152
|
end
|
|
@@ -156,7 +160,7 @@ module Inform
|
|
|
156
160
|
false
|
|
157
161
|
end
|
|
158
162
|
|
|
159
|
-
def
|
|
163
|
+
def ephemeral?
|
|
160
164
|
false
|
|
161
165
|
end
|
|
162
166
|
|
data/lib/story_teller/history.rb
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
# lib/story_teller/inflector.rb
|
|
1
2
|
# encoding: utf-8
|
|
2
3
|
# frozen_string_literal: false
|
|
3
4
|
|
|
4
|
-
# Copyright (c)
|
|
5
|
+
# Copyright (c) David Heinemeier Hansson
|
|
5
6
|
|
|
6
7
|
# Permission is hereby granted, free of charge, to any person obtaining
|
|
7
8
|
# a copy of this software and associated documentation files (the
|
|
@@ -31,6 +32,8 @@
|
|
|
31
32
|
# The StoryTeller module
|
|
32
33
|
module StoryTeller
|
|
33
34
|
# The Inflector module
|
|
35
|
+
# Mostly adapted from:
|
|
36
|
+
# https://github.com/rails/rails/blob/main/activesupport/lib/active_support/inflections.rb
|
|
34
37
|
module Inflector
|
|
35
38
|
# The Inflections class
|
|
36
39
|
class Inflections
|
|
@@ -181,7 +184,6 @@ module StoryTeller
|
|
|
181
184
|
inflect.irregular('child', 'children')
|
|
182
185
|
inflect.irregular('man', 'men')
|
|
183
186
|
inflect.irregular('move', 'moves')
|
|
184
|
-
inflect.irregular('glove', 'gloves')
|
|
185
187
|
inflect.irregular('person', 'people')
|
|
186
188
|
inflect.irregular('sex', 'sexes')
|
|
187
189
|
inflect.irregular('zombie', 'zombies')
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
# encoding: utf-8
|
|
3
3
|
# frozen_string_literal: false
|
|
4
4
|
|
|
5
|
-
# Copyright Nels Nelson 2008-
|
|
5
|
+
# Copyright Nels Nelson 2008-2026 but freely usable (see license)
|
|
6
6
|
#
|
|
7
7
|
# This file is part of the StoryTeller.
|
|
8
8
|
#
|
|
@@ -21,17 +21,18 @@
|
|
|
21
21
|
|
|
22
22
|
# Link
|
|
23
23
|
|
|
24
|
-
#
|
|
24
|
+
# module Inform
|
|
25
25
|
module Inform
|
|
26
26
|
# module Ephemeral
|
|
27
27
|
module Ephemeral
|
|
28
28
|
# The Inform::Ephemeral::Link class
|
|
29
|
-
class Link
|
|
29
|
+
class Link
|
|
30
30
|
LinkTemplate = '%<link_name>s -> %<to_name>s [%<to_identity>s]'.freeze
|
|
31
|
-
|
|
31
|
+
attr_accessor :name, :to, :from, :created_at, :modified_at
|
|
32
32
|
|
|
33
33
|
def initialize(properties)
|
|
34
34
|
super()
|
|
35
|
+
before_create
|
|
35
36
|
@name = properties[:name]
|
|
36
37
|
@to = properties[:to]
|
|
37
38
|
@from = properties[:from]
|
|
@@ -39,11 +40,13 @@ module Ephemeral
|
|
|
39
40
|
|
|
40
41
|
def before_create
|
|
41
42
|
self.created_at ||= Time.now
|
|
42
|
-
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def save
|
|
46
|
+
after_save
|
|
43
47
|
end
|
|
44
48
|
|
|
45
49
|
def after_save
|
|
46
|
-
super
|
|
47
50
|
self.modified_at = Time.now.utc
|
|
48
51
|
end
|
|
49
52
|
|
|
@@ -54,14 +57,6 @@ module Ephemeral
|
|
|
54
57
|
def <=>(other)
|
|
55
58
|
self.name <=> other.name
|
|
56
59
|
end
|
|
57
|
-
|
|
58
|
-
def init_with(coder)
|
|
59
|
-
LinkMethods.each do |method_name|
|
|
60
|
-
method_symbol = format(MethodWriterTemplate, method_name: method_name).to_sym
|
|
61
|
-
self.send(method_symbol, coder[method_name]) if self.respond_to? method_symbol
|
|
62
|
-
end
|
|
63
|
-
self
|
|
64
|
-
end
|
|
65
60
|
end
|
|
66
61
|
# class Link
|
|
67
62
|
end
|
|
@@ -71,6 +66,11 @@ end
|
|
|
71
66
|
|
|
72
67
|
# The Inform module
|
|
73
68
|
module Inform
|
|
69
|
+
def link_klass
|
|
70
|
+
Inform::Ephemeral::Link
|
|
71
|
+
end
|
|
72
|
+
module_function :link_klass
|
|
73
|
+
|
|
74
74
|
# The Linkable module
|
|
75
75
|
module Linkable
|
|
76
76
|
def links
|
|
@@ -80,16 +80,29 @@ module Inform
|
|
|
80
80
|
end
|
|
81
81
|
|
|
82
82
|
# rubocop: disable Metrics/AbcSize
|
|
83
|
+
# rubocop: disable Metrics/CyclomaticComplexity
|
|
83
84
|
# rubocop: disable Metrics/MethodLength
|
|
85
|
+
# rubocop: disable Metrics/PerceivedComplexity
|
|
84
86
|
def link(link_name, obj = nil)
|
|
85
|
-
link = Inform
|
|
87
|
+
link = if Inform.link_klass.respond_to?(:first)
|
|
88
|
+
Inform.link_klass.first(name: link_name.to_s, from_id: self.id)
|
|
89
|
+
else
|
|
90
|
+
self.links.find { |l| l.name == link_name.to_s }
|
|
91
|
+
end
|
|
86
92
|
link&.to&.refresh
|
|
87
93
|
return link if obj.nil?
|
|
88
94
|
if link.nil?
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
95
|
+
link = if Inform.link_klass.respond_to?(:find_or_create)
|
|
96
|
+
clauses = { name: link_name.to_s, from_id: self.id, to_id: obj.id }
|
|
97
|
+
Inform.link_klass.find_or_create(**clauses) do |l|
|
|
98
|
+
l.from = self
|
|
99
|
+
l.to = obj
|
|
100
|
+
end
|
|
101
|
+
else
|
|
102
|
+
properties = { name: link_name.to_s, from: self, to: obj }
|
|
103
|
+
Inform::Ephemeral::Link.new(properties).tap do |l|
|
|
104
|
+
self.links << l
|
|
105
|
+
end
|
|
93
106
|
end
|
|
94
107
|
else
|
|
95
108
|
link.to = obj
|
|
@@ -98,40 +111,59 @@ module Inform
|
|
|
98
111
|
link
|
|
99
112
|
end
|
|
100
113
|
# rubocop: enable Metrics/AbcSize
|
|
114
|
+
# rubocop: enable Metrics/CyclomaticComplexity
|
|
101
115
|
# rubocop: enable Metrics/MethodLength
|
|
116
|
+
# rubocop: enable Metrics/PerceivedComplexity
|
|
102
117
|
|
|
103
118
|
def linked?(link_name)
|
|
104
|
-
if Inform
|
|
105
|
-
Inform
|
|
119
|
+
if Inform.link_klass.respond_to?(:filter)
|
|
120
|
+
Inform.link_klass.filter(name: link_name.to_s, from_id: self.id).count > 0
|
|
106
121
|
else
|
|
107
|
-
|
|
122
|
+
self.links.any? { |link| link.name == link_name.to_s && link.from == self }
|
|
108
123
|
end
|
|
109
124
|
end
|
|
110
125
|
|
|
126
|
+
# rubocop: disable Metrics/AbcSize
|
|
111
127
|
def unlink(link_name)
|
|
112
|
-
Inform
|
|
128
|
+
if Inform.link_klass.respond_to?(:first)
|
|
129
|
+
Inform.link_klass.first(name: link_name.to_s, from_id: self.id).destroy&.to
|
|
130
|
+
else
|
|
131
|
+
self.links.delete { |link| link.name == link_name.to_s && link.from == self }
|
|
132
|
+
end
|
|
113
133
|
rescue Sequel::NoExistingObject => e
|
|
114
|
-
log.warn
|
|
115
|
-
log.warn
|
|
134
|
+
log.warn "Error: #{e.message}"
|
|
135
|
+
log.warn "No such link: #{link_name}"
|
|
116
136
|
nil
|
|
117
137
|
end
|
|
138
|
+
# rubocop: enable Metrics/AbcSize
|
|
118
139
|
|
|
119
140
|
def linkto(link_name)
|
|
120
|
-
Inform
|
|
141
|
+
if Inform.link_klass.respond_to?(:first)
|
|
142
|
+
Inform.link_klass.first(name: link_name.to_s, from_id: self.id)&.to&.refresh
|
|
143
|
+
else
|
|
144
|
+
self.links.find { |link| link.name == link_name.to_s && link.from == self }&.to
|
|
145
|
+
end
|
|
121
146
|
end
|
|
122
147
|
|
|
148
|
+
# rubocop: disable Metrics/AbcSize
|
|
123
149
|
def linksfrom(link_name = nil)
|
|
124
|
-
if
|
|
125
|
-
|
|
150
|
+
if Inform.link_klass.respond_to?(:filter)
|
|
151
|
+
if link_name.nil?
|
|
152
|
+
Inform.link_klass.filter(to_id: self.id)
|
|
153
|
+
else
|
|
154
|
+
Inform.link_klass.filter(name: link_name.to_s, to_id: self.id)
|
|
155
|
+
end
|
|
126
156
|
else
|
|
127
|
-
|
|
128
|
-
end
|
|
157
|
+
self.links.select { |link| link.name == link_name.to_s && link.to == self }
|
|
158
|
+
end.map(&:from)
|
|
129
159
|
end
|
|
160
|
+
# rubocop: enable Metrics/AbcSize
|
|
130
161
|
|
|
131
162
|
alias _key? linked?
|
|
132
163
|
alias _get_object linkto
|
|
133
164
|
def _set_object(link_name, obj = nil)
|
|
134
|
-
link(link_name, obj)
|
|
165
|
+
link = link(link_name, obj)
|
|
166
|
+
link.to
|
|
135
167
|
end
|
|
136
168
|
alias _unset_object unlink
|
|
137
169
|
end
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
# lib/story_teller/inform/module.rb
|
|
1
2
|
# encoding: utf-8
|
|
2
3
|
# frozen_string_literal: false
|
|
3
4
|
|
|
4
|
-
# Copyright Nels Nelson 2008-
|
|
5
|
+
# Copyright Nels Nelson 2008-2026 but freely usable (see license)
|
|
5
6
|
#
|
|
6
7
|
# This file is part of StoryTeller.
|
|
7
8
|
#
|
|
@@ -20,12 +21,12 @@
|
|
|
20
21
|
|
|
21
22
|
# Module
|
|
22
23
|
|
|
23
|
-
#
|
|
24
|
+
# module Inform
|
|
24
25
|
module Inform
|
|
25
26
|
# module Ephemeral
|
|
26
27
|
module Ephemeral
|
|
27
|
-
#
|
|
28
|
-
class Module
|
|
28
|
+
# class Module
|
|
29
|
+
class Module
|
|
29
30
|
def to_s
|
|
30
31
|
name
|
|
31
32
|
end
|
|
@@ -81,7 +82,7 @@ module Inform
|
|
|
81
82
|
# module Ephemeral
|
|
82
83
|
module Ephemeral
|
|
83
84
|
# The Inform::Ephemeral::Modularized class
|
|
84
|
-
class Modularized
|
|
85
|
+
class Modularized; end
|
|
85
86
|
end
|
|
86
87
|
end
|
|
87
88
|
# module Inform
|