eql 0.0.2 → 0.0.3
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 +4 -4
- data/lib/eql.rb +2 -0
- data/lib/eql/builder.rb +8 -34
- data/lib/eql/config.rb +14 -3
- data/lib/eql/template_loader.rb +89 -0
- data/lib/eql/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9aef4bcdca60abb3b59d17f32199073965fc2aa8
|
4
|
+
data.tar.gz: 4848ccd3aa324bd0d4869301fa128401bef73e04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38c8a56b15f1a30c6fe2b1504f5a035498e8e19927ef4b8a85358094b5e0ec0166cc7231c1b19255ce470bc827deb12f1557bea973db0169cd0296bb74c00cf7
|
7
|
+
data.tar.gz: f8b934bddd07357feb230de012b4e7f7c80ed0b1e8b19ebf27bd9a301e8fc1e9e7792ee784656ab30221cb5eb0f35f6b11cf58c4c40e5aee5a46f01ef865a5ff
|
data/lib/eql.rb
CHANGED
data/lib/eql/builder.rb
CHANGED
@@ -34,7 +34,14 @@ module Eql
|
|
34
34
|
# @param [String, Symbol] name template's name
|
35
35
|
#
|
36
36
|
def load_template(name)
|
37
|
-
@template_content =
|
37
|
+
@template_content = loader.load_template(name)
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# @return [Eql::TemplateLoader]
|
42
|
+
#
|
43
|
+
def loader
|
44
|
+
@loader ||= TemplateLoader.new(self)
|
38
45
|
end
|
39
46
|
|
40
47
|
#
|
@@ -73,12 +80,6 @@ module Eql
|
|
73
80
|
@template_content.to_s
|
74
81
|
end
|
75
82
|
|
76
|
-
class H < Hash
|
77
|
-
def name
|
78
|
-
:h
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
83
|
#
|
83
84
|
# Render a template
|
84
85
|
#
|
@@ -97,33 +98,6 @@ module Eql
|
|
97
98
|
Eql::Proxy.generate(adapter)
|
98
99
|
end
|
99
100
|
|
100
|
-
#
|
101
|
-
# File template to find
|
102
|
-
#
|
103
|
-
# @param [String, Symbol] file template's name
|
104
|
-
#
|
105
|
-
# @return [String] returns file path pattern
|
106
|
-
#
|
107
|
-
def template_path(file)
|
108
|
-
File.join(@path.to_s, file.to_s) + adapter.extension
|
109
|
-
end
|
110
|
-
|
111
|
-
#
|
112
|
-
# Resolve file's path
|
113
|
-
#
|
114
|
-
# @raise [RuntimeError] when can't wind a file
|
115
|
-
#
|
116
|
-
# @param [String] file template's name
|
117
|
-
#
|
118
|
-
# @return [String] returns template's path
|
119
|
-
#
|
120
|
-
def resolve_path(file)
|
121
|
-
path = template_path(file)
|
122
|
-
Dir.glob(path).first.tap do |f|
|
123
|
-
raise "Unable to find query template with #{path.inspect} location" unless f
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
101
|
def method_missing(name, *args, &block)
|
128
102
|
adapter.send(name, *args, &block)
|
129
103
|
end
|
data/lib/eql/config.rb
CHANGED
@@ -3,13 +3,24 @@ module Eql
|
|
3
3
|
# Config class holds rendering settings
|
4
4
|
#
|
5
5
|
class Config
|
6
|
-
# @
|
6
|
+
# @return [String] returns default templates folder
|
7
7
|
attr_accessor :path
|
8
|
-
# @
|
8
|
+
# @return [Symbol] returns key of default adapter
|
9
9
|
attr_accessor :adapter
|
10
|
+
attr_writer :cache_templates
|
10
11
|
|
11
12
|
def initialize
|
12
|
-
@adapter
|
13
|
+
@adapter = :active_record
|
14
|
+
@cache_templates = true
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
# Should templates be cached?
|
19
|
+
#
|
20
|
+
# @return [Boolean]
|
21
|
+
#
|
22
|
+
def cache_templates?
|
23
|
+
@cache_templates
|
13
24
|
end
|
14
25
|
|
15
26
|
#
|
@@ -0,0 +1,89 @@
|
|
1
|
+
module Eql
|
2
|
+
#
|
3
|
+
# Loader class loads templates and caches them.
|
4
|
+
#
|
5
|
+
class TemplateLoader
|
6
|
+
extend Forwardable
|
7
|
+
|
8
|
+
def_delegator 'self.class', :cache
|
9
|
+
|
10
|
+
# @return [Eql::Builder]
|
11
|
+
attr_reader :builder
|
12
|
+
|
13
|
+
#
|
14
|
+
# @param [Eql::Builder] builder
|
15
|
+
#
|
16
|
+
def initialize(builder)
|
17
|
+
@builder = builder
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# Load builder template
|
22
|
+
#
|
23
|
+
# @param [String, Symbol] name template's name
|
24
|
+
#
|
25
|
+
# @return [String] returns loaded template
|
26
|
+
#
|
27
|
+
def load_template(name)
|
28
|
+
path = resolve_path(name)
|
29
|
+
return load_file(path) unless Eql.config.cache_templates?
|
30
|
+
cache[path] ||= load_file(path)
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# Load file's content
|
35
|
+
#
|
36
|
+
# @api private
|
37
|
+
#
|
38
|
+
# @param [String] path file's path
|
39
|
+
#
|
40
|
+
# @return [String]
|
41
|
+
#
|
42
|
+
def load_file(path)
|
43
|
+
File.read(path)
|
44
|
+
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# File template to find
|
48
|
+
#
|
49
|
+
# @api private
|
50
|
+
#
|
51
|
+
# @param [String, Symbol] file template's name
|
52
|
+
#
|
53
|
+
# @return [String] returns file path pattern
|
54
|
+
#
|
55
|
+
def template_path(file)
|
56
|
+
[
|
57
|
+
File.join(@builder.path.to_s, file.to_s),
|
58
|
+
@builder.adapter.extension
|
59
|
+
].join
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# Resolve file's path
|
64
|
+
#
|
65
|
+
# @api private
|
66
|
+
#
|
67
|
+
# @raise [RuntimeError] when can't wind a file
|
68
|
+
#
|
69
|
+
# @param [String] file template's name
|
70
|
+
#
|
71
|
+
# @return [String] returns template's path
|
72
|
+
#
|
73
|
+
def resolve_path(file)
|
74
|
+
path = template_path(file)
|
75
|
+
Dir.glob(path).first.tap do |f|
|
76
|
+
raise "Unable to find query template with #{path.inspect} location" unless f
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
#
|
81
|
+
# Templates cache
|
82
|
+
#
|
83
|
+
# @return [Hash{String => String}]
|
84
|
+
#
|
85
|
+
def self.cache
|
86
|
+
@cache ||= {}
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
data/lib/eql/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Oleg Yashchuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-04-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description: Eql provides an ability to use ERB templates with your DB queries
|
84
84
|
email:
|
85
85
|
- oazoer@gmail.com
|
86
86
|
executables: []
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- lib/eql/builder.rb
|
97
97
|
- lib/eql/config.rb
|
98
98
|
- lib/eql/proxy.rb
|
99
|
+
- lib/eql/template_loader.rb
|
99
100
|
- lib/eql/version.rb
|
100
101
|
homepage:
|
101
102
|
licenses:
|
@@ -120,5 +121,5 @@ rubyforge_project:
|
|
120
121
|
rubygems_version: 2.5.1
|
121
122
|
signing_key:
|
122
123
|
specification_version: 4
|
123
|
-
summary:
|
124
|
+
summary: Eql Query Language
|
124
125
|
test_files: []
|