taggata 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2d7713cd81be332797275ebd869ea39818c825a8
4
- data.tar.gz: 138c4eb01a7c07cad98c8522463474d912ab7023
3
+ metadata.gz: af1fd56a3c40bf5cae4dd502103e294280763987
4
+ data.tar.gz: f8f7b604307f9ce1402a5b73989475be2778ab45
5
5
  SHA512:
6
- metadata.gz: 37a36288180cb07f9ba8889b77c2b3d54ef5ce6cffcba14d970caa6f4322a7410cd577427db3d76f5f13f21d4cbad44334b8c0d7d772999bcfb8c9870c47aecb
7
- data.tar.gz: 6ec36c4c738c0265910a200428c6cdec2ccf7468cf2363677446c9ee7d37caed6ddba901a59c2106511676af136c79c25113ec2dfae15f69b667e97172575659
6
+ metadata.gz: fce98df89bbb25cbe946517853ef9b675b12687071538c246bad6c6ae165697d65ecac7458e997699d2d6668d6a67c9b2d959748fd7e9b56012347c49dec23bd
7
+ data.tar.gz: cc2c1d8091c499072ebc92c0c7616626f96fd2eb83700ac92467126591a10587f31e2ae6efdcbf182be980ff786a350bc7b3c2148d5334577aeed24fb6b440fa
data/bin/taggata CHANGED
@@ -6,6 +6,7 @@ DB = Sequel.connect("sqlite://#{ARGV[0]}")
6
6
  DB.create_table :file_tags do
7
7
  foreign_key :tag_id, :tags
8
8
  foreign_key :file_id, :files
9
+ primary_key [:tag_id, :file_id], :name => :file_tags_pk, :unique => true
9
10
  end unless DB.table_exists? :file_tags
10
11
 
11
12
  Sequel::Model.plugin(:schema)
@@ -29,14 +30,18 @@ when 'tag'
29
30
  result = ::Taggata::Parser::Query.parse(ARGV[2])
30
31
  tag_hash = ::Taggata::Parser::Tag.parse(ARGV[3])
31
32
  result.each do |file|
32
- tag_hash[:del].each { |tag| file.remove_tag tag }
33
- tag_hash[:add].each { |tag| file.add_tag tag }
34
- end
33
+ deletions = tag_hash[:del].map { |tag| [file.id, tag.id] }
34
+ DB[:file_tags].where([:file_id, :tag_id] => deletions).delete
35
+ end.flatten 1
36
+ additions = result.map do |file|
37
+ adds = tag_hash[:add].map { |tag| [file.id, tag.id] }
38
+ in_db = DB[:file_tags].where([:file_id, :tag_id] => adds).map([:file_id, :tag_id])
39
+ (adds - in_db).map { |file_id, tag_id| { :file_id => file_id, :tag_id => tag_id } }
40
+ end.flatten
41
+ DB[:file_tags].multi_insert(additions)
35
42
  when 'remove'
36
43
  files = ::Taggata::Parser::Query.parse(ARGV[2])
37
44
  files.each(&:destroy)
38
45
  when 'count'
39
46
  puts ::Taggata::Parser::Query.parse(ARGV[2]).count
40
- when 'pry'
41
- require 'pry'; binding.pry
42
47
  end
@@ -1,5 +1,3 @@
1
1
  module Taggata
2
2
  MISSING_TAG_NAME = '_MISSING'
3
- DEFAULT_TAG_NAME = 'default'
4
3
  end
5
-
@@ -18,7 +18,7 @@ module Taggata
18
18
  private
19
19
 
20
20
  def self.find_tags(names)
21
- in_db = ::Taggata::Tag.where(:name => names).all
21
+ in_db = ::Taggata::Tag.where(:name => names).map(:name)
22
22
  ::Taggata::Tag
23
23
  .dataset
24
24
  .multi_insert((names - in_db).map { |name| { :name => name } })
data/lib/taggata/tag.rb CHANGED
@@ -7,7 +7,7 @@ module Taggata
7
7
 
8
8
  set_schema do
9
9
  primary_key :id
10
- String :name
10
+ String :name, :unique => true
11
11
  end
12
12
 
13
13
  create_table unless table_exists?
@@ -1,3 +1,3 @@
1
1
  module Taggata
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.2'
3
3
  end
data/taggata.gemspec CHANGED
@@ -27,7 +27,4 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency 'minitest', '~> 5.6.1', '>= 5.6.1'
28
28
  spec.add_development_dependency 'minitest-reporters', '~> 1.0.16', '>= 1.0.16'
29
29
  spec.add_development_dependency 'mocha', '~> 1.1', '>= 1.1.0'
30
- spec.add_development_dependency 'pry', '~> 0.1', '>= 0.0.1'
31
- spec.add_development_dependency 'pry-coolline', '~> 0.1', '>= 0.0.1'
32
-
33
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: taggata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Ruzicka
@@ -138,46 +138,6 @@ dependencies:
138
138
  - - ">="
139
139
  - !ruby/object:Gem::Version
140
140
  version: 1.1.0
141
- - !ruby/object:Gem::Dependency
142
- name: pry
143
- requirement: !ruby/object:Gem::Requirement
144
- requirements:
145
- - - "~>"
146
- - !ruby/object:Gem::Version
147
- version: '0.1'
148
- - - ">="
149
- - !ruby/object:Gem::Version
150
- version: 0.0.1
151
- type: :development
152
- prerelease: false
153
- version_requirements: !ruby/object:Gem::Requirement
154
- requirements:
155
- - - "~>"
156
- - !ruby/object:Gem::Version
157
- version: '0.1'
158
- - - ">="
159
- - !ruby/object:Gem::Version
160
- version: 0.0.1
161
- - !ruby/object:Gem::Dependency
162
- name: pry-coolline
163
- requirement: !ruby/object:Gem::Requirement
164
- requirements:
165
- - - "~>"
166
- - !ruby/object:Gem::Version
167
- version: '0.1'
168
- - - ">="
169
- - !ruby/object:Gem::Version
170
- version: 0.0.1
171
- type: :development
172
- prerelease: false
173
- version_requirements: !ruby/object:Gem::Requirement
174
- requirements:
175
- - - "~>"
176
- - !ruby/object:Gem::Version
177
- version: '0.1'
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- version: 0.0.1
181
141
  description:
182
142
  email:
183
143
  - a.ruzicka@outlook.com