calibre-ruby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 05cd2bd56b6aedda20cf7984e1c0b87bd207526b
4
+ data.tar.gz: ed08b843ce908f42edd76224570df2aa1cc33e67
5
+ SHA512:
6
+ metadata.gz: d6df299c342d974277d7bcd62654024d448f5c2b09faaf1601e84fac24d8a4034858559f4e95b33609de10c6bf1af203d48095e9761614da1a1657a4752dced8
7
+ data.tar.gz: f961ceaba98d923c41a226fd902151eb4aed31dcd28433970b73a8c35ec387ad42aa61b191905a2316f9572d71ae68f537a07c7fa9d135c176f391cd7d286b33
@@ -0,0 +1,3 @@
1
+ Gemfile.lock
2
+ .bundle/
3
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'pry'
7
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 fauno <fauno@partidopirata.com.ar>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a
4
+ copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included
12
+ in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,33 @@
1
+ ActiveRecord for Calibre's book database!
2
+
3
+ # Usage
4
+
5
+ Install:
6
+
7
+ ```ruby
8
+ gem install calibre-ruby
9
+ ```
10
+
11
+ Open database:
12
+
13
+ ```ruby
14
+ require 'calibre'
15
+
16
+ Calibre.db = '/path/to/metadata.db'
17
+ ```
18
+
19
+ Work with models:
20
+
21
+ ```ruby
22
+ # Get all books
23
+ Calibre::Book.all
24
+
25
+ # Get book authors
26
+ Calibre::Book.find(1).authors
27
+
28
+ # Get book files
29
+ Calibre::Book.find(1).data.map(&:path)
30
+
31
+ # Get book cover
32
+ Calibre::Book.find(1).cover
33
+ ```
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'calibre/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = 'calibre-ruby'
8
+ gem.version = Calibre::VERSION
9
+ gem.authors = ['fauno']
10
+ gem.email = ['fauno@partidopirata.com.ar']
11
+ gem.description = %q{This gem provides an ActiveRecord interface to Calibre's book database}
12
+ gem.summary = %q{This gem provides an ActiveRecord interface to Calibre's book database}
13
+ gem.homepage = 'https://0xacab.org/partido-interdimensional-pirata/calibre-ruby'
14
+ gem.license = 'MIT'
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ['lib']
20
+
21
+ gem.add_dependency('activerecord', '~> 5.2.0')
22
+ gem.add_dependency('sqlite3', '~> 1.3.0')
23
+ end
@@ -0,0 +1,13 @@
1
+ require 'sqlite3'
2
+ require 'active_record'
3
+
4
+ require_relative 'calibre/author'
5
+ require_relative 'calibre/book'
6
+ require_relative 'calibre/data'
7
+
8
+ module Calibre
9
+ def self.db=(calibre_db)
10
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3',
11
+ database: calibre_db)
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ module Calibre
2
+ class AbstractAuthor < ActiveRecord::Base
3
+ self.table_name = 'authors'
4
+
5
+ has_and_belongs_to_many :books,
6
+ join_table: 'books_authors_link',
7
+ association_foreign_key: 'author',
8
+ foreign_key: 'book'
9
+ end
10
+
11
+ class Author < AbstractAuthor; end
12
+ end
@@ -0,0 +1,23 @@
1
+ module Calibre
2
+ # We do this to prevent AR to fail miserably because the foreign key
3
+ # name is the same as the class
4
+ class AbstractBook < ActiveRecord::Base
5
+ has_many :data, foreign_key: 'book', class_name: 'Calibre::Data'
6
+ 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'
11
+
12
+ def cover
13
+ File.join(path, 'cover.jpg')
14
+ end
15
+
16
+ def cover?
17
+ has_cover == 1
18
+ end
19
+ end
20
+
21
+ # You can use this :)
22
+ class Book < AbstractBook ; end
23
+ end
@@ -0,0 +1,12 @@
1
+ class Calibre::Data < ActiveRecord::Base
2
+ belongs_to :reference, foreign_key: 'book', class_name: 'Calibre::Book'
3
+ self.table_name = 'data'
4
+
5
+ # We alias reference, because the relationship can't clash with the
6
+ # foreign key
7
+ alias :book :reference
8
+
9
+ def path
10
+ File.join(reference.path, [name,format.downcase].join('.'))
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module Calibre
2
+ VERSION = '0.0.1'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: calibre-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - fauno
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: sqlite3
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.3.0
41
+ description: This gem provides an ActiveRecord interface to Calibre's book database
42
+ email:
43
+ - fauno@partidopirata.com.ar
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE
51
+ - README.md
52
+ - calibre-ruby.gemspec
53
+ - lib/calibre.rb
54
+ - lib/calibre/author.rb
55
+ - lib/calibre/book.rb
56
+ - lib/calibre/data.rb
57
+ - lib/calibre/version.rb
58
+ homepage: https://0xacab.org/partido-interdimensional-pirata/calibre-ruby
59
+ licenses:
60
+ - MIT
61
+ metadata: {}
62
+ post_install_message:
63
+ rdoc_options: []
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 2.5.2
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: This gem provides an ActiveRecord interface to Calibre's book database
82
+ test_files: []