quantum_fields 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 75256efead78bb5b4cf0fb0addf73eb4ebc4e541c5a549b2f26a0708a2dbc7b6
4
- data.tar.gz: 783c270ceb4e8d3fae1a2bb3669fe075694c5137a8816bab8d48dd10340e0621
3
+ metadata.gz: 9cc27f3dfbb9f1839c4181a91ad750a8ba0f7a255409a5a0574116df423a4a4f
4
+ data.tar.gz: 6e22264a1fd7d81ac75befda172afab1e2a6891594a29a692cfdf7b008f74259
5
5
  SHA512:
6
- metadata.gz: 319478c26780c49f9862863882239d5a11056bc8ec1c30895a1be826e4c01af04f562d3e5d72e9b9bc854cf19c13cfff815a4bf1e109635ed1e13baa0a303995
7
- data.tar.gz: 936e0ef4b000b0370f9a060c769583e62029a820f129d47c9b9e2e49ebdaa4b8901be50db9e427ccc5ebac64ba589a1a3f6b8de5b9931e07bb2d1feb125a7597
6
+ metadata.gz: 61c95851553049b511fd1afffe1ab3f723f83ab852714843d5abfa876789fd3e9ea1f6cfa0cf35c87183ab37b5c6a6b754a5b328fb697455faf91db5234f029d
7
+ data.tar.gz: a92e736b89cd46bc23bdeeb1c538a33cb5f643d2dba17465ff2bc7be512d09bdd9473cb720e38d5720122c6df3f9f58a2ffd146f1b0e58710aa247cff13c2af8
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # QuantumFields [![Build Status](https://travis-ci.com/ErvalhouS/quantum_fields.svg?branch=master)](https://travis-ci.com/ErvalhouS/quantum_fields) [![Maintainability](https://api.codeclimate.com/v1/badges/48fd7d9c967edc9327fe/maintainability)](https://codeclimate.com/github/ErvalhouS/quantum_fields/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/48fd7d9c967edc9327fe/test_coverage)](https://codeclimate.com/github/ErvalhouS/quantum_fields/test_coverage) [![Inline docs](http://inch-ci.org/github/ErvalhouS/quantum_fields.svg?branch=master)](http://inch-ci.org/github/ErvalhouS/quantum_fields)
1
+ # QuantumFields [![Build Status](https://travis-ci.com/ErvalhouS/quantum_fields.svg?branch=master)](https://travis-ci.com/ErvalhouS/quantum_fields) [![Maintainability](https://api.codeclimate.com/v1/badges/48fd7d9c967edc9327fe/maintainability)](https://codeclimate.com/github/ErvalhouS/quantum_fields/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/48fd7d9c967edc9327fe/test_coverage)](https://codeclimate.com/github/ErvalhouS/quantum_fields/test_coverage) [![Inline docs](http://inch-ci.org/github/ErvalhouS/quantum_fields.svg?branch=master)](http://inch-ci.org/github/ErvalhouS/quantum_fields) [![Gem Version](https://badge.fury.io/rb/quantum_fields.svg)](https://badge.fury.io/rb/quantum_fields)
2
2
 
3
3
  ### Give noSQL powers to your SQL database
4
4
  QuantumFields is a gem to extend your Rails model's making them able to use virtual fields from a JSON column or a Text column serialized as a Hash. This means that you can use fields that were not explicitly declared in your schema as if they were.
data/Rakefile CHANGED
@@ -4,6 +4,16 @@ rescue LoadError
4
4
  puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
5
  end
6
6
 
7
+ begin
8
+ require 'rspec/core/rake_task'
9
+
10
+ RSpec::Core::RakeTask.new(:spec)
11
+
12
+ task :default => :spec
13
+ rescue LoadError
14
+ # no rspec available
15
+ end
16
+
7
17
  require 'rdoc/task'
8
18
 
9
19
  RDoc::Task.new(:rdoc) do |rdoc|
@@ -1,9 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_record'
4
+ require 'rails/railtie'
3
5
  require 'active_support/concern'
4
6
  require 'quantum_fields/active_record_patch'
5
7
  require 'quantum_fields/no_sqlize'
6
8
  require 'quantum_fields/railtie'
9
+ require 'quantum_fields/support'
7
10
  require 'quantum_fields/validation_injector'
8
11
 
9
12
  # A module to abstract a noSQL aproach into SQL records, using a `parameters`
@@ -6,9 +6,8 @@ ActiveRecord::PredicateBuilder.class_eval do
6
6
  bind = build_bind_attribute(attribute.name, value)
7
7
  attribute.eq(bind)
8
8
  elsif table.send('klass').respond_to?(:fields_column) && !table.send('klass').column_names.include?(attribute.name)
9
- json_key = attribute.name
9
+ op = QuantumFields::Support.field_node(table.send('klass').arel_table[table.send('klass').fields_column], attribute.name)
10
10
  attribute.name = table.send('klass').fields_column.to_s
11
- op = Arel::Nodes::InfixOperation.new('->>', table.send('klass').arel_table[table.send('klass').fields_column], Arel::Nodes.build_quoted(json_key))
12
11
  bind = build_bind_attribute(op, value)
13
12
  op.eq(bind)
14
13
  else
@@ -21,9 +20,8 @@ ActiveRecord::Relation.class_eval do
21
20
  if klass.column_names.include?(name.to_s) || !klass.respond_to?(:fields_column)
22
21
  klass.arel_attribute(name, table)
23
22
  else
24
- Arel::Nodes::InfixOperation.new('->>',
25
- klass.arel_table[klass.fields_column],
26
- Arel::Nodes.build_quoted(name))
23
+ QuantumFields::Support.field_node klass.arel_table[klass.fields_column],
24
+ name
27
25
  end
28
26
  end
29
27
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'quantum_fields/support/postgresql'
4
+ require 'quantum_fields/support/mysql'
5
+ require 'quantum_fields/support/sqlite3'
6
+
7
+ module QuantumFields
8
+ # Module to add support to different database operation
9
+ module Support
10
+ class << self
11
+ # Redirects call to current database context support module
12
+ def field_node(field, key)
13
+ ('QuantumFields::Support::' +
14
+ ActiveRecord::Base.connection
15
+ .instance_values['config'][:adapter]
16
+ .classify).constantize.field_node(field, key)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module QuantumFields
4
+ module Support
5
+ # Abstracts MySQL support for quantum_fields operations
6
+ module Mysql
7
+ class << self
8
+ # Returns an Arel node in the context of given field and JSON key,
9
+ # which in this context constructs as "json_extract("my_models"."my_json_field", '$.key')"
10
+ def field_node(field, key)
11
+ Arel::Nodes::NamedFunction.new('json_extract',
12
+ [field,
13
+ Arel::Nodes.build_quoted("$.#{key}")])
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module QuantumFields
4
+ module Support
5
+ # Abstracts PostgreSQL support for quantum_fields operations
6
+ module Postgresql
7
+ class << self
8
+ # Returns an Arel node in the context of given field and JSON key,
9
+ # which in this context constructs as "'my_json_field'->>'my_key'"
10
+ def field_node(field, key)
11
+ Arel::Nodes::InfixOperation.new('->>',
12
+ field,
13
+ Arel::Nodes.build_quoted(key))
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module QuantumFields
4
+ module Support
5
+ # Abstracts SQLite support for quantum_fields operations
6
+ module Sqlite3
7
+ class << self
8
+ # Returns an Arel node in the context of given field and JSON key,
9
+ # which in this context constructs as "json_extract("my_models"."my_json_field", '$.key')"
10
+ def field_node(field, key)
11
+ Arel::Nodes::NamedFunction.new('json_extract',
12
+ [field,
13
+ Arel::Nodes.build_quoted("$.#{key}")])
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module QuantumFields
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quantum_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fernando Bellincanta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-13 00:00:00.000000000 Z
11
+ date: 2019-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '5'
27
27
  - !ruby/object:Gem::Dependency
28
- name: pg
28
+ name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,19 +39,19 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rspec
42
+ name: sqlite3
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 1.3.6
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 1.3.6
55
55
  description: QuantumFields is a gem to extend your Rails model's making them able
56
56
  to use virtual fields from a JSON column or a Text column serialized as a Hash.
57
57
  This means that you can use fields that were not explicitly declared in your schema
@@ -69,6 +69,10 @@ files:
69
69
  - lib/quantum_fields/active_record_patch.rb
70
70
  - lib/quantum_fields/no_sqlize.rb
71
71
  - lib/quantum_fields/railtie.rb
72
+ - lib/quantum_fields/support.rb
73
+ - lib/quantum_fields/support/mysql.rb
74
+ - lib/quantum_fields/support/postgresql.rb
75
+ - lib/quantum_fields/support/sqlite3.rb
72
76
  - lib/quantum_fields/validation_injector.rb
73
77
  - lib/quantum_fields/version.rb
74
78
  - lib/tasks/quantum_fields_tasks.rake
@@ -92,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
96
  version: '0'
93
97
  requirements: []
94
98
  rubyforge_project:
95
- rubygems_version: 2.7.7
99
+ rubygems_version: 2.7.5
96
100
  signing_key:
97
101
  specification_version: 4
98
102
  summary: Give noSQL powers to your SQL database