rubyql 0.0.0 → 0.0.1

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: ff161429f1ce9cd5f0aeb8ff0e506709ae916c7c
4
- data.tar.gz: 1229bce22970e2730c4fb96e7647ed8ad24aebe9
3
+ metadata.gz: 7ebe793cb41788c0005aea403a8163ee8e1a3d5e
4
+ data.tar.gz: 6c055b0202a59cb35f06db26d906dc3ac37f631d
5
5
  SHA512:
6
- metadata.gz: 76f777f681ed4c59b9715f8c37b3398b5fdaeef6ce33f98bcba94bdd9780f3676fd62bebd51b3ad6166a88117781fa5dd46cc796c84580330ca434382b6d43a3
7
- data.tar.gz: 84b2a60a17d0b30aeb2016c69910b4b6f8d3c3a97d0dfd918b3e0604e23dd1966c08a131139ce35dd35ea787c1bea945740012ee6b9e5cb7287e0523dc1dfe5d
6
+ metadata.gz: a97cc880a462bbb7474d01d6279b51c198af8e1aa9bb2f2c904ccfa0034f961c6bf61c637bc9ae93d7c9175dafa5dc6581ec2e880340e5f54c29d0d12ca85f84
7
+ data.tar.gz: 9a3c8cf06369b801006ca7601546b7575bcc67281e7a6c068893964296353cc8d677a8cf4f5cb9dda2c867458e9ead26c94e435f568286eadd4b0c3bf54b9905
data/README.md CHANGED
@@ -0,0 +1,71 @@
1
+ # RubyQL
2
+ ## A query language for ruby hashes
3
+
4
+ RubyQL is a query language designed for very flexible rest apis or plain ruby hashes.
5
+
6
+ RubyQL loves it when its used together with ActiveRecord 🤤
7
+
8
+ Example:
9
+ ``` ruby
10
+ require 'rubyql'
11
+
12
+ class UserQuery < RubyQL
13
+ def query
14
+ User.find_by(query_params).attributes
15
+ end
16
+ end
17
+ ```
18
+
19
+ The class we created overwrites the query method, to provide a custom mechanism which should return a hash. `query_params` is
20
+ the hash which holds the provided parameter, like `WHERE` in SQL.
21
+
22
+ **IMPORTANT**: `.attributes` is necessary for ActiveRecord, only returning the actual hash, not the ActiveModel object.
23
+
24
+ Usage:
25
+ ```
26
+ UserQuery.new({"firstname"=>"", "lastname"=>"", "email"=>"niklas.hanft@outlook.com"}).execute
27
+ => {"firstname"=>"Niklas", "lastname"=>"Hanft", "email"=>"niklas.hanft@outlook.com"}
28
+
29
+ UserQuery.new({"lastname"=>"", "email"=>"niklas.hanft@outlook.com"}).execute
30
+ => {"lastname"=>"Hanft", "email"=>"niklas.hanft@outlook.com"}
31
+
32
+ UserQuery.new({"lastname"=>"", "email"=>"", "id"=>1}).execute
33
+ => {"lastname"=>"Hanft", "email"=>"niklas.hanft@outlook.com", "id"=>1}
34
+ ```
35
+
36
+ As you can see we left the wanted attributes blank, so rubyql will fill them out, if they exist.
37
+
38
+ For a better understanding another plain ruby example:
39
+
40
+ ``` ruby
41
+ require 'rubyql
42
+
43
+ class PlainQuery < RubyQL
44
+ def query
45
+ {"firstname"=>"Niklas", "lastname"=>"Hanft", "email"=>"niklas.hanft@outlook.com", "id"=>1337, "another_attribute"=>"Hello World"}
46
+ end
47
+ end
48
+ ```
49
+
50
+ The method is only returning a simple hash. Now we can execute queries:
51
+
52
+ ```
53
+ PlainQuery.new({"firstname"=>"", "lastname"=>"", "email"=>"niklas.hanft@outlook.com", "id"=>""}).execute
54
+ => {"firstname"=>"Hanft", "lastname"=>"Niklas", "email"=>"niklas.hanft@outlook.com", "id"=>1337}
55
+
56
+ PlainQuery.new({"email"=>"niklas.hanft@outlook.com", "id"=>"", "another_attribute"=>""}).execute
57
+ => {"email"=>"niklas.hanft@outlook.com", "id"=>1337, "another_attribute"=>"Hello World"}
58
+ ```
59
+
60
+ As this is static, it doesn't really make sense, but for understanding it might be ok to use it this way. But mainly it
61
+ should be used with a database orm or some dynamic functions which return hashes.
62
+
63
+ Advanced usage:
64
+
65
+ *Coming soon*
66
+
67
+
68
+
69
+
70
+
71
+
data/lib/rubyql.rb CHANGED
@@ -21,8 +21,6 @@ class RubyQL
21
21
  end
22
22
  end
23
23
 
24
- private
25
-
26
24
  def response_attr
27
25
  @params.select do |key, value|
28
26
  value == '' || value.nil?
@@ -0,0 +1,27 @@
1
+ require 'spectr'
2
+ require_relative '../lib/rubyql'
3
+
4
+ Spectr.new.test 'Test the queryable class' do |test|
5
+
6
+ class UserQuery < RubyQL
7
+ def query
8
+ {"username"=>"paradoxxger", "firstname"=>"Niklas", "lastname"=>"Hanft", "email"=>"niklas.hanft@outlook.com"}
9
+ end
10
+ end
11
+
12
+ test.assume('The response is a hash', true) do
13
+ UserQuery.new({"firstname"=>"", "lastname"=>"", "email"=>"niklas.hanft@outlook.com"}).execute.is_a?(Hash)
14
+ end
15
+
16
+ test.assume('The response equals the given hash', {"firstname"=>"Niklas", "lastname"=>"Hanft", "email"=>"niklas.hanft@outlook.com"}) do
17
+ UserQuery.new({"firstname"=>"", "lastname"=>"", "email"=>"niklas.hanft@outlook.com"}).execute
18
+ end
19
+
20
+ test.assume('The response equals the given hash, removing some attributes', {"lastname"=>"Hanft", "email"=>"niklas.hanft@outlook.com"}) do
21
+ UserQuery.new({"lastname"=>"", "email"=>"niklas.hanft@outlook.com"}).execute
22
+ end
23
+
24
+ test.assume('The query_params are only the email', {"email" => "niklas.hanft@outlook.com"}) do
25
+ UserQuery.new({"lastname"=>"", "email"=>"niklas.hanft@outlook.com"}).query_params
26
+ end
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niklas Hanft
@@ -18,6 +18,7 @@ extra_rdoc_files: []
18
18
  files:
19
19
  - README.md
20
20
  - lib/rubyql.rb
21
+ - test/user_query_spectr.rb
21
22
  homepage: https://github.com/ParadoXxGER/rubyql
22
23
  licenses:
23
24
  - MIT