calibre-ruby 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: 05cd2bd56b6aedda20cf7984e1c0b87bd207526b
4
- data.tar.gz: ed08b843ce908f42edd76224570df2aa1cc33e67
3
+ metadata.gz: afd2661d0ccf57af8af51f30dda2138d4882ed3b
4
+ data.tar.gz: 3023c261eb8a7fbc6947c3505d2ea52872b3b05f
5
5
  SHA512:
6
- metadata.gz: d6df299c342d974277d7bcd62654024d448f5c2b09faaf1601e84fac24d8a4034858559f4e95b33609de10c6bf1af203d48095e9761614da1a1657a4752dced8
7
- data.tar.gz: f961ceaba98d923c41a226fd902151eb4aed31dcd28433970b73a8c35ec387ad42aa61b191905a2316f9572d71ae68f537a07c7fa9d135c176f391cd7d286b33
6
+ metadata.gz: cee0c325707725cc987ba09f5cee7288819c0ce73b370138ce0ac2f674ba80621e6edec5bc0dcc0276a008773f3858e49fa84634f2148afbe9bc964c4c891f90
7
+ data.tar.gz: dfe5421dcbff8ebeb995e0cd33c5242cdac392a06d76b8d04c5e10dcab8d5fd9232bd4090e675fffe51c7f22e14238efd148da271d7eb5ef9f51462f4c0cacc4
@@ -4,6 +4,13 @@ require 'active_record'
4
4
  require_relative 'calibre/author'
5
5
  require_relative 'calibre/book'
6
6
  require_relative 'calibre/data'
7
+ require_relative 'calibre/comment'
8
+ require_relative 'calibre/identifier'
9
+ require_relative 'calibre/publisher'
10
+ require_relative 'calibre/rating'
11
+ require_relative 'calibre/tag'
12
+ require_relative 'calibre/series'
13
+ require_relative 'calibre/language'
7
14
 
8
15
  module Calibre
9
16
  def self.db=(calibre_db)
@@ -4,8 +4,8 @@ module Calibre
4
4
 
5
5
  has_and_belongs_to_many :books,
6
6
  join_table: 'books_authors_link',
7
- association_foreign_key: 'author',
8
- foreign_key: 'book'
7
+ association_foreign_key: 'book',
8
+ foreign_key: 'author'
9
9
  end
10
10
 
11
11
  class Author < AbstractAuthor; end
@@ -3,11 +3,28 @@ module Calibre
3
3
  # name is the same as the class
4
4
  class AbstractBook < ActiveRecord::Base
5
5
  has_many :data, foreign_key: 'book', class_name: 'Calibre::Data'
6
+ has_many :comments, foreign_key: 'book', class_name: 'Calibre::Comment'
7
+ has_many :identifiers, foreign_key: 'book', class_name: 'Calibre::Identifier'
6
8
  self.table_name = 'books'
7
- has_and_belongs_to_many :authors,
8
- join_table: 'books_authors_link',
9
- association_foreign_key: 'book',
10
- foreign_key: 'author'
9
+
10
+ %w[author publisher rating tag].each do |association|
11
+ has_and_belongs_to_many "#{association}s".to_sym,
12
+ join_table: "books_#{association}s_link",
13
+ association_foreign_key: association,
14
+ foreign_key: 'book'
15
+ end
16
+
17
+ # This association is pluralized
18
+ has_and_belongs_to_many :series,
19
+ join_table: "books_series_link",
20
+ association_foreign_key: 'series',
21
+ foreign_key: 'book'
22
+
23
+ # And this one is weirdly name
24
+ has_and_belongs_to_many :languages,
25
+ join_table: "books_languages_link",
26
+ association_foreign_key: 'lang_code',
27
+ foreign_key: 'book'
11
28
 
12
29
  def cover
13
30
  File.join(path, 'cover.jpg')
@@ -0,0 +1,8 @@
1
+ class Calibre::Comment < ActiveRecord::Base
2
+ belongs_to :reference, foreign_key: 'book', class_name: 'Calibre::Book'
3
+ self.table_name = 'comments'
4
+
5
+ # We alias reference, because the relationship can't clash with the
6
+ # foreign key
7
+ alias :book :reference
8
+ end
@@ -0,0 +1,9 @@
1
+ class Calibre::Identifier < ActiveRecord::Base
2
+ belongs_to :reference, foreign_key: 'book', class_name: 'Calibre::Book'
3
+ self.table_name = 'identifiers'
4
+ self.inheritance_column = 'noop'
5
+
6
+ # We alias reference, because the relationship can't clash with the
7
+ # foreign key
8
+ alias :book :reference
9
+ end
@@ -0,0 +1,12 @@
1
+ module Calibre
2
+ class AbstractLanguage < ActiveRecord::Base
3
+ self.table_name = 'languages'
4
+
5
+ has_and_belongs_to_many :books,
6
+ join_table: 'books_languages_link',
7
+ association_foreign_key: 'book',
8
+ foreign_key: 'lang_code'
9
+ end
10
+
11
+ class Language < AbstractLanguage; end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Calibre
2
+ class AbstractPublisher < ActiveRecord::Base
3
+ self.table_name = 'publishers'
4
+
5
+ has_and_belongs_to_many :books,
6
+ join_table: 'books_publishers_link',
7
+ association_foreign_key: 'book',
8
+ foreign_key: 'publisher'
9
+ end
10
+
11
+ class Publisher < AbstractPublisher; end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Calibre
2
+ class AbstractRating < ActiveRecord::Base
3
+ self.table_name = 'ratings'
4
+
5
+ has_and_belongs_to_many :books,
6
+ join_table: 'books_ratings_link',
7
+ association_foreign_key: 'book',
8
+ foreign_key: 'rating'
9
+ end
10
+
11
+ class Rating < AbstractRating; end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Calibre
2
+ class AbstractSeries < ActiveRecord::Base
3
+ self.table_name = 'series'
4
+
5
+ has_and_belongs_to_many :books,
6
+ join_table: 'books_series_link',
7
+ association_foreign_key: 'book',
8
+ foreign_key: 'series'
9
+ end
10
+
11
+ class Series < AbstractSeries; end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Calibre
2
+ class AbstractTag < ActiveRecord::Base
3
+ self.table_name = 'tags'
4
+
5
+ has_and_belongs_to_many :books,
6
+ join_table: 'books_tags_link',
7
+ association_foreign_key: 'book',
8
+ foreign_key: 'tag'
9
+ end
10
+
11
+ class Tag < AbstractTag; end
12
+ end
@@ -1,3 +1,3 @@
1
1
  module Calibre
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '0.0.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: calibre-ruby
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
  - fauno
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-27 00:00:00.000000000 Z
11
+ date: 2018-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -53,7 +53,14 @@ files:
53
53
  - lib/calibre.rb
54
54
  - lib/calibre/author.rb
55
55
  - lib/calibre/book.rb
56
+ - lib/calibre/comment.rb
56
57
  - lib/calibre/data.rb
58
+ - lib/calibre/identifier.rb
59
+ - lib/calibre/language.rb
60
+ - lib/calibre/publisher.rb
61
+ - lib/calibre/rating.rb
62
+ - lib/calibre/series.rb
63
+ - lib/calibre/tag.rb
57
64
  - lib/calibre/version.rb
58
65
  homepage: https://0xacab.org/partido-interdimensional-pirata/calibre-ruby
59
66
  licenses: