Class: Inform::Link

Inherits:
Sequel::Model show all
Defined in:
lib/runtime/link.rb

Overview

The Inform::Link class

Constant Summary collapse

LinkTemplate =
'%<link_name>s -> %<to_name>s [%<to_identity>s]'.freeze
LinkMethods =
%w[from_id to_id].freeze
MethodWriterTemplate =
'%<method_name>s='.freeze

Instance Method Summary collapse

Methods inherited from Sequel::Model

implicit_table_name

Methods included from InheritanceListener

included

Instance Method Details

#<=>(other) ⇒ Object



80
81
82
# File 'lib/runtime/link.rb', line 80

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

#after_saveObject



71
72
73
74
# File 'lib/runtime/link.rb', line 71

def after_save
  super
  self.modified_at = Time.now.utc
end

#before_createObject



66
67
68
69
# File 'lib/runtime/link.rb', line 66

def before_create
  self.created_at ||= Time.now
  super
end

#init_with(coder) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/runtime/link.rb', line 84

def init_with(coder)
  LinkMethods.each do |method_name|
    method_symbol = format(MethodWriterTemplate, method_name: method_name).to_sym
    self.send(method_symbol, coder[method_name]) if self.respond_to? method_symbol
  end
  self
end

#to_sObject



76
77
78
# File 'lib/runtime/link.rb', line 76

def to_s
  format(LinkTemplate, link_name: name, to_name: to.name, to_identity: to.identity)
end