yinx_sql 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9ebcfe753667d3e0f0cd31483817cbbb3b54c2da
4
+ data.tar.gz: 48e0b15a5b3c1f7e270666e5c5d29eca6ae112fe
5
+ SHA512:
6
+ metadata.gz: 82f7b69aebc38044849035383b02f581d793edec2c090b0eeaee88467590194370ba29df04b58afa8b24186f0330699ccb35caf62c51f4ecd71b0eabba7967e0
7
+ data.tar.gz: bc65059099c0bc7cfd7abd2e4cc07508046a1c8dc4a9200399b0db70b542ba60b255b09c8e55ed12d2b3ca572e48baca2846988e7f15fab96a3d405a1aa15a7d
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.swp
11
+ *.gem
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.14.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in yinx_sql.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 ken
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # YinxSql
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/yinx_sql`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'yinx_sql'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install yinx_sql
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ken/yinx_sql.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "yinx_sql"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,56 @@
1
+ require 'yinx'
2
+ require 'yinx_sql/stack'
3
+ require 'yinx_sql/book'
4
+ require 'yinx_sql/note'
5
+ require 'yinx_sql/tag'
6
+
7
+ module Yinx
8
+ module SQL
9
+ class Batch < ActiveRecord::Base
10
+ has_many :tags, dependent: :destroy
11
+ has_many :stacks, dependent: :destroy
12
+ has_many :books, dependent: :destroy
13
+
14
+ def self.insert notes
15
+ batch = Batch.new
16
+
17
+ stacks = Hash.new do |h, name|
18
+ stack = Stack.new name: name
19
+ batch.stacks << stack
20
+ h[name] = stack
21
+ end
22
+
23
+ books = Hash.new do |h, stack_book|
24
+ b = Book.new(name: stack_book[1])
25
+ batch.books << b
26
+ stacks[stack_book[0]].books << b
27
+ h[stack_book] = b
28
+ end
29
+
30
+ tags = Hash.new do |h, name|
31
+ tag = Tag.new name: name
32
+ batch.tags << tag
33
+ h[name] = tag
34
+ end
35
+
36
+ notes.each do |note|
37
+ n = Note.new(title: note.title,
38
+ content_length: note.contentLength,
39
+ created_at: note.created_at,
40
+ updated_at: note.updated_at)
41
+
42
+ book = books[[note.stack, note.book]]
43
+ book.notes << n
44
+
45
+ note.tags.each do |tag_name|
46
+ tag = tags[tag_name]
47
+ tag.notes << n
48
+ end
49
+ end
50
+
51
+ batch.save
52
+ end
53
+
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,11 @@
1
+ module Yinx
2
+ module SQL
3
+
4
+ class Book < ActiveRecord::Base
5
+ belongs_to :stack
6
+ belongs_to :batch
7
+ has_many :notes
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,25 @@
1
+ module Yinx
2
+ module SQL
3
+ class JsonBatch < ActiveRecord::Base
4
+ def books
5
+ batch.
6
+ map { |note| [note['notebookGuid'], note['book']] }.
7
+ uniq.
8
+ map { |id_name| id_name[1] }
9
+ end
10
+
11
+ def stacks
12
+ batch.
13
+ map { |note| note['stack'] }.
14
+ uniq
15
+ end
16
+
17
+ def tags
18
+ batch.
19
+ map { |note| note['tags'] }.
20
+ flatten.
21
+ uniq
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,10 @@
1
+ module Yinx
2
+ module SQL
3
+
4
+ class Note < ActiveRecord::Base
5
+ belongs_to :book
6
+ has_and_belongs_to_many :tags
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Yinx
2
+ module SQL
3
+
4
+ class Stack < ActiveRecord::Base
5
+ belongs_to :batch
6
+ has_many :books
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Yinx
2
+ module SQL
3
+
4
+ class Tag < ActiveRecord::Base
5
+ belongs_to :batch
6
+ has_and_belongs_to_many :notes
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module Yinx
2
+ module SQL
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
data/lib/yinx_sql.rb ADDED
@@ -0,0 +1,68 @@
1
+ require "yinx_sql/version"
2
+ require 'active_record'
3
+ require 'yinx'
4
+ require 'yinx_sql/batch'
5
+
6
+ module Yinx
7
+ module SQL
8
+
9
+ def self.connect *args
10
+ ActiveRecord::Base.establish_connection *args
11
+ end
12
+
13
+ class Tables < ActiveRecord::Migration
14
+ def up
15
+ create_table :batches do |t|
16
+ t.timestamps
17
+ end
18
+
19
+ create_table :tags do |t|
20
+ t.string :name
21
+ t.belongs_to :batch
22
+ end
23
+
24
+ create_table :stacks do |t|
25
+ t.string :name
26
+ t.belongs_to :batch
27
+ end
28
+
29
+ create_table :books do |t|
30
+ t.string :name
31
+ t.belongs_to :stack
32
+ t.belongs_to :batch
33
+ end
34
+
35
+ create_table :notes do |t|
36
+ t.string :title
37
+ t.integer :content_length
38
+ t.timestamps
39
+ t.belongs_to :book
40
+ end
41
+
42
+ create_table :notes_tags do |t|
43
+ t.belongs_to :note, index: true
44
+ t.belongs_to :tag, index: true
45
+ end
46
+ end
47
+
48
+ def down
49
+ [:notes_tags, :notes, :books, :stacks, :tags, :batches].each do |t|
50
+ drop_table t
51
+ end
52
+ end
53
+ end
54
+
55
+ class Json < ActiveRecord::Migration
56
+ def up
57
+ create_table :json_batches do |t|
58
+ t.jsonb :batch, default: '[]'
59
+ end
60
+ end
61
+
62
+ def down
63
+ drop_table :json_batched
64
+ end
65
+ end
66
+
67
+ end
68
+ end
data/yinx_sql.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'yinx_sql/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "yinx_sql"
8
+ spec.version = Yinx::SQL::VERSION
9
+ spec.authors = ["ken"]
10
+ spec.email = ["block24block@gmail.com"]
11
+
12
+ spec.summary = %q{Store yinx metadata with activerecord}
13
+ spec.homepage = "https://github.com/turnon/yinx_sql"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.14"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest", "~> 5.0"
26
+
27
+ spec.add_dependency "yinx", "= 0.1.3"
28
+ spec.add_dependency "activerecord", "~> 5.0.0"
29
+ spec.add_dependency "pg", "~> 0.19.0"
30
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yinx_sql
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - ken
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-01-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yinx
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 0.1.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: activerecord
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 5.0.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 5.0.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: pg
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.19.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.19.0
97
+ description:
98
+ email:
99
+ - block24block@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - ".travis.yml"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/console
111
+ - bin/setup
112
+ - lib/yinx_sql.rb
113
+ - lib/yinx_sql/batch.rb
114
+ - lib/yinx_sql/book.rb
115
+ - lib/yinx_sql/json_batch.rb
116
+ - lib/yinx_sql/note.rb
117
+ - lib/yinx_sql/stack.rb
118
+ - lib/yinx_sql/tag.rb
119
+ - lib/yinx_sql/version.rb
120
+ - yinx_sql.gemspec
121
+ homepage: https://github.com/turnon/yinx_sql
122
+ licenses:
123
+ - MIT
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.6.8
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Store yinx metadata with activerecord
145
+ test_files: []