Debian Codegraph @

plugin/extract/model/setting.rb

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 module Plugin::Extract
4 def Setting(hash)
5 if hash.is_a? Setting
6 hash
7 else
8 Plugin::Extract::Setting.new(hash)
9 end
10 end
11
12 class Setting < Diva::Model
13 register :extract_setting, name: '抽出タブ'
14
15 field.string :name, required: true
16 field.int :id, required: true
17 field.string :slug, required: true
18 field.has :sources, [:string], required: true
19 field.uri :sound
20 field.bool :popup
21 field.string :order
22 field.uri :icon
23
24 def initialize(hash)
25 hash[:id] ||= Time.now.to_i << 16 | rand(0..0xffff)
26 hash[:slug] ||= "extract_#{hash[:id]}"
27 hash[:sources] ||= []
28 super(hash)
29 end
30
31 def slug
32 self[:slug].to_sym
33 end
34
35 def sources
36 (self[:sources] || []).map(&:to_sym)
37 end
38
39 def order
40 (self[:order] || :modified).to_sym
41 end
42
43 def find_ordering_obj
44 Plugin.collect(:extract_order).find { |o| o.slug == order }
45 end
46
47 def sexp
48 self[:sexp]
49 end
50
51 # 引数のsourceがsourcesに含まれていれば真を返す
52 def using?(source_name)
53 sources.include?(source_name.to_sym)
54 end
55
56 # 更新イベントを発生させる。
57 def notify_update
58 Plugin.call(:extract_tab_update, self)
59 end
60
61 # この抽出タブを消去する。
62 # force: に真を渡すと、確認ダイアログを表示せずに削除する。
63 def delete(force: false)
64 if force
65 Plugin.call(:extract_tab_delete, id)
66 else
67 Plugin.call(:extract_tab_delete_with_confirm, id)
68 end
69 end
70
71 def export_to_userconfig
72 { name: name,
73 id: id,
74 slug: slug,
75 sources: sources,
76 sound: sound ? sound.to_s : nil,
77 popup: popup?,
78 icon: icon ? icon.to_s : nil,
79 order: order,
80 uri: uri.to_s,
81 sexp: self[:sexp]
82 }
83 end
84
85 def path
86 "/#{id}"
87 end
88 end
89 end