nssql 0.1.1 → 1.0.0

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: 29a14e303af8a7a3adf5bd10c115095f2690c1dde7d7b9bca930f669e3b279fb
4
- data.tar.gz: fbd6d7e0032ed00f4a12dc6bc3032aea5b0b135935b703c64de14a44fda0bfe1
3
+ metadata.gz: 3800e381c1ae7811f2e0eac2c216d61047d87c06fbc576331d4b787d7c554388
4
+ data.tar.gz: 991f4188a0a767ac2714157a5deaca48e2c2edd26c1235a1397c40b52a7e5a45
5
5
  SHA512:
6
- metadata.gz: 2f112c9987540c853e48ff1fc3f41c2c9fe1f281675eec16d27e9366ee8c75fb3dd1886df23240ef968bccdf100d93cac8bc629f99df2b169776fb9cfcadfbff
7
- data.tar.gz: b2baa0aaf4a14a71bad05f8fe50ac1a89e86b0bf46e38b23dd3d9a3219032d11097737932679ebd49d2924fd58d75131e485a89d4538593a0ccc60127cda0a52
6
+ metadata.gz: ae877bc33608e7153a87f78c87a0abd2e5bf921be54c14b0186f0ae309c09bf33b4a1f49883f2b67a2bf9f4e1825d4371d35b261f802bf85499c5e402b949376
7
+ data.tar.gz: f8e03add922fcd156a184308392aa40125416b7e31d9a3c03129b6b0d61a33c7ca8d57a158bff1a1b2184f266c2c59959c6e847b79d2f1cacb90e45fbc68de7c
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-2.6.2
1
+ ruby-2.6.3
data/.travis.yml CHANGED
@@ -9,6 +9,7 @@ rvm:
9
9
  - 2.5.1
10
10
  - 2.5.3
11
11
  - 2.6.2
12
+ - 2.6.3
12
13
  before_install: gem install bundler -v 1.17.3
13
14
  before_script:
14
15
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## 1.0.0 (2019-08-07)
2
+
3
+ - New way of defining columns: `ns_column :column`
4
+ - Uses `include` to support inheritance from other classes
5
+
1
6
  ## 0.1.1 (2019-04-08)
2
7
 
3
8
  - Now possible to get `table_name`, `primary_keys`, and `column` from a `NSSQL::Table`
data/README.md CHANGED
@@ -39,16 +39,23 @@ end
39
39
  ### Table
40
40
 
41
41
  ```ruby
42
- class TestTable < NSSQL::Table
43
- table_name 'test_table'
44
- primary_keys 'id', 'line_id'
45
- columns 'id', 'line_id', 'name'
42
+ class TestTable
43
+ include NSSQL::Table
44
+
45
+ ns_table_name :test_table
46
+ ns_primary_keys :id, :line_id
47
+ ns_column :id
48
+ ns_column :line_id
49
+ ns_column :name, as: :display_name
46
50
  end
51
+
52
+ TestTable.ns_column_names # => [:id, :line_id, :name]
53
+ TestTable.ns_aliased_column_names # => [:id, :line_id, :display_name]
47
54
  ```
48
55
 
49
56
  ### Select columns
50
57
 
51
- `TestTable.select_columns_query` will generate:
58
+ `TestTable.select_ns_columns_query` will generate:
52
59
 
53
60
  ```SQL
54
61
  SELECT
@@ -59,7 +66,7 @@ ORDER BY
59
66
  id
60
67
  ```
61
68
 
62
- We can pass options, like `TestTable.select_columns_query(where: 'id > 500')` and this will generate:
69
+ We can pass options, like `TestTable.select_ns_columns_query(where: 'id > 500')` and this will generate:
63
70
 
64
71
  ```SQL
65
72
  SELECT
data/lib/nssql/table.rb CHANGED
@@ -3,38 +3,56 @@
3
3
  module NSSQL
4
4
  # Base class for representing NetSuite tables.
5
5
  # Table name, primary keys and wanted columns are expected to be defined.
6
- class Table
7
- class << self
8
- def select_columns_query(where: nil)
6
+ #
7
+ module Table
8
+ def self.included(klass)
9
+ klass.extend(ClassMethods)
10
+ end
11
+
12
+ # Class methods for NSSQL::Table module.
13
+ #
14
+ module ClassMethods
15
+ attr_reader :ns_columns
16
+
17
+ def select_ns_columns_query(where: nil)
9
18
  where_statement = "WHERE #{where}" if where
10
19
 
11
20
  <<~SQL
12
21
  SELECT
13
- #{columns.join(',')}
22
+ #{ns_column_names.join(',')}
14
23
  FROM
15
- #{table_name}
24
+ #{ns_table_name}
16
25
  #{where_statement if where}
17
26
  ORDER BY
18
- #{primary_keys.first}
27
+ #{ns_primary_keys.first}
19
28
  SQL
20
29
  end
21
30
 
22
- def table_name(table_name = nil)
23
- return @table_name if table_name.nil?
31
+ def ns_table_name(ns_table_name = nil)
32
+ return @ns_table_name if ns_table_name.nil?
24
33
 
25
- @table_name = table_name
34
+ @ns_table_name = ns_table_name
26
35
  end
27
36
 
28
- def primary_keys(*primary_keys)
29
- return @primary_keys if primary_keys.empty?
37
+ def ns_primary_keys(*ns_primary_keys)
38
+ return @ns_primary_keys if ns_primary_keys.empty?
30
39
 
31
- @primary_keys = primary_keys
40
+ @ns_primary_keys = ns_primary_keys.flatten
32
41
  end
33
42
 
34
- def columns(*columns)
35
- return @columns if columns.empty?
43
+ def ns_column(name, options = {})
44
+ @ns_columns ||= {}
45
+ @ns_columns[name] = options
46
+ end
47
+
48
+ def ns_aliased_column_names
49
+ ns_columns.sort.map do |name, options|
50
+ options[:as] || name
51
+ end
52
+ end
36
53
 
37
- @columns = columns
54
+ def ns_column_names
55
+ ns_columns.keys.sort
38
56
  end
39
57
  end
40
58
  end
data/lib/nssql/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NSSQL
4
- VERSION = '0.1.1'
4
+ VERSION = '1.0.0'
5
5
  end
data/nssql.gemspec CHANGED
@@ -39,7 +39,7 @@ Gem::Specification.new do |spec|
39
39
 
40
40
  spec.add_runtime_dependency 'ruby-odbc', '~> 0.99997'
41
41
 
42
- spec.add_development_dependency 'bundler', '~> 1.17'
42
+ spec.add_development_dependency 'bundler', '>= 1.17', '< 3'
43
43
  spec.add_development_dependency 'minitest', '~> 5.0'
44
44
  spec.add_development_dependency 'rake', '~> 10.0'
45
45
  spec.add_development_dependency 'rubocop', '>= 0.60.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nssql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Love Ottosson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-08 00:00:00.000000000 Z
11
+ date: 2019-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-odbc
@@ -28,16 +28,22 @@ dependencies:
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '1.17'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '3'
34
37
  type: :development
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - "~>"
41
+ - - ">="
39
42
  - !ruby/object:Gem::Version
40
43
  version: '1.17'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '3'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: minitest
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -143,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
149
  - !ruby/object:Gem::Version
144
150
  version: '0'
145
151
  requirements: []
146
- rubygems_version: 3.0.3
152
+ rubygems_version: 3.0.4
147
153
  signing_key:
148
154
  specification_version: 4
149
155
  summary: Lightweight gem for fetching data from NetSuite with SQL.