bezel-app 0.0.7 → 0.0.8

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
  SHA1:
3
- metadata.gz: 7eb7d3e03695a324803eb0be6125841bbb5d17a5
4
- data.tar.gz: 66ab72c4309df61a07d3126f5844ed261f3edbf5
3
+ metadata.gz: 703eaccf4e5de1143a209437645a632304dd3390
4
+ data.tar.gz: 78819b0d174f637158a6c23e048783c30af75e3c
5
5
  SHA512:
6
- metadata.gz: 57368d376b440714338edfd82730e4f4e52869b308cd9c202ea1f25f8facf132b7236f7bee92d0323898eba7d3ea7ab746b7bce1320aa36bb4dcd32c97f63984
7
- data.tar.gz: 3b367b6cf877d6e02d6081da992a56b6f7d4b8d757062c5941fc4d19efda5f541547b2589d732313be3420275a8c618ce0ecfb62c22de04d7d9d5ef68a9eafcf
6
+ metadata.gz: 13327481eda4e0e601de696d572a4885ecbe2830bd4935b2cd648601cb93ff901bc89be7896b1a86a51265b924af9be41d8a16e840e2a2fb90780cdec4ff7f7a
7
+ data.tar.gz: 0f54c6edb6d86cce7dc8eb8b1628007575785c8ee6d51b25310fc537603bd18108550886f348fe55b3ce0407059f8df0400d08e418284e7194a059fe76d914ff
data/bezel-app.gemspec CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'bezel-app'
8
- spec.version = '0.0.7'
8
+ spec.version = '0.0.8'
9
9
  spec.authors = ['Keith Thompson']
10
10
  spec.email = ['KeithM_Thompson@outlook.com']
11
11
 
@@ -3,120 +3,122 @@ require_relative '../../lib/db_connection'
3
3
  require_relative 'associatable'
4
4
  require_relative 'searchable'
5
5
 
6
- class BezelrecordBase
7
- extend Associatable
8
- extend Searchable
9
-
10
- def self.columns
11
- unless @columns
12
- temp_columns = DBConnection.execute2(<<-SQL)
13
- SELECT
14
- *
15
- FROM
16
- #{table_name}
17
- SQL
18
- @columns = temp_columns.first.map { |column| column.to_sym }
6
+ module Bezel
7
+ class BezelrecordBase
8
+ extend Associatable
9
+ extend Searchable
10
+
11
+ def self.columns
12
+ unless @columns
13
+ temp_columns = DBConnection.execute2(<<-SQL)
14
+ SELECT
15
+ *
16
+ FROM
17
+ #{table_name}
18
+ SQL
19
+ @columns = temp_columns.first.map { |column| column.to_sym }
20
+ end
21
+ @columns
19
22
  end
20
- @columns
21
- end
22
23
 
23
- def self.finalize!
24
- columns.each do |column|
24
+ def self.finalize!
25
+ columns.each do |column|
25
26
 
26
- define_method("#{column}") do
27
- @attributes = self.attributes
28
- @attributes[column]
29
- end
27
+ define_method("#{column}") do
28
+ @attributes = self.attributes
29
+ @attributes[column]
30
+ end
30
31
 
31
- define_method("#{column}=") do |value|
32
- @attributes = self.attributes
33
- @attributes[column] = value
32
+ define_method("#{column}=") do |value|
33
+ @attributes = self.attributes
34
+ @attributes[column] = value
35
+ end
34
36
  end
35
37
  end
36
- end
37
38
 
38
- def self.table_name=(table_name)
39
- @table_name = table_name
40
- end
39
+ def self.table_name=(table_name)
40
+ @table_name = table_name
41
+ end
41
42
 
42
- def self.table_name
43
- @table_name || to_s.tableize
44
- end
43
+ def self.table_name
44
+ @table_name || to_s.tableize
45
+ end
45
46
 
46
- def self.all
47
- results = DBConnection.execute(<<-SQL)
48
- SELECT
49
- #{table_name}.*
50
- FROM
51
- #{table_name}
52
- SQL
53
- parse_all(results)
54
- end
47
+ def self.all
48
+ results = DBConnection.execute(<<-SQL)
49
+ SELECT
50
+ #{table_name}.*
51
+ FROM
52
+ #{table_name}
53
+ SQL
54
+ parse_all(results)
55
+ end
55
56
 
56
- def self.parse_all(results)
57
- objects = results.map do |object|
58
- self.new(object)
57
+ def self.parse_all(results)
58
+ objects = results.map do |object|
59
+ self.new(object)
60
+ end
59
61
  end
60
- end
61
62
 
62
- def self.find(id)
63
- object = DBConnection.execute(<<-SQL, id)
64
- SELECT
65
- *
66
- FROM
67
- #{table_name}
68
- WHERE
69
- id = ?
70
- LIMIT
71
- 1
72
- SQL
73
- nil || object.map {|obj| self.new(obj)}.first
74
- end
63
+ def self.find(id)
64
+ object = DBConnection.execute(<<-SQL, id)
65
+ SELECT
66
+ *
67
+ FROM
68
+ #{table_name}
69
+ WHERE
70
+ id = ?
71
+ LIMIT
72
+ 1
73
+ SQL
74
+ nil || object.map {|obj| self.new(obj)}.first
75
+ end
75
76
 
76
- def initialize(params = {})
77
- table_columns = self.class.columns
77
+ def initialize(params = {})
78
+ table_columns = self.class.columns
78
79
 
79
- params.each do |key, value|
80
- raise "unknown attribute '#{key}'" unless table_columns.include?(key.to_sym)
81
- send("#{key}=",value)
80
+ params.each do |key, value|
81
+ raise "unknown attribute '#{key}'" unless table_columns.include?(key.to_sym)
82
+ send("#{key}=",value)
83
+ end
82
84
  end
83
- end
84
85
 
85
- def attributes
86
- @attributes = @attributes || {}
87
- end
86
+ def attributes
87
+ @attributes = @attributes || {}
88
+ end
88
89
 
89
- def attribute_values
90
- table_cols = self.class.columns
91
- table_cols
92
- table_cols.map{ |col| self.send("#{col}")}
93
- end
90
+ def attribute_values
91
+ table_cols = self.class.columns
92
+ table_cols
93
+ table_cols.map{ |col| self.send("#{col}")}
94
+ end
94
95
 
95
- def insert
96
- columns = self.class.columns
96
+ def insert
97
+ columns = self.class.columns
97
98
 
98
- DBConnection.execute(<<-SQL, *attribute_values)
99
- INSERT INTO
100
- #{self.class.table_name} (#{columns.join(", ")})
101
- VALUES
102
- (#{Array.new(columns.length,"?").join(", ")})
103
- SQL
104
- self.send(:id=,DBConnection.last_insert_row_id)
105
- end
99
+ DBConnection.execute(<<-SQL, *attribute_values)
100
+ INSERT INTO
101
+ #{self.class.table_name} (#{columns.join(", ")})
102
+ VALUES
103
+ (#{Array.new(columns.length,"?").join(", ")})
104
+ SQL
105
+ self.send(:id=,DBConnection.last_insert_row_id)
106
+ end
106
107
 
107
- def update
108
- DBConnection.execute(<<-SQL,*attribute_values[1..-1], attribute_values.first)
109
- UPDATE
110
- #{self.class.table_name}
111
- SET
112
- #{self.class.columns[1..-1].map{|col| "#{col} = ?"}.join(", ")}
113
- WHERE
114
- id = ?
115
- SQL
108
+ def update
109
+ DBConnection.execute(<<-SQL,*attribute_values[1..-1], attribute_values.first)
110
+ UPDATE
111
+ #{self.class.table_name}
112
+ SET
113
+ #{self.class.columns[1..-1].map{|col| "#{col} = ?"}.join(", ")}
114
+ WHERE
115
+ id = ?
116
+ SQL
116
117
 
117
- end
118
+ end
118
119
 
119
- def save
120
- id.nil? ? insert : update
120
+ def save
121
+ id.nil? ? insert : update
122
+ end
121
123
  end
122
124
  end
data/lib/db_connection.rb CHANGED
@@ -4,7 +4,6 @@ require 'yaml'
4
4
  PRINT_QUERIES = ENV['PRINT_QUERIES'] == 'true'
5
5
  MIGRATIONS = Dir.glob('./db/migrate/*.sql').to_a
6
6
 
7
- module Bezel
8
7
  class DBConnection
9
8
  def self.app_name
10
9
  YAML.load_file(Dir.pwd + '/config/database.yml')['database']
@@ -114,4 +113,3 @@ module Bezel
114
113
  commands.each { |command| `#{command}` }
115
114
  end
116
115
  end
117
- end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bezel-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keith Thompson