| 1 |
|
| 2 |
require_relative 'model/identity' |
| 3 |
require_relative 'model/memory' |
| 4 |
|
| 5 |
module Mikutter::DivaHacks::Model |
| 6 |
ストを返す。 |
| 7 |
|
| 8 |
|
| 9 |
def links |
| 10 |
@entity ||= self.class.entity_class.new(self) |
| 11 |
end |
| 12 |
alias :entity :links |
| 13 |
end |
| 14 |
|
| 15 |
module Mikutter::DivaHacks::ModelExtend |
| 16 |
extend Gem::Deprecate |
| 17 |
を設定する。 |
| 18 |
グインがこのModelを見つけることができるようになるので、 |
| 19 |
加されたり、設定で背景色が指定できるようになる |
| 20 |
|
| 21 |
|
| 22 |
名前 |
| 23 |
宛先が存在するなら真 |
| 24 |
カウントによって作成できるなら真 |
| 25 |
ラインに表示することができる |
| 26 |
def register(new_slug, |
| 27 |
name: new_slug.to_s, |
| 28 |
reply: true, |
| 29 |
myself: true, |
| 30 |
timeline: false |
| 31 |
) |
| 32 |
@slug = new_slug.to_sym |
| 33 |
spec = @spec = Diva::ModelSpec.new(@slug, |
| 34 |
name.to_s.freeze, |
| 35 |
!!reply, |
| 36 |
!!myself, |
| 37 |
!!timeline |
| 38 |
).freeze |
| 39 |
plugin do |
| 40 |
filter_retrievers do |retrievers| |
| 41 |
retrievers << spec |
| 42 |
[retrievers] |
| 43 |
end |
| 44 |
end |
| 45 |
end |
| 46 |
|
| 47 |
def plugin(&block) |
| 48 |
if not @slug |
| 49 |
raise Diva::DivaError, "`#{self}'.slug is not set." |
| 50 |
end |
| 51 |
Plugin.create(:"retriever_model_#{@slug}", &block) |
| 52 |
end |
| 53 |
|
| 54 |
を設定する。 |
| 55 |
|
| 56 |
するEntityクラス |
| 57 |
|
| 58 |
されている)Entityクラス |
| 59 |
def entity_class(klass=nil) |
| 60 |
if klass |
| 61 |
@entity_class = klass |
| 62 |
else |
| 63 |
@entity_class ||= Diva::Entity::BlankEntity |
| 64 |
end |
| 65 |
end |
| 66 |
|
| 67 |
れば真を返す条件 _condition_ を設定する。 |
| 68 |
のURIをこのModelで取り扱えるということになる |
| 69 |
|
| 70 |
、URIにマッチするもの |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
ースの内容を含んだModelを作って返す |
| 75 |
|
| 76 |
チしたURI |
| 77 |
|
| 78 |
|
| 79 |
を行って取得するなど取得に時間がかかる場合 |
| 80 |
|
| 81 |
できる場合、そのModel |
| 82 |
|
| 83 |
ソースが見つからなかった |
| 84 |
def handle(condition, &block) |
| 85 |
model_slug = self.slug |
| 86 |
plugin do |
| 87 |
if condition.is_a? Regexp |
| 88 |
filter_model_of_uri do |uri, models| |
| 89 |
if condition =~ uri.to_s |
| 90 |
models << model_slug |
| 91 |
end |
| 92 |
[uri, models] |
| 93 |
end |
| 94 |
else |
| 95 |
filter_model_of_uri do |uri, models| |
| 96 |
if condition === uri |
| 97 |
models << model_slug |
| 98 |
end |
| 99 |
[uri, models] |
| 100 |
end |
| 101 |
end |
| 102 |
end |
| 103 |
if block |
| 104 |
define_singleton_method(:find_by_uri, &block) |
| 105 |
end |
| 106 |
end |
| 107 |
|
| 108 |
スタンスがない場合、それを生成して返します。 |
| 109 |
def new_ifnecessary(hash) |
| 110 |
type_strict hash => tcor(self, Hash) |
| 111 |
result_strict(self) do |
| 112 |
case hash |
| 113 |
when self |
| 114 |
hash |
| 115 |
when Hash |
| 116 |
self.new(hash) |
| 117 |
else |
| 118 |
raise ArgumentError.new("incorrect type #{hash.class} #{hash.inspect}") |
| 119 |
end |
| 120 |
end |
| 121 |
end |
| 122 |
|
| 123 |
|
| 124 |
def rewind(args) |
| 125 |
type_strict args => Hash |
| 126 |
result_strict(:merge){ new_ifnecessary(args) }.merge(args) |
| 127 |
end |
| 128 |
|
| 129 |
|
| 130 |
end |
| 131 |
|
| 132 |
module Diva |
| 133 |
class Model |
| 134 |
extend Mikutter::DivaHacks::ModelExtend |
| 135 |
include Mikutter::DivaHacks::Model |
| 136 |
end |
| 137 |
|
| 138 |
RetrieverError = DivaError |
| 139 |
|
| 140 |
deprecate_constant :RetrieverError |
| 141 |
end |