yinx_sql 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f703709951eaeef0cf7a2b115278102d7acea21
4
- data.tar.gz: 48cc8532ab89e5a2546628213bdeab682ff2d583
3
+ metadata.gz: 1fc35c9b4ca3237fff11f3c1ec25ab076dd77f50
4
+ data.tar.gz: 5ea8718c80eda6e7c9d102d0cf4ae101fd247748
5
5
  SHA512:
6
- metadata.gz: 3bb765ecea74beedabe74a1adde08bced30f3cbfb71176079091e30ffe595c8d01d2c7f0407e24f14796a3ea374c736d2235aa5a362ea76922652e13be4894f7
7
- data.tar.gz: be02438d9c453e7866f8dabe1f75eefefb0ef2a9f0d56b089d5b2af4144f98d68c67f9df16bd0c939fcd845b7001e30003aaf224eb4dc2a97c44a47740ab0f12
6
+ metadata.gz: f6a0e458109bf921e989de7e603099839c17e0b702115cbb9fea2e05f09a7a4ce32e3b3887a3deb9abe6acdfc6ee0944f82e748518ce786a74fed13bc5050534
7
+ data.tar.gz: a2d16bc5730fc93ec0655537f72b8d5c2517ba80bf131b0547bd005b16184718aea556f3f5a0172d3aec46bcb7a66e8573ba5d126c5e4a83f7f6e8217fc2a86e
data/lib/yinx_sql.rb CHANGED
@@ -22,22 +22,13 @@ module Yinx
22
22
  t.belongs_to :batch
23
23
  end
24
24
 
25
- create_table :stacks do |t|
26
- t.string :name
27
- t.belongs_to :batch
28
- end
29
-
30
- create_table :books do |t|
31
- t.string :name
32
- t.belongs_to :stack
33
- t.belongs_to :batch
34
- end
35
-
36
25
  create_table :notes do |t|
37
26
  t.string :title
27
+ t.string :book
28
+ t.string :stack
38
29
  t.integer :content_length
39
30
  t.timestamps
40
- t.belongs_to :book
31
+ t.belongs_to :batch
41
32
  end
42
33
 
43
34
  create_table :notes_tags do |t|
@@ -47,7 +38,7 @@ module Yinx
47
38
  end
48
39
 
49
40
  def down
50
- [:notes_tags, :notes, :books, :stacks, :tags, :batches].each do |t|
41
+ [:notes_tags, :notes, :tags, :batches].each do |t|
51
42
  drop_table t
52
43
  end
53
44
  end
@@ -1,6 +1,4 @@
1
1
  require 'yinx'
2
- require 'yinx_sql/stack'
3
- require 'yinx_sql/book'
4
2
  require 'yinx_sql/note'
5
3
  require 'yinx_sql/tag'
6
4
 
@@ -8,25 +6,11 @@ module Yinx
8
6
  module SQL
9
7
  class Batch < ActiveRecord::Base
10
8
  has_many :tags, dependent: :destroy
11
- has_many :stacks, dependent: :destroy
12
- has_many :books, dependent: :destroy
9
+ has_many :notes, dependent: :destroy
13
10
 
14
11
  def self.insert notes
15
12
  batch = Batch.new
16
13
 
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
14
  tags = Hash.new do |h, name|
31
15
  tag = Tag.new name: name
32
16
  batch.tags << tag
@@ -35,12 +19,13 @@ module Yinx
35
19
 
36
20
  notes.each do |note|
37
21
  n = Note.new(title: note.title,
22
+ book: note.book,
23
+ stack: note.stack,
38
24
  content_length: note.contentLength,
39
25
  created_at: note.created_at,
40
26
  updated_at: note.updated_at)
41
27
 
42
- book = books[[note.stack, note.book]]
43
- book.notes << n
28
+ batch.notes << n
44
29
 
45
30
  note.tags.each do |tag_name|
46
31
  tag = tags[tag_name]
@@ -51,6 +36,14 @@ module Yinx
51
36
  batch.save
52
37
  end
53
38
 
39
+ def books
40
+ notes.map(&:stack_book).uniq
41
+ end
42
+
43
+ def stacks
44
+ notes.map{|note| note.stack.nil? ? 'NO_STACK' : note.stack}.uniq
45
+ end
46
+
54
47
  end
55
48
  end
56
49
  end
data/lib/yinx_sql/note.rb CHANGED
@@ -2,8 +2,14 @@ module Yinx
2
2
  module SQL
3
3
 
4
4
  class Note < ActiveRecord::Base
5
- belongs_to :book
5
+ belongs_to :batch
6
6
  has_and_belongs_to_many :tags
7
+
8
+ def stack_book
9
+ st = stack.nil? ? '' : "#{stack}/"
10
+ "#{st}#{book}"
11
+ end
12
+
7
13
  end
8
14
 
9
15
  end
@@ -1,5 +1,5 @@
1
1
  module Yinx
2
2
  module SQL
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
data/yinx_sql.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency "rake", "~> 10.0"
25
25
  spec.add_development_dependency "minitest", "~> 5.0"
26
26
 
27
- spec.add_dependency "yinx", "0.1.4"
27
+ spec.add_dependency "yinx", "~> 0.1.5"
28
28
  spec.add_dependency "activerecord", "~> 5.0.0"
29
29
  spec.add_dependency "pg", "~> 0.19.0"
30
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yinx_sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ken
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-01-29 00:00:00.000000000 Z
11
+ date: 2017-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,16 +56,16 @@ dependencies:
56
56
  name: yinx
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '='
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.1.4
61
+ version: 0.1.5
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '='
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 0.1.4
68
+ version: 0.1.5
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activerecord
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -111,10 +111,8 @@ files:
111
111
  - bin/setup
112
112
  - lib/yinx_sql.rb
113
113
  - lib/yinx_sql/batch.rb
114
- - lib/yinx_sql/book.rb
115
114
  - lib/yinx_sql/json_batch.rb
116
115
  - lib/yinx_sql/note.rb
117
- - lib/yinx_sql/stack.rb
118
116
  - lib/yinx_sql/tag.rb
119
117
  - lib/yinx_sql/version.rb
120
118
  - yinx_sql.gemspec
data/lib/yinx_sql/book.rb DELETED
@@ -1,11 +0,0 @@
1
- module Yinx
2
- module SQL
3
-
4
- class Book < ActiveRecord::Base
5
- belongs_to :stack
6
- belongs_to :batch
7
- has_many :notes, dependent: :destroy
8
- end
9
-
10
- end
11
- end
@@ -1,10 +0,0 @@
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