inform-runtime 1.0.4 → 1.2.0

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.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -12
  3. data/Rakefile +26 -16
  4. data/lib/{runtime → story_teller}/articles.rb +14 -10
  5. data/lib/{runtime → story_teller}/builtins.rb +50 -22
  6. data/lib/{runtime → story_teller}/color.rb +8 -8
  7. data/lib/{runtime → story_teller}/command.rb +26 -28
  8. data/lib/{runtime → story_teller}/context.rb +23 -24
  9. data/lib/story_teller/core.rb +38 -0
  10. data/lib/{runtime → story_teller}/daemon.rb +35 -36
  11. data/lib/story_teller/engine.rb +151 -0
  12. data/lib/story_teller/ephemeral_adapter.rb +42 -0
  13. data/lib/{runtime → story_teller}/events.rb +8 -9
  14. data/lib/{runtime → story_teller}/experimental/handler_dsl.rb +7 -18
  15. data/lib/story_teller/experimental/reverse_engineer_class.rb +37 -0
  16. data/lib/{runtime → story_teller}/grammar_parser.rb +24 -40
  17. data/lib/{runtime → story_teller}/helpers.rb +21 -7
  18. data/lib/{runtime → story_teller}/history.rb +5 -5
  19. data/lib/{runtime → story_teller}/inflector.rb +4 -5
  20. data/lib/story_teller/inform/base.rb +160 -0
  21. data/lib/{runtime → story_teller/inform/ephemeral}/link.rb +27 -45
  22. data/lib/{runtime → story_teller/inform/ephemeral}/module.rb +17 -58
  23. data/lib/story_teller/inform/ephemeral/object.rb +329 -0
  24. data/lib/{runtime → story_teller/inform/ephemeral}/tag.rb +54 -81
  25. data/lib/story_teller/inform/models.rb +25 -0
  26. data/lib/{runtime → story_teller}/io.rb +10 -10
  27. data/lib/{runtime → story_teller}/kernel.rb +21 -31
  28. data/lib/story_teller/library/bootstrap.rb +66 -0
  29. data/lib/story_teller/library/declarations.rb +53 -0
  30. data/lib/story_teller/library/directives.rb +91 -0
  31. data/lib/story_teller/library/loader.rb +104 -0
  32. data/lib/story_teller/library/location.rb +73 -0
  33. data/lib/{runtime → story_teller}/library.rb +27 -12
  34. data/lib/{runtime → story_teller}/logging.rb +47 -24
  35. data/lib/{runtime → story_teller}/mixins.rb +6 -6
  36. data/lib/story_teller/model_adapter.rb +132 -0
  37. data/lib/{runtime → story_teller}/plurals.rb +11 -11
  38. data/lib/{runtime → story_teller}/prototype.rb +11 -10
  39. data/lib/{runtime → story_teller}/publication.rb +9 -9
  40. data/lib/{runtime → story_teller}/session.rb +6 -8
  41. data/lib/{runtime → story_teller}/stdlib.rb +13 -11
  42. data/lib/{runtime → story_teller}/subscription.rb +8 -8
  43. data/lib/{runtime → story_teller}/tree.rb +6 -6
  44. data/lib/{runtime → story_teller}/version.rb +16 -6
  45. data/lib/story_teller/world_tree.rb +54 -0
  46. data/lib/story_teller.rb +26 -0
  47. metadata +59 -99
  48. data/config/database.yml +0 -37
  49. data/exe/inform.rb +0 -6
  50. data/game/config.yml +0 -5
  51. data/game/example.inf +0 -76
  52. data/game/example.rb +0 -90
  53. data/game/forms/example_form.rb +0 -2
  54. data/game/grammar/game_grammar.inf.rb +0 -11
  55. data/game/languages/english.rb +0 -2
  56. data/game/models/example_model.rb +0 -2
  57. data/game/modules/example_module.rb +0 -9
  58. data/game/rules/example_state.rb +0 -2
  59. data/game/scripts/example_script.rb +0 -2
  60. data/game/topics/example_topic.rb +0 -2
  61. data/game/verbs/game_verbs.rb +0 -15
  62. data/game/verbs/metaverbs.rb +0 -2028
  63. data/lib/runtime/config.rb +0 -48
  64. data/lib/runtime/database.rb +0 -500
  65. data/lib/runtime/game.rb +0 -74
  66. data/lib/runtime/game_loader.rb +0 -132
  67. data/lib/runtime/library_loader.rb +0 -135
  68. data/lib/runtime/object.rb +0 -761
  69. data/lib/runtime/options.rb +0 -104
  70. data/lib/runtime/persistence.rb +0 -292
  71. data/lib/runtime/runtime.rb +0 -321
  72. data/lib/runtime/world_tree.rb +0 -69
  73. data/lib/runtime.rb +0 -35
@@ -1,24 +1,22 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: false
3
3
 
4
- # Copyright Nels Nelson 2008-2023 but freely usable (see license)
4
+ # Copyright Nels Nelson 2008-2025 but freely usable (see license)
5
5
  #
6
- # This file is part of the Inform Runtime.
6
+ # This file is part of StoryTeller.
7
7
  #
8
- # The Inform Runtime is free software: you can redistribute it and/or
8
+ # StoryTeller is free software: you can redistribute it and/or
9
9
  # modify it under the terms of the GNU General Public License as published
10
10
  # by the Free Software Foundation, either version 3 of the License, or
11
11
  # (at your option) any later version.
12
12
  #
13
- # The Inform Runtime is distributed in the hope that it will be useful,
13
+ # StoryTeller is distributed in the hope that it will be useful,
14
14
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
15
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
16
  # GNU General Public License for more details.
17
17
  #
18
18
  # You should have received a copy of the GNU General Public License
19
- # along with the Inform Runtime. If not, see <http://www.gnu.org/licenses/>.
20
-
21
- require 'set'
19
+ # along with StoryTeller. If not, see <http://www.gnu.org/licenses/>.
22
20
 
23
21
  # In-file Grammar support implementation follows.
24
22
  #
@@ -102,7 +100,7 @@ module Inform
102
100
  ''
103
101
  end +
104
102
  map { |verb| "'#{verb}'" }.join(SpaceString) + Newline +
105
- grammars.map(&:to_s).join(Newline)
103
+ grammars.join(Newline)
106
104
  end
107
105
  alias to_str to_s
108
106
 
@@ -122,7 +120,7 @@ module Inform
122
120
  concat(symbolize_grammar(grammar)) unless grammar.empty?
123
121
  push(:end)
124
122
  @action = action
125
- @expected_tokens = grammar.map { |a| a =~ CustomScopePattern ? a.to_s.split('=').first.to_sym : a }
123
+ @expected_tokens = grammar.map { |a| CustomScopePattern.match?(a) ? a.to_s.split('=').first.to_sym : a }
126
124
  @reverse = reverse.nil? ? false : reverse
127
125
  @source = source
128
126
  end
@@ -251,26 +249,10 @@ module Inform
251
249
  "(#{@file}):#{@line}: token error, unexpected '#{@found}', expecting '#{@expected}'"
252
250
  end
253
251
  end
252
+ end
254
253
 
255
- def self.load_grammar(module_name)
256
- Inform::Grammar.load_by_name(module_name)
257
- end
258
-
259
- def self.load_grammar_by_path(module_path)
260
- Inform::Grammar.load_by_path(module_path)
261
- end
262
-
263
- def self.unload_grammars!
264
- log.debug "Unloading all grammars"
265
- Inform::Grammar::Verbs.clear
266
- end
267
-
268
- def self.prime_dictionary
269
- Inform::Object.select_map(:name).compact.each do |n|
270
- Inform::Dictionary.merge(n.split(/[,\s]+/).grep_v(/[^a-z]/i).map(&:downcase).map(&:to_sym))
271
- end
272
- end
273
-
254
+ # The Inform module
255
+ module Inform
274
256
  ### Grammar
275
257
  module Grammar
276
258
  # The Inform::Grammar::Index class
@@ -368,8 +350,8 @@ module Inform
368
350
  grammar_guess = str + ext
369
351
  guess = File.expand_path(
370
352
  File.join(
371
- Inform::Library.inform_gem_lib_path,
372
- Inform::Runtime.inform_dir_path,
353
+ StoryTeller::Library.inform_gem_lib_path,
354
+ StoryTeller::Engine.inform_code_prefix,
373
355
  grammar_guess))
374
356
  return guess if File.exist?(guess)
375
357
  end
@@ -403,6 +385,7 @@ module Inform
403
385
  @block_comment = false
404
386
  end
405
387
 
388
+ # rubocop: disable Metrics/AbcSize
406
389
  # rubocop: disable Metrics/MethodLength
407
390
  def parse_grammar(grammar_module, lines, origin_path: nil, origin_line: 0)
408
391
  line_index = Integer(origin_line || 0)
@@ -411,18 +394,19 @@ module Inform
411
394
  next unless /^\s*[^\#\n]/.match?(line)
412
395
  begin
413
396
  parse(grammar_module, line)
414
- rescue DuplicateVerb => e
415
- e.file = File.basename(origin_path)
397
+ rescue Inform::DuplicateVerb => e
398
+ e.file = File.basename(origin_path) unless origin_path.nil?
416
399
  e.line = line_index
417
400
  log.warn e
418
- rescue UnexpectedToken => e
419
- e.file = File.basename(origin_path)
401
+ rescue Inform::UnexpectedToken => e
402
+ e.file = File.basename(origin_path) unless origin_path.nil?
420
403
  e.line = line_index
421
404
  raise e
422
405
  end
423
406
  end
424
407
  true
425
408
  end
409
+ # rubocop: enable Metrics/AbcSize
426
410
  # rubocop: enable Metrics/MethodLength
427
411
 
428
412
  # rubocop: disable Metrics/AbcSize
@@ -454,13 +438,13 @@ module Inform
454
438
  # tokens.delete_if { |a| !TokenPattern.match?(a) }
455
439
  keys = tokens.map { |a| a[1..-2] }
456
440
  key = synonym ? keys.last : keys.first
457
- log.debug "Loading verb: #{key}"
441
+ log.trace "Loading verb: #{key}"
458
442
  @verb = Inform::Grammar::Verbs.lookup(key)
459
443
  if @verb
460
444
  raise DuplicateVerb.new(key) unless synonym
461
445
  @verb.merge keys
462
446
  else
463
- @verb = Verb.new(keys, source, meta, emote)
447
+ @verb = Inform::Verb.new(keys, source, meta, emote)
464
448
  end
465
449
  keys.each do |k|
466
450
  Inform::Grammar::Verbs[k] = @verb
@@ -480,7 +464,7 @@ module Inform
480
464
  key = keys.first
481
465
  existing_verb = Inform::Grammar::Verbs.lookup(key)
482
466
  if existing_verb.nil?
483
- @verb = Verb.new(keys, source, meta, emote)
467
+ @verb = Inform::Verb.new(keys, source, meta, emote)
484
468
  elsif only.nil?
485
469
  existing_verb.merge(keys)
486
470
  @verb = existing_verb
@@ -493,7 +477,7 @@ module Inform
493
477
  Inform::Grammar::Verbs.delete(existing_key)
494
478
  existing_verb.delete(existing_key)
495
479
  end
496
- @verb = Verb.new(keys, source, meta, emote)
480
+ @verb = Inform::Verb.new(keys, source, meta, emote)
497
481
  @verb.grammars = existing_verb.grammars if replace.nil?
498
482
  keys.each do |new_key|
499
483
  Inform::Grammar::Verbs[new_key] = @verb
@@ -506,7 +490,7 @@ module Inform
506
490
  tokens.shift
507
491
  reverse = false; reverse = true if /reverse/.match?(action)
508
492
  action = action.gsub(/;/, '').split.first.to_sym
509
- grammar = Verb::Grammar.new(tokens, source, action, reverse)
493
+ grammar = Inform::Verb::Grammar.new(tokens, source, action, reverse)
510
494
  @grammars.push(grammar)
511
495
  else
512
496
  unless @verb.nil?
@@ -550,4 +534,4 @@ module Inform
550
534
  end
551
535
  # module Grammar
552
536
  end
553
- # module Inform
537
+ # module StoryTeller
@@ -1,22 +1,22 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: false
3
3
 
4
- # Copyright Nels Nelson 2008-2023 but freely usable (see license)
4
+ # Copyright Nels Nelson 2008-2025 but freely usable (see license)
5
5
  #
6
- # This file is part of the Inform Runtime.
6
+ # This file is part of StoryTeller.
7
7
  #
8
- # The Inform Runtime is free software: you can redistribute it and/or
8
+ # StoryTeller is free software: you can redistribute it and/or
9
9
  # modify it under the terms of the GNU General Public License as published
10
10
  # by the Free Software Foundation, either version 3 of the License, or
11
11
  # (at your option) any later version.
12
12
  #
13
- # The Inform Runtime is distributed in the hope that it will be useful,
13
+ # StoryTeller is distributed in the hope that it will be useful,
14
14
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
15
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
16
  # GNU General Public License for more details.
17
17
  #
18
18
  # You should have received a copy of the GNU General Public License
19
- # along with the Inform Runtime. If not, see <http://www.gnu.org/licenses/>.
19
+ # along with StoryTeller. If not, see <http://www.gnu.org/licenses/>.
20
20
 
21
21
  # Additional mixin methods
22
22
 
@@ -139,15 +139,29 @@ module Inform
139
139
  # The ObjectHelpers module functionality
140
140
  module ObjectHelpers
141
141
  def object?(obj = self)
142
- obj.is_a?(Inform::Object) || obj.is_a?(Inform::System::Object)
142
+ obj.is_a?(Inform::Object)
143
143
  end
144
144
 
145
145
  def sysobj?(obj = self)
146
- obj.is_a?(Inform::System::Object)
146
+ defined?(Inform::Ephemeral::Object) && obj.is_a?(Inform::Ephemeral::Object)
147
147
  end
148
148
  end
149
149
  end
150
150
 
151
+ # # The Inform module
152
+ # module Inform
153
+ # # The ObjectHelpers module functionality
154
+ # module ObjectHelpers
155
+ # def object?(obj = self)
156
+ # obj.is_a?(Inform::Object) || obj.is_a?(Inform::Ephemeral::Object)
157
+ # end
158
+
159
+ # def sysobj?(obj = self)
160
+ # obj.is_a?(Inform::Ephemeral::Object)
161
+ # end
162
+ # end
163
+ # end
164
+
151
165
  # The Inform module
152
166
  module Inform
153
167
  # The NilClassObjectHelpers module functionality
@@ -1,22 +1,22 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: false
3
3
 
4
- # Copyright Nels Nelson 2008-2023 but freely usable (see license)
4
+ # Copyright Nels Nelson 2008-2025 but freely usable (see license)
5
5
  #
6
- # This file is part of the Inform Runtime.
6
+ # This file is part of StoryTeller.
7
7
  #
8
- # The Inform Runtime is free software: you can redistribute it and/or
8
+ # StoryTeller is free software: you can redistribute it and/or
9
9
  # modify it under the terms of the GNU General Public License as published
10
10
  # by the Free Software Foundation, either version 3 of the License, or
11
11
  # (at your option) any later version.
12
12
  #
13
- # The Inform Runtime is distributed in the hope that it will be useful,
13
+ # StoryTeller is distributed in the hope that it will be useful,
14
14
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
15
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
16
  # GNU General Public License for more details.
17
17
  #
18
18
  # You should have received a copy of the GNU General Public License
19
- # along with the Inform Runtime. If not, see <http://www.gnu.org/licenses/>.
19
+ # along with StoryTeller. If not, see <http://www.gnu.org/licenses/>.
20
20
 
21
21
  # The Inform module
22
22
  module Inform
@@ -28,12 +28,10 @@
28
28
 
29
29
  # * http://www.opensource.org/licenses/MIT
30
30
 
31
- # The Inform module
32
- module Inform
31
+ # The StoryTeller module
32
+ module StoryTeller
33
33
  # The Inflector module
34
34
  module Inflector
35
- extend self # rubocop: disable Style/ModuleFunction
36
-
37
35
  # The Inflections class
38
36
  class Inflections
39
37
  @instance = nil
@@ -124,6 +122,7 @@ module Inform
124
122
  return yield Inflections.instance if block_given?
125
123
  Inflections.instance
126
124
  end
125
+ module_function :inflections
127
126
  end
128
127
  # module Inflector
129
128
 
@@ -192,4 +191,4 @@ module Inform
192
191
  # rubocop: enable Metrics/BlockLength
193
192
  # Inflector.inflections do |inflect|
194
193
  end
195
- # module Inform
194
+ # module StoryTeller
@@ -0,0 +1,160 @@
1
+ # lib/story_teller/inform/base.rb
2
+ # encoding: utf-8
3
+ # frozen_string_literal: false
4
+
5
+ # Copyright Nels Nelson 2008-2026 but freely usable (see license)
6
+ #
7
+ # This file is part of StoryTeller.
8
+ #
9
+ # The StoryTeller is free software: you can redistribute it and/or
10
+ # modify it under the terms of the GNU General Public License as published
11
+ # by the Free Software Foundation, either version 3 of the License, or
12
+ # (at your option) any later version.
13
+ #
14
+ # The StoryTeller is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU General Public License
20
+ # along with the StoryTeller. If not, see <http://www.gnu.org/licenses/>.
21
+
22
+ # module Inform
23
+ module Inform
24
+ # module AdapterClassDelegation
25
+ module AdapterClassDelegation
26
+ def delegated_adapter_class
27
+ klass = adapter_class
28
+ klass.equal?(self) ? nil : klass
29
+ rescue NotImplementedError
30
+ nil
31
+ end
32
+
33
+ def ===(other)
34
+ klass = delegated_adapter_class
35
+ super || (!klass.nil? && other.is_a?(klass))
36
+ end
37
+
38
+ def method_missing(method_name, *args, **kwargs, &block)
39
+ klass = delegated_adapter_class
40
+ return klass.public_send(method_name, *args, **kwargs, &block) if !klass.nil? && klass.respond_to?(method_name)
41
+
42
+ super
43
+ end
44
+
45
+ def respond_to_missing?(method_name, include_private = false)
46
+ klass = delegated_adapter_class
47
+ (!klass.nil? && klass.respond_to?(method_name, include_private)) || super
48
+ end
49
+ end
50
+
51
+ # class Object
52
+ class Object
53
+ class << self
54
+ include AdapterClassDelegation
55
+
56
+ def adapter_class
57
+ StoryTeller::ModelAdapter.object_class
58
+ end
59
+
60
+ def new(*args, **kwargs, &block)
61
+ return super unless equal?(Inform::Object)
62
+
63
+ StoryTeller::ModelAdapter.object_class!.new(*args, **kwargs, &block)
64
+ end
65
+
66
+ def build(*args, **kwargs, &block)
67
+ if equal?(Inform::Object)
68
+ StoryTeller::ModelAdapter.object_class!.new(*args, **kwargs, &block)
69
+ else
70
+ super
71
+ end
72
+ end
73
+
74
+ def create(*args, **kwargs, &block)
75
+ if equal?(Inform::Object)
76
+ StoryTeller::ModelAdapter.object_class!.create(*args, **kwargs, &block)
77
+ else
78
+ new(*args, **kwargs, &block)
79
+ end
80
+ end
81
+
82
+ def fetch_or_create_by_name(*args, **kwargs, &block)
83
+ if equal?(Inform::Object)
84
+ StoryTeller::ModelAdapter.object_class!.fetch_or_create_by_name(*args, **kwargs, &block)
85
+ else
86
+ super
87
+ end
88
+ end
89
+
90
+ def all(*args, **kwargs, &block)
91
+ if equal?(Inform::Object)
92
+ StoryTeller::ModelAdapter.object_class!.all(*args, **kwargs, &block)
93
+ else
94
+ super
95
+ end
96
+ end
97
+ end
98
+ end
99
+ # class Object
100
+
101
+ # class Tag
102
+ class Tag
103
+ class << self
104
+ include AdapterClassDelegation
105
+
106
+ def adapter_class
107
+ StoryTeller::ModelAdapter.tag_class
108
+ end
109
+
110
+ def new(*args, &block)
111
+ return super unless equal?(Inform::Tag)
112
+
113
+ StoryTeller::ModelAdapter.tag_class!.new(*args, &block)
114
+ end
115
+ end
116
+ end
117
+
118
+ # class Link
119
+ class Link
120
+ class << self
121
+ include AdapterClassDelegation
122
+
123
+ def adapter_class
124
+ StoryTeller::ModelAdapter.link_class
125
+ end
126
+
127
+ def new(*args, &block)
128
+ return super unless equal?(Inform::Link)
129
+
130
+ StoryTeller::ModelAdapter.link_class!.new(*args, &block)
131
+ end
132
+ end
133
+ end
134
+
135
+ # class Module
136
+ class Module
137
+ class << self
138
+ include AdapterClassDelegation
139
+
140
+ def adapter_class
141
+ StoryTeller::ModelAdapter.module_class
142
+ end
143
+
144
+ def new(*args, &block)
145
+ return super unless equal?(Inform::Module)
146
+
147
+ StoryTeller::ModelAdapter.module_class!.new(*args, &block)
148
+ end
149
+ end
150
+ end
151
+
152
+ # class Tagged
153
+ class Tagged
154
+ end
155
+
156
+ # class Modularized
157
+ class Modularized
158
+ end
159
+ end
160
+ # module Inform
@@ -1,67 +1,41 @@
1
+ # lib/story_teller/link.rb
1
2
  # encoding: utf-8
2
3
  # frozen_string_literal: false
3
4
 
4
- # Copyright Nels Nelson 2008-2023 but freely usable (see license)
5
+ # Copyright Nels Nelson 2008-2025 but freely usable (see license)
5
6
  #
6
- # This file is part of the Inform Runtime.
7
+ # This file is part of the StoryTeller.
7
8
  #
8
- # The Inform Runtime is free software: you can redistribute it and/or
9
+ # The StoryTeller is free software: you can redistribute it and/or
9
10
  # modify it under the terms of the GNU General Public License as published
10
11
  # by the Free Software Foundation, either version 3 of the License, or
11
12
  # (at your option) any later version.
12
13
  #
13
- # The Inform Runtime is distributed in the hope that it will be useful,
14
+ # The StoryTeller is distributed in the hope that it will be useful,
14
15
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
16
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
17
  # GNU General Public License for more details.
17
18
  #
18
19
  # You should have received a copy of the GNU General Public License
19
- # along with the Inform Runtime. If not, see <http://www.gnu.org/licenses/>.
20
+ # along with the StoryTeller. If not, see <http://www.gnu.org/licenses/>.
20
21
 
21
22
  # Link
22
23
 
23
- if defined?(Sequel::Migration)
24
- # The LinkSetup class
25
- class LinkSetup < Sequel::Migration
26
- # rubocop: disable Metrics/MethodLength
27
- def up
28
- # return if table_exists? :link
29
- log.debug "#up"
30
- create_table? :link do
31
- primary_key :id
32
- foreign_key :from_id, :object, on_delete: :cascade
33
- foreign_key :to_id, :object, on_delete: :cascade
34
- index :name
35
- index :created_at
36
-
37
- String :name
38
- DateTime :created_at
39
- DateTime :modified_at
40
- end
41
- end
42
- # rubocop: enable Metrics/MethodLength
43
-
44
- def down
45
- drop_table :link if table_exists? :link
46
- end
47
- end
48
- # class LinkSetup
49
- end
50
- # defined?(Sequel::Migration)
51
-
52
24
  # The Inform module
53
25
  module Inform
54
- # The Inform::Link class
55
- class Link < Sequel::Model
56
- set_primary_key :id
57
- def_column_accessor :created_at, :modified_at
58
- def_column_accessor :name
59
- many_to_one :from, class: Inform::Object, key: :from_id
60
- many_to_one :to, class: Inform::Object, key: :to_id
61
-
26
+ # module Ephemeral
27
+ module Ephemeral
28
+ # The Inform::Ephemeral::Link class
29
+ class Link < Inform::Link
62
30
  LinkTemplate = '%<link_name>s -> %<to_name>s [%<to_identity>s]'.freeze
63
- LinkMethods = %w[from_id to_id].freeze
64
- MethodWriterTemplate = '%<method_name>s='.freeze
31
+ attr_reader :name, :to, :from
32
+
33
+ def initialize(properties)
34
+ super()
35
+ @name = properties[:name]
36
+ @to = properties[:to]
37
+ @from = properties[:from]
38
+ end
65
39
 
66
40
  def before_create
67
41
  self.created_at ||= Time.now
@@ -89,7 +63,11 @@ module Inform
89
63
  self
90
64
  end
91
65
  end
66
+ # class Link
67
+ end
68
+ # module Ephemeral
92
69
  end
70
+ # module Inform
93
71
 
94
72
  # The Inform module
95
73
  module Inform
@@ -123,7 +101,11 @@ module Inform
123
101
  # rubocop: enable Metrics/MethodLength
124
102
 
125
103
  def linked?(link_name)
126
- Inform::Link.filter(name: link_name.to_s, from_id: self.id).count > 0
104
+ if Inform::Link.respond_to?(:filter)
105
+ Inform::Link.filter(name: link_name.to_s, from_id: self.id).count > 0
106
+ else
107
+ !self.links.find(&:link_name).nil?
108
+ end
127
109
  end
128
110
 
129
111
  def unlink(link_name)
@@ -1,57 +1,31 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: false
3
3
 
4
- # Copyright Nels Nelson 2008-2023 but freely usable (see license)
4
+ # Copyright Nels Nelson 2008-2025 but freely usable (see license)
5
5
  #
6
- # This file is part of the Inform Runtime.
6
+ # This file is part of StoryTeller.
7
7
  #
8
- # The Inform Runtime is free software: you can redistribute it and/or
8
+ # StoryTeller is free software: you can redistribute it and/or
9
9
  # modify it under the terms of the GNU General Public License as published
10
10
  # by the Free Software Foundation, either version 3 of the License, or
11
11
  # (at your option) any later version.
12
12
  #
13
- # The Inform Runtime is distributed in the hope that it will be useful,
13
+ # StoryTeller is distributed in the hope that it will be useful,
14
14
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
15
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
16
  # GNU General Public License for more details.
17
17
  #
18
18
  # You should have received a copy of the GNU General Public License
19
- # along with the Inform Runtime. If not, see <http://www.gnu.org/licenses/>.
19
+ # along with StoryTeller. If not, see <http://www.gnu.org/licenses/>.
20
20
 
21
21
  # Module
22
22
 
23
- if defined?(Sequel::Migration)
24
- # The ModuleSetup class
25
- class ModuleSetup < Sequel::Migration
26
- def up
27
- log.debug "#up"
28
- create_table? :module do
29
- primary_key :id
30
- index :name
31
- index :created_at
32
-
33
- String :name, unique: true, null: false
34
- DateTime :created_at
35
- DateTime :modified_at
36
- end
37
- end
38
-
39
- def down
40
- drop_table(:module, cascade: true) if table_exists? :module
41
- end
42
- end
43
- # class ModuleSetup
44
- end
45
- # defined?(Sequel::Migration)
46
-
47
23
  # The Inform module
48
24
  module Inform
49
- # Deine the Inform::Module class
50
- class Module < Sequel::Model
51
- set_primary_key :id
52
- def_column_accessor :created_at, :modified_at
53
- def_column_accessor :name
54
-
25
+ # module Ephemeral
26
+ module Ephemeral
27
+ # The Inform::Module class
28
+ class Module < Inform::Module
55
29
  def to_s
56
30
  name
57
31
  end
@@ -94,36 +68,21 @@ from module a, modularized b where b.module_id = a.id group by a.id, a.name}
94
68
  # rubocop: enable Style/FormatString
95
69
  # rubocop: enable Style/FormatStringToken
96
70
  end
71
+ # class Module
72
+ end
73
+ # module Ephemeral
97
74
  end
98
75
  # module Inform
99
76
 
100
77
  # Modularized
101
78
 
102
- if defined?(Sequel::Migration)
103
- # The ModularizedSetup class
104
- class ModularizedSetup < Sequel::Migration
105
- def up
106
- create_table? :modularized do
107
- primary_key :id
108
- foreign_key :object_id, :object, on_delete: :cascade
109
- foreign_key :module_id, :module, on_delete: :cascade
110
- end
111
- end
112
-
113
- def down
114
- drop_table(:modularized, cascade: true) if table_exists? :modularized
115
- end
116
- end
117
- # class ModularizedSetup
118
- end
119
- # defined?(Sequel::Migration)
120
-
121
79
  # The Inform module
122
80
  module Inform
123
- # The Inform::Modularized class
124
- class Modularized < Sequel::Model
125
- set_primary_key :id
126
- end
81
+ # module Ephemeral
82
+ module Ephemeral
83
+ # The Inform::Ephemeral::Modularized class
84
+ class Modularized < Inform::Modularized; end
85
+ end
127
86
  end
128
87
  # module Inform
129
88