tableling-rails 0.0.17 → 0.0.18
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tableling-rails/field.rb +2 -2
- data/lib/tableling-rails/settings.rb +7 -7
- data/lib/tableling-rails/{serializer.rb → type_serializer.rb} +1 -1
- data/lib/tableling-rails/version.rb +1 -1
- data/lib/tableling-rails/view.rb +57 -28
- data/spec/dummy/app/models/book.rb +9 -5
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/log/development.log +35 -42
- data/spec/dummy/log/test.log +8 -13
- metadata +9 -3
@@ -69,8 +69,8 @@ module Tableling
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def serialize value
|
72
|
-
|
73
|
-
|
72
|
+
type_serializer = @view.settings.type_serializers.find{ |s| s.match? value }
|
73
|
+
type_serializer ? type_serializer.serialize(value) : value
|
74
74
|
end
|
75
75
|
end
|
76
76
|
end
|
@@ -5,26 +5,26 @@ module Tableling
|
|
5
5
|
|
6
6
|
def initialize parent = nil
|
7
7
|
@parent = parent
|
8
|
-
@
|
8
|
+
@type_serializers = []
|
9
9
|
end
|
10
10
|
|
11
11
|
def configure &block
|
12
12
|
instance_eval &block if block
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
@
|
15
|
+
def serialize_type type, &block
|
16
|
+
@type_serializers << TypeSerializer.new(type, block)
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
(@parent ? @parent.
|
19
|
+
def type_serializers
|
20
|
+
(@parent ? @parent.type_serializers : []) + @type_serializers
|
21
21
|
end
|
22
22
|
|
23
23
|
def dsl
|
24
24
|
m = Module.new do
|
25
25
|
|
26
|
-
def
|
27
|
-
@settings.
|
26
|
+
def serialize_type type, &block
|
27
|
+
@settings.serialize_type type, &block
|
28
28
|
end
|
29
29
|
end
|
30
30
|
m.instance_variable_set :@settings, self
|
data/lib/tableling-rails/view.rb
CHANGED
@@ -2,7 +2,8 @@
|
|
2
2
|
module Tableling
|
3
3
|
|
4
4
|
class View
|
5
|
-
attr_reader :name, :config, :settings, :
|
5
|
+
attr_reader :name, :config, :settings, :fields
|
6
|
+
attr_accessor :base_query, :base_count_query, :quick_search_block, :serialize_record_block, :serialize_response_block
|
6
7
|
|
7
8
|
def initialize name, config, options = {}, &block
|
8
9
|
|
@@ -13,28 +14,16 @@ module Tableling
|
|
13
14
|
@base_count_query = nil
|
14
15
|
|
15
16
|
@settings = Settings.new @config.settings
|
16
|
-
extend @settings.dsl
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
return @fields.find{ |f| f.name.to_s == name.to_s } if @frozen
|
24
|
-
@fields.delete_if{ |f| f.name.to_s == name.to_s }
|
25
|
-
Field.new(name, self, options, &block).tap{ |f| @fields << f }
|
26
|
-
end
|
27
|
-
|
28
|
-
def quick_search &block
|
29
|
-
@quick_search = block
|
30
|
-
end
|
31
|
-
|
32
|
-
def base base_query
|
33
|
-
@base_query = base_query
|
18
|
+
if block
|
19
|
+
dsl = DSL.new self
|
20
|
+
dsl.extend @settings.dsl
|
21
|
+
dsl.instance_eval &block
|
22
|
+
end
|
34
23
|
end
|
35
24
|
|
36
|
-
def
|
37
|
-
@
|
25
|
+
def field name
|
26
|
+
@fields.find{ |f| f.name.to_s == name.to_s }
|
38
27
|
end
|
39
28
|
|
40
29
|
def process options = {}
|
@@ -42,9 +31,9 @@ module Tableling
|
|
42
31
|
q = options[:base] || @base_query
|
43
32
|
cq = options[:base_count] || @base_count_query
|
44
33
|
|
45
|
-
if @
|
46
|
-
q = @
|
47
|
-
cq = @
|
34
|
+
if @quick_search_block and options[:quickSearch].present?
|
35
|
+
q = @quick_search_block.call q, options[:quickSearch].to_s
|
36
|
+
cq = @quick_search_block.call cq, options[:quickSearch].to_s if cq
|
48
37
|
end
|
49
38
|
|
50
39
|
total = (cq || q).count
|
@@ -68,12 +57,52 @@ module Tableling
|
|
68
57
|
offset = 0 if offset < 0
|
69
58
|
q = q.offset offset * limit
|
70
59
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
60
|
+
serialize_response total, q
|
61
|
+
end
|
62
|
+
|
63
|
+
class DSL
|
64
|
+
|
65
|
+
def initialize view
|
66
|
+
@view = view
|
67
|
+
end
|
68
|
+
|
69
|
+
def field name, options = {}, &block
|
70
|
+
@view.fields.delete_if{ |f| f.name.to_s == name.to_s }
|
71
|
+
Field.new(name, @view, options, &block).tap{ |f| @view.fields << f }
|
72
|
+
end
|
73
|
+
|
74
|
+
%w(base base_count).each do |m|
|
75
|
+
define_method m do |q|
|
76
|
+
@view.send "#{m}_query=", q
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
%w(quick_search serialize_record serialize_response).each do |m|
|
81
|
+
define_method m do |&block|
|
82
|
+
@view.send "#{m}_block=", block
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def serialize_response total, query
|
90
|
+
|
91
|
+
res = {
|
92
|
+
total: total,
|
93
|
+
data: query.all
|
76
94
|
}
|
95
|
+
|
96
|
+
if @serialize_response_block
|
97
|
+
@serialize_response_block.call res
|
98
|
+
else
|
99
|
+
res[:data] = res[:data].collect{ |r| serialize_record r }
|
100
|
+
res
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def serialize_record record
|
105
|
+
@serialize_record_block ? @serialize_record_block.call(record) : @fields.inject({}){ |memo,f| memo[f.name] = f.extract(record); memo }
|
77
106
|
end
|
78
107
|
end
|
79
108
|
end
|
@@ -1,13 +1,17 @@
|
|
1
1
|
class Book < ActiveRecord::Base
|
2
|
+
include Tableling::Model
|
2
3
|
|
3
4
|
tableling do
|
4
5
|
|
5
|
-
|
6
|
-
field :author
|
6
|
+
default_view do
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
field :title
|
9
|
+
field :author
|
10
|
+
|
11
|
+
quick_search do |query,term|
|
12
|
+
term = "%#{term.downcase}%"
|
13
|
+
query.where('LOWER(books.title) LIKE ? OR LOWER(books.author) LIKE ?', term, term)
|
14
|
+
end
|
11
15
|
end
|
12
16
|
end
|
13
17
|
end
|
Binary file
|
data/spec/dummy/db/test.sqlite3
CHANGED
Binary file
|
@@ -1,59 +1,52 @@
|
|
1
1
|
Connecting to database specified by database.yml
|
2
|
-
[1m[36m (0.
|
3
|
-
[1m[35m (
|
4
|
-
[1m[36m (
|
5
|
-
[1m[35m (
|
6
|
-
[1m[36m (2.3ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
2
|
+
[1m[36m (0.1ms)[0m [1mselect sqlite_version(*)[0m
|
3
|
+
[1m[35m (5.7ms)[0m CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
|
4
|
+
[1m[36m (1.3ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
5
|
+
[1m[35m (2.1ms)[0m SELECT "schema_migrations"."version" FROM "schema_migrations"
|
7
6
|
Connecting to database specified by database.yml
|
8
|
-
[1m[36m (
|
7
|
+
[1m[36m (1.4ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
9
8
|
Migrating to CreateBooks (20121008115302)
|
10
9
|
[1m[35m (0.0ms)[0m select sqlite_version(*)
|
11
10
|
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
12
|
-
[1m[35m (0.
|
13
|
-
[1m[36m (0.
|
14
|
-
[1m[35m (0.
|
15
|
-
[1m[36m (
|
16
|
-
[1m[35m (3.0ms)[0m commit transaction
|
17
|
-
[1m[36m (0.3ms)[0m [1mselect sqlite_version(*)[0m
|
11
|
+
[1m[35m (0.4ms)[0m CREATE TABLE "books" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255) NOT NULL, "author" varchar(255) NOT NULL, "year" integer NOT NULL, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
|
12
|
+
[1m[36m (0.2ms)[0m [1mCREATE UNIQUE INDEX "index_books_on_title" ON "books" ("title")[0m
|
13
|
+
[1m[35m (0.1ms)[0m INSERT INTO "schema_migrations" ("version") VALUES ('20121008115302')
|
14
|
+
[1m[36m (4.9ms)[0m [1mcommit transaction[0m
|
18
15
|
[1m[35m (0.1ms)[0m SELECT "schema_migrations"."version" FROM "schema_migrations"
|
19
|
-
[1m[36m (0.0ms)[0m [1mPRAGMA index_list("books")[0m
|
20
|
-
[1m[35m (0.0ms)[0m PRAGMA index_info('index_books_on_title')
|
21
16
|
Connecting to database specified by database.yml
|
22
|
-
[1m[36m (1.
|
23
|
-
[1m[35m (0.
|
24
|
-
[1m[36m (
|
25
|
-
[1m[35m (0.
|
26
|
-
[1m[36m (
|
27
|
-
[1m[35m (
|
28
|
-
[1m[36m (0.0ms)[0m [1mPRAGMA index_list("schema_migrations")[0m
|
29
|
-
[1m[35m (1.0ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
17
|
+
[1m[36m (1.2ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
18
|
+
[1m[35m (0.2ms)[0m select sqlite_version(*)
|
19
|
+
[1m[36m (1.0ms)[0m [1mCREATE TABLE "books" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255) NOT NULL, "author" varchar(255) NOT NULL, "year" integer NOT NULL, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) [0m
|
20
|
+
[1m[35m (0.8ms)[0m CREATE UNIQUE INDEX "index_books_on_title" ON "books" ("title")
|
21
|
+
[1m[36m (0.8ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL) [0m
|
22
|
+
[1m[35m (0.7ms)[0m CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
|
30
23
|
[1m[36m (0.1ms)[0m [1mSELECT version FROM "schema_migrations"[0m
|
31
24
|
[1m[35m (0.8ms)[0m INSERT INTO "schema_migrations" (version) VALUES ('20121008115302')
|
32
25
|
Connecting to database specified by database.yml
|
33
|
-
[1m[36m (
|
34
|
-
[1m[35m (
|
35
|
-
[1m[36m (1.
|
36
|
-
[1m[35m (
|
37
|
-
[1m[36m (
|
26
|
+
[1m[36m (1.4ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
27
|
+
[1m[35m (0.2ms)[0m select sqlite_version(*)
|
28
|
+
[1m[36m (1.8ms)[0m [1mDROP TABLE "books"[0m
|
29
|
+
[1m[35m (0.9ms)[0m CREATE TABLE "books" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255) NOT NULL, "author" varchar(255) NOT NULL, "year" integer NOT NULL, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
|
30
|
+
[1m[36m (0.8ms)[0m [1mCREATE UNIQUE INDEX "index_books_on_title" ON "books" ("title")[0m
|
38
31
|
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
39
32
|
Connecting to database specified by database.yml
|
40
|
-
[1m[36m (1.
|
41
|
-
[1m[35m (0.
|
42
|
-
[1m[36m (
|
43
|
-
[1m[35m (
|
44
|
-
[1m[36m (1.0ms)[0m [1mCREATE UNIQUE INDEX "index_books_on_title" ON "books" ("title")[0m
|
45
|
-
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
46
|
-
Connecting to database specified by database.yml
|
47
|
-
[1m[36m (2.2ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
48
|
-
[1m[35m (0.4ms)[0m select sqlite_version(*)
|
49
|
-
[1m[36m (3.3ms)[0m [1mDROP TABLE "books"[0m
|
50
|
-
[1m[35m (1.0ms)[0m CREATE TABLE "books" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255) NOT NULL, "author" varchar(255) NOT NULL, "year" integer NOT NULL, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
|
33
|
+
[1m[36m (1.3ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
34
|
+
[1m[35m (0.2ms)[0m select sqlite_version(*)
|
35
|
+
[1m[36m (5.2ms)[0m [1mDROP TABLE "books"[0m
|
36
|
+
[1m[35m (0.9ms)[0m CREATE TABLE "books" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255) NOT NULL, "author" varchar(255) NOT NULL, "year" integer NOT NULL, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
|
51
37
|
[1m[36m (0.9ms)[0m [1mCREATE UNIQUE INDEX "index_books_on_title" ON "books" ("title")[0m
|
52
38
|
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
53
39
|
Connecting to database specified by database.yml
|
54
|
-
[1m[36m (
|
55
|
-
[1m[35m (0.
|
56
|
-
[1m[36m (
|
40
|
+
[1m[36m (1.3ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
41
|
+
[1m[35m (0.2ms)[0m select sqlite_version(*)
|
42
|
+
[1m[36m (5.5ms)[0m [1mDROP TABLE "books"[0m
|
57
43
|
[1m[35m (1.1ms)[0m CREATE TABLE "books" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255) NOT NULL, "author" varchar(255) NOT NULL, "year" integer NOT NULL, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
|
58
|
-
[1m[36m (1.
|
44
|
+
[1m[36m (1.4ms)[0m [1mCREATE UNIQUE INDEX "index_books_on_title" ON "books" ("title")[0m
|
45
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
46
|
+
Connecting to database specified by database.yml
|
47
|
+
[1m[36m (1.2ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
48
|
+
[1m[35m (0.2ms)[0m select sqlite_version(*)
|
49
|
+
[1m[36m (1.3ms)[0m [1mDROP TABLE "books"[0m
|
50
|
+
[1m[35m (0.8ms)[0m CREATE TABLE "books" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255) NOT NULL, "author" varchar(255) NOT NULL, "year" integer NOT NULL, "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
|
51
|
+
[1m[36m (0.7ms)[0m [1mCREATE UNIQUE INDEX "index_books_on_title" ON "books" ("title")[0m
|
59
52
|
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
data/spec/dummy/log/test.log
CHANGED
@@ -1,28 +1,23 @@
|
|
1
1
|
Connecting to database specified by database.yml
|
2
|
-
|
2
|
+
Connecting to database specified by database.yml
|
3
|
+
Connecting to database specified by database.yml
|
4
|
+
[1m[36m (1.3ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
3
5
|
Migrating to CreateBooks (20121008115302)
|
4
6
|
[1m[35m (0.1ms)[0m begin transaction
|
5
|
-
[1m[36m (0.
|
7
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
6
8
|
[1m[35m (0.0ms)[0m begin transaction
|
7
9
|
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
8
10
|
Connecting to database specified by database.yml
|
9
|
-
[1m[36m (
|
11
|
+
[1m[36m (1.2ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
10
12
|
Migrating to CreateBooks (20121008115302)
|
11
13
|
[1m[35m (0.1ms)[0m begin transaction
|
12
|
-
[1m[36m (0.
|
14
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
13
15
|
[1m[35m (0.0ms)[0m begin transaction
|
14
16
|
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
15
17
|
Connecting to database specified by database.yml
|
16
|
-
[1m[36m (1.
|
18
|
+
[1m[36m (1.3ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
17
19
|
Migrating to CreateBooks (20121008115302)
|
18
20
|
[1m[35m (0.1ms)[0m begin transaction
|
19
21
|
[1m[36m (0.1ms)[0m [1mrollback transaction[0m
|
20
|
-
[1m[35m (0.1ms)[0m begin transaction
|
21
|
-
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
22
|
-
Connecting to database specified by database.yml
|
23
|
-
[1m[36m (1.9ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
24
|
-
Migrating to CreateBooks (20121008115302)
|
25
|
-
[1m[35m (0.1ms)[0m begin transaction
|
26
|
-
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
27
22
|
[1m[35m (0.0ms)[0m begin transaction
|
28
|
-
[1m[36m (0.
|
23
|
+
[1m[36m (0.0ms)[0m [1mrollback transaction[0m
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tableling-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.18
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-07-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -41,8 +41,8 @@ files:
|
|
41
41
|
- lib/tableling-rails/ext.rb
|
42
42
|
- lib/tableling-rails/field.rb
|
43
43
|
- lib/tableling-rails/global.rb
|
44
|
-
- lib/tableling-rails/serializer.rb
|
45
44
|
- lib/tableling-rails/settings.rb
|
45
|
+
- lib/tableling-rails/type_serializer.rb
|
46
46
|
- lib/tableling-rails/version.rb
|
47
47
|
- lib/tableling-rails/view.rb
|
48
48
|
- lib/tableling-rails.rb
|
@@ -123,12 +123,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
123
|
- - ! '>='
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
hash: -4338373402448950759
|
126
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
130
|
none: false
|
128
131
|
requirements:
|
129
132
|
- - ! '>='
|
130
133
|
- !ruby/object:Gem::Version
|
131
134
|
version: '0'
|
135
|
+
segments:
|
136
|
+
- 0
|
137
|
+
hash: -4338373402448950759
|
132
138
|
requirements: []
|
133
139
|
rubyforge_project:
|
134
140
|
rubygems_version: 1.8.25
|