hiiro 0.1.326 → 0.1.327
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/bin/h-branch +11 -1
- data/bin/h-link +5 -19
- data/bin/h-tags +18 -0
- data/lib/hiiro/tags.rb +73 -48
- data/lib/hiiro/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5b59bf7d57b8661136281afe559d7fb3afd1e7fa090483f556074be405aa69a4
|
|
4
|
+
data.tar.gz: '08e9ff25437d1991c0f75007cabeb0bc993fb8e8a98225538fbd39b9e0baf71d'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2e4cc0a15c2216ebd6f4a3159b72b1a9cb9b2beda9fb47f0aede821c4024f8f95743838df19d0068edd5e0b1ec37001e5d4f68bbce4f3aa09fa15383376b9066
|
|
7
|
+
data.tar.gz: 103b722f78dbd84c6680ba171f3c60c69cf3848017b79ccb42a1e30f6eab10645cc1ace1e6edbec1280199dad00e1f55dc22f0e4f19f20990ff3723fcbe233fd
|
data/CHANGELOG.md
CHANGED
data/bin/h-branch
CHANGED
|
@@ -245,7 +245,17 @@ Hiiro.run(*ARGV) do
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
247
|
add_subcmd(:edit) { edit_files(__FILE__) }
|
|
248
|
-
add_subcmd(:save)
|
|
248
|
+
add_subcmd(:save) do |*save_args|
|
|
249
|
+
opts = Hiiro::Options.parse(save_args) { option(:tag, short: 't', desc: 'Tag to apply (repeatable)', multi: true) }
|
|
250
|
+
branch_name = opts.args.first
|
|
251
|
+
manager.save(branch_name)
|
|
252
|
+
tags = Array(opts.tag).reject(&:empty?)
|
|
253
|
+
if tags.any?
|
|
254
|
+
branch_name ||= git.branch
|
|
255
|
+
tag_store.add(branch_name, *tags)
|
|
256
|
+
puts "Tagged with: #{tags.join(', ')}"
|
|
257
|
+
end
|
|
258
|
+
end
|
|
249
259
|
|
|
250
260
|
add_subcmd(:saved) do |*saved_args|
|
|
251
261
|
data = manager.load_data
|
data/bin/h-link
CHANGED
|
@@ -528,25 +528,11 @@ Hiiro.run(*ARGV, plugins: [Pins], links_file: lm.links_file) do
|
|
|
528
528
|
end
|
|
529
529
|
|
|
530
530
|
add_subcmd(:tags) do |*tag_args|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
puts "#{tag_name}:"
|
|
537
|
-
links.each { |link| puts " #{link.display_string(exclude_tags: [tag_name])}" }
|
|
538
|
-
end
|
|
539
|
-
else
|
|
540
|
-
all_known.select{ |tag|
|
|
541
|
-
tag_args.any?{ |arg|
|
|
542
|
-
tag.start_with?(arg)
|
|
543
|
-
}
|
|
544
|
-
}.map do |tag|
|
|
545
|
-
links = Hiiro::Tag.tagged_by_type(tag_name, 'Link')
|
|
546
|
-
puts "#{tag_name}:"
|
|
547
|
-
links.each { |link| puts " #{link.display_string(exclude_tags: [tag_name])}" }
|
|
548
|
-
end
|
|
549
|
-
end
|
|
531
|
+
Hiiro::Tag.search(tag_args, type: 'Link').each do |tag|
|
|
532
|
+
links = Hiiro::Tag.tagged_by_type(tag, 'Link')
|
|
533
|
+
puts "#{tag}:"
|
|
534
|
+
links.each { |link| puts " #{link.display_string(exclude_tags: [tag])}" }
|
|
535
|
+
end.empty? && puts("No tags found!")
|
|
550
536
|
end
|
|
551
537
|
|
|
552
538
|
add_subcmd(:paste) do |*paste_args|
|
data/bin/h-tags
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'hiiro'
|
|
4
|
+
|
|
5
|
+
Hiiro.run do
|
|
6
|
+
add_subcmd(:tags_by_type) do |*args|
|
|
7
|
+
# use options to determine if we want a tag or the object?
|
|
8
|
+
tags = Hiiro::Tag.tags_by_type(args)
|
|
9
|
+
puts tags
|
|
10
|
+
|
|
11
|
+
tagged = tags.flat_map{|tag|
|
|
12
|
+
Hiiro::Tag.tagged_by_type(tag, args)
|
|
13
|
+
}
|
|
14
|
+
puts tagged
|
|
15
|
+
binding.pry
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
data/lib/hiiro/tags.rb
CHANGED
|
@@ -4,70 +4,95 @@ class Hiiro
|
|
|
4
4
|
class Tag < Sequel::Model(:tags)
|
|
5
5
|
Hiiro::DB.register(self)
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
class << self
|
|
8
|
+
def create_table!(db)
|
|
9
|
+
db.create_table?(:tags) do
|
|
10
|
+
primary_key :id
|
|
11
|
+
String :name, null: false # tag value, e.g. "oncall"
|
|
12
|
+
String :taggable_type, null: false # e.g. "Branch", "PinnedPr", "Task"
|
|
13
|
+
String :taggable_id, null: false # string id of tagged object
|
|
14
|
+
String :created_at
|
|
15
|
+
unique [:name, :taggable_type, :taggable_id]
|
|
16
|
+
end
|
|
15
17
|
end
|
|
16
|
-
end
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
end
|
|
19
|
+
def all_tags
|
|
20
|
+
select(:name).distinct
|
|
21
|
+
end
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
end
|
|
23
|
+
def filter(terms, tags=all_tags)
|
|
24
|
+
$stderr.puts("tags class: #{tags.class}")
|
|
25
|
+
$stderr.puts("terms count: #{terms.count}")
|
|
26
|
+
return tags if terms.empty?
|
|
28
27
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
where(name: tag_name.to_s)
|
|
32
|
-
end
|
|
28
|
+
conditions = terms.map{|q| Sequel.like(:name, "%#{q}%") }
|
|
29
|
+
tags.where(Sequel.|(*conditions)).all
|
|
33
30
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
# tags.select{|tag|
|
|
32
|
+
# terms.any?{|term| tag.start_with?(term) }
|
|
33
|
+
# }
|
|
34
|
+
end
|
|
37
35
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
end
|
|
36
|
+
def search(*terms, type: nil)
|
|
37
|
+
filter(terms.flatten, tags_by_type(type))
|
|
38
|
+
end
|
|
42
39
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
# Returns all Tag rows for a given object
|
|
41
|
+
def tags_by_type(type=nil)
|
|
42
|
+
return all_tags if type.nil?
|
|
43
|
+
|
|
44
|
+
where(taggable_type: type).select(:name).distinct.map(&:name).sort
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Returns all Tag rows for a given object
|
|
48
|
+
def for(obj)
|
|
49
|
+
t = obj.class.name.split('::').last
|
|
50
|
+
where(taggable_type: t, taggable_id: obj.id.to_s)
|
|
52
51
|
end
|
|
53
|
-
end
|
|
54
52
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
name:
|
|
62
|
-
|
|
53
|
+
# Returns all Tag rows with a given name
|
|
54
|
+
def named(tag_name)
|
|
55
|
+
where(name: tag_name.to_s)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def tagged_by_type(tag, type)
|
|
59
|
+
where(name: tag, taggable_type: type).map(&:taggable)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
# Returns all tagged objects across all types for a tag name
|
|
63
|
+
def everything_tagged(tag_name)
|
|
64
|
+
named(tag_name).map(&:taggable).compact
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# Idempotent tag assignment
|
|
68
|
+
def tag!(obj, *tag_names)
|
|
69
|
+
t = obj.class.name.split('::').last
|
|
70
|
+
tag_names.each do |name|
|
|
71
|
+
find_or_create(
|
|
72
|
+
name: name.to_s,
|
|
73
|
+
taggable_type: t,
|
|
74
|
+
taggable_id: obj.id.to_s
|
|
75
|
+
) { |tag| tag.created_at = Time.now.iso8601 }
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Remove tags from an object
|
|
80
|
+
def untag!(obj, *tag_names)
|
|
81
|
+
t = obj.class.name.split('::').last
|
|
82
|
+
where(
|
|
83
|
+
taggable_type: t,
|
|
84
|
+
taggable_id: obj.id.to_s,
|
|
85
|
+
name: tag_names.map(&:to_s)
|
|
86
|
+
).delete
|
|
87
|
+
end
|
|
63
88
|
end
|
|
64
|
-
end
|
|
65
89
|
|
|
66
90
|
# Polymorphic accessor — returns the tagged object
|
|
67
91
|
def taggable
|
|
68
92
|
klass = Hiiro.const_get(taggable_type) rescue nil
|
|
69
93
|
klass&.[](taggable_id)
|
|
70
94
|
end
|
|
95
|
+
end
|
|
71
96
|
|
|
72
97
|
# Shared tag store, keyed by namespace (e.g. :branch, :task).
|
|
73
98
|
# Delegates to Hiiro::Tag internally; maintains tags.yml as a backup.
|
data/lib/hiiro/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hiiro
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.327
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Joshua Toyota
|
|
@@ -151,6 +151,7 @@ files:
|
|
|
151
151
|
- bin/h-session
|
|
152
152
|
- bin/h-sha
|
|
153
153
|
- bin/h-sparse
|
|
154
|
+
- bin/h-tags
|
|
154
155
|
- bin/h-title
|
|
155
156
|
- bin/h-todo
|
|
156
157
|
- bin/h-window
|