railz_lite 0.2.0 → 0.2.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
  SHA256:
3
- metadata.gz: 3c89ff0ff19ada2a09bfd2735696dcd83ea0d6452cb176c388d8f73f2d427cc5
4
- data.tar.gz: 19af0a264b0b90bde7f35f7ee4603554b2859a444fc5354bfe060cb46e60cdf2
3
+ metadata.gz: d9913416758845461437f605307b2a10be934ed1da34652947f9a2dcbfdb1caa
4
+ data.tar.gz: 33c8f9a302c65d3f4f55ebcd1682458de7a856d2c0c66c4fc6e1c614d64792e6
5
5
  SHA512:
6
- metadata.gz: ad80911593eff8acf24ca6e5e80ba09860075694d880a8549514164f1ded5b4889df94cd82d1905d1ef28ee36a87329a74186468d0cbd0eb8618f6465650c193
7
- data.tar.gz: d8ce5424801a719ef0e24d2cd078c7c33119331802fc73861673d5fa622e055c2b331d69296a5f18d9ef2849ed6ecd2454e08de5cf6f26ea1e2fd82605b2f0b5
6
+ metadata.gz: 900a8e1808fdfc07b4c5638c1a7fb0cc3357c15fe9eaf8a563c8b56596716fc12ba038a75df0fe462ddd7f2bffc42c6367c6743e9184fe4d63c3be5e8cd384ec
7
+ data.tar.gz: 56cdd5db6f1d0b008f1ad9b34e24047da258601bd57b8d76723bf1ccd8a76bbad486c1ec7df5503965d3d0f1b1d3e7fb8e7939974e71739bfbee4d94ca762144
@@ -46,34 +46,32 @@ class HasManyOptions < AssocOptions
46
46
  end
47
47
  end
48
48
 
49
- module Associatable
50
- def belongs_to(name, options = {})
51
- options = BelongsToOptions.new(name, options)
52
- assoc_options[name] = options
53
- define_method(name) do
54
- foreign_key = send(options.foreign_key)
55
- primary_key = options.primary_key
56
- params = [[primary_key, foreign_key]].to_h
57
- options.model_class.where(params).first
49
+ module RailzLite
50
+ module Associatable
51
+ def belongs_to(name, options = {})
52
+ options = BelongsToOptions.new(name, options)
53
+ assoc_options[name] = options
54
+ define_method(name) do
55
+ foreign_key = send(options.foreign_key)
56
+ primary_key = options.primary_key
57
+ params = [[primary_key, foreign_key]].to_h
58
+ options.model_class.where(params).first
59
+ end
58
60
  end
59
- end
60
61
 
61
- def has_many(name, options = {})
62
- options = HasManyOptions.new(name, self.name, options)
63
- define_method(name) do
64
- foreign_key = options.foreign_key
65
- primary_key = send(options.primary_key)
66
- params = [[foreign_key, primary_key]].to_h
67
- options.model_class.where(params)
62
+ def has_many(name, options = {})
63
+ options = HasManyOptions.new(name, self.name, options)
64
+ define_method(name) do
65
+ foreign_key = options.foreign_key
66
+ primary_key = send(options.primary_key)
67
+ params = [[foreign_key, primary_key]].to_h
68
+ options.model_class.where(params)
69
+ end
68
70
  end
69
- end
70
71
 
71
- def assoc_options
72
- @assoc_options ||= {}
73
- @assoc_options
72
+ def assoc_options
73
+ @assoc_options ||= {}
74
+ @assoc_options
75
+ end
74
76
  end
75
77
  end
76
-
77
- class SQLObject
78
- extend Associatable
79
- end
@@ -1,10 +1,10 @@
1
1
  require_relative 'db_connection'
2
- require_relative 'sql_object'
3
2
 
4
- module Searchable
5
- def where(params)
6
- where_line = params.keys.map { |attr_name| "#{attr_name} = ?" }.join(" AND ")
7
- results = DBConnection.execute(<<-SQL, *params.values)
3
+ module RailzLite
4
+ module Searchable
5
+ def where(params)
6
+ where_line = params.keys.map { |attr_name| "#{attr_name} = ?" }.join(" AND ")
7
+ results = DBConnection.execute(<<-SQL, *params.values)
8
8
  SELECT
9
9
  *
10
10
  FROM
@@ -12,10 +12,7 @@ module Searchable
12
12
  WHERE
13
13
  #{where_line}
14
14
  SQL
15
- results.map { |attrs| self.new(attrs) }
15
+ results.map { |attrs| self.new(attrs) }
16
+ end
16
17
  end
17
18
  end
18
-
19
- class SQLObject
20
- extend Searchable
21
- end
@@ -1,8 +1,13 @@
1
1
  require_relative 'db_connection'
2
+ require_relative 'associatable'
3
+ require_relative 'searchable'
2
4
  require 'active_support/inflector'
3
5
 
4
6
  module RailzLite
5
7
  class SQLObject
8
+ extend RailzLite::Associatable
9
+ extend RailzLite::Searchable
10
+
6
11
  def self.columns
7
12
  @columns ||= DBConnection.execute2(<<-SQL)
8
13
  SELECT
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailzLite
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railz_lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - bryan lynch