| 1 |
|
| 2 |
|
| 3 |
require_relative 'error' |
| 4 |
|
| 5 |
Plugin.create(:current_world) do |
| 6 |
カウントに対応するModelを返すフィルタ。 |
| 7 |
filter_world_current do |result| |
| 8 |
if result |
| 9 |
[result] |
| 10 |
else |
| 11 |
[current_world] |
| 12 |
end |
| 13 |
end |
| 14 |
|
| 15 |
ントを _new_ に変更する |
| 16 |
on_world_change_current do |new| |
| 17 |
if self.current_world != new |
| 18 |
self.current_world = new |
| 19 |
Plugin.call(:primary_service_changed, current_world) |
| 20 |
end |
| 21 |
rescue Plugin::CurrentWorld::WorldNotfoundError |
| 22 |
activity :system, _('アカウントを存在しないアカウント(%{uri})に切り替えようとしました') % {uri: new&.uri || 'nil'}, |
| 23 |
description: _('アカウントを切り替えようとしましたが、切り替えようとしたアカウントは存在しませんでした。') + "\n\n" + |
| 24 |
_("切り替え先のアカウント:\n%{uri}") % {uri: new&.uri || 'nil'} + "\n\n" + |
| 25 |
_('現在存在するアカウント:') + "\n" + |
| 26 |
Plugin.collect(:worlds).map{|w| "#{w.slug} (#{w.uri})" }.to_a.join("\n") + "\n\n" + |
| 27 |
_('%{world_class}#uri を定義することでこのエラーを回避できます。詳しくは %{see} を参照してください') % {world_class: new.class, see: 'https://dev.mikutter.hachune.net/issues/1231'} |
| 28 |
end |
| 29 |
|
| 30 |
れているアカウントを返す |
| 31 |
|
| 32 |
トアカウント |
| 33 |
def current_world |
| 34 |
@current ||= Plugin.collect(:worlds).first |
| 35 |
end |
| 36 |
|
| 37 |
ントを _new_ に変更する。 |
| 38 |
|
| 39 |
|
| 40 |
カウント(Diva::Model)。 |
| 41 |
ちのいずれかでなければならない。 |
| 42 |
|
| 43 |
レントアカウント |
| 44 |
|
| 45 |
ウントが渡された場合 |
| 46 |
def current_world=(new) |
| 47 |
raise Plugin::CurrentWorld::WorldNotfoundError unless Plugin.collect(:worlds).include?(new) |
| 48 |
@current = new |
| 49 |
end |
| 50 |
|
| 51 |
end |