active_tsv 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/data/nokeys.tsv +3 -0
- data/lib/active_tsv/base.rb +30 -2
- data/lib/active_tsv/errors.rb +1 -0
- data/lib/active_tsv/relation.rb +1 -1
- data/lib/active_tsv/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd70390aab63f668f621f2305a840d60169f6e1e
|
4
|
+
data.tar.gz: dd47ec7b43b36397d701db69aadcedc1166a64a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c200088cb1725b2d2357642b99c4aa2102c0e591c8b2c88a4b9ba7c42b2077f907f059c0c3f9ba238b453f882772d3fdd69a70e6cca61119dff17bcede9ab188
|
7
|
+
data.tar.gz: 2ad08364ab1dd69f2937e6f8b4a54f2a55275da21f900a8e1fffa7ac79ac62d05cb57d75b2b9e24bc8cdc719f06e668b975fee4228e346dcb9a805c8cc0c94ac
|
data/.travis.yml
CHANGED
data/data/nokeys.tsv
ADDED
data/lib/active_tsv/base.rb
CHANGED
@@ -28,6 +28,7 @@ module ActiveTsv
|
|
28
28
|
end
|
29
29
|
|
30
30
|
@column_names = nil
|
31
|
+
@custom_column_name = false
|
31
32
|
@table_path = path
|
32
33
|
column_names.each do |k|
|
33
34
|
define_method(k) { @attrs[k] }
|
@@ -48,7 +49,24 @@ module ActiveTsv
|
|
48
49
|
end
|
49
50
|
|
50
51
|
def column_names
|
51
|
-
@column_names ||=
|
52
|
+
@column_names ||= begin
|
53
|
+
@custom_column_name = false
|
54
|
+
open { |csv| csv.gets }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def column_names=(names)
|
59
|
+
@custom_column_name = true
|
60
|
+
column_names = names.map(&:to_s)
|
61
|
+
column_names.each do |k|
|
62
|
+
define_method(k) { @attrs[k] }
|
63
|
+
define_method("#{k}=") { |v| @attrs[k] = v }
|
64
|
+
end
|
65
|
+
@column_names = column_names
|
66
|
+
end
|
67
|
+
|
68
|
+
def custom_column_name?
|
69
|
+
@custom_column_name
|
52
70
|
end
|
53
71
|
|
54
72
|
def primary_key
|
@@ -76,7 +94,17 @@ module ActiveTsv
|
|
76
94
|
def initialize(attrs = {})
|
77
95
|
case attrs
|
78
96
|
when Hash
|
79
|
-
|
97
|
+
h = {}
|
98
|
+
self.class.column_names.each do |name|
|
99
|
+
h[name] = nil
|
100
|
+
end
|
101
|
+
attrs.each do |name, v|
|
102
|
+
unless respond_to?("#{name}=")
|
103
|
+
raise UnknownAttributeError, "unknown attribute '#{name}' for #{self.class}."
|
104
|
+
end
|
105
|
+
h[name.to_s] = v
|
106
|
+
end
|
107
|
+
@attrs = h
|
80
108
|
when Array
|
81
109
|
@attrs = self.class.column_names.zip(attrs).to_h
|
82
110
|
else
|
data/lib/active_tsv/errors.rb
CHANGED
data/lib/active_tsv/relation.rb
CHANGED
@@ -198,7 +198,7 @@ module ActiveTsv
|
|
198
198
|
|
199
199
|
key_to_value_index = @model.column_names.each_with_index.to_h
|
200
200
|
@model.open do |csv|
|
201
|
-
csv.gets
|
201
|
+
csv.gets if !@model.custom_column_name?
|
202
202
|
csv.each do |value|
|
203
203
|
yield value if @where_values.all? do |cond|
|
204
204
|
case cond
|
data/lib/active_tsv/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_tsv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- data/books.tsv
|
88
88
|
- data/names.tsv
|
89
89
|
- data/nicknames.tsv
|
90
|
+
- data/nokeys.tsv
|
90
91
|
- data/passwords.tsv
|
91
92
|
- data/user_books.tsv
|
92
93
|
- data/users.csv
|