jails 0.1.0 → 0.1.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: f53ada8cf3d1d775d9f47993c8139a883211f4ab
4
- data.tar.gz: ea8af3753aea35be1c8a300f99b81c56a9ba776e
3
+ metadata.gz: 8dcea83b5e40d0d4bee233158e6f3e2b40dc12c2
4
+ data.tar.gz: ecbe81fc22f054350751e27c2c7fecf96fc9e90c
5
5
  SHA512:
6
- metadata.gz: 7024db4c3466b3f4f2f0b23257db233155b6ca586f6e256a269bd46ddfa846c5ea3a9e36feccff5e15d25ca01e0f0d7dad5d59ebb14155862d13bcc0f076d163
7
- data.tar.gz: '0483d20143deba21b48bd844eae76cfb80307b1a017aaac9bb61c19592fd6236a113cde9609771f85ab3b73a170041a9b5e488070525b3ee604bdf6d39c38370'
6
+ metadata.gz: 4ea9ca42c4621dfa0739dd63bc34c002494f600bee9d12df324e5bd2e9d84a332f4d1e1678436f61678f3494c56755daf0b00e0d605c32b056f1d9c9f4d410dd
7
+ data.tar.gz: e15299620ddae8c32efbf58c8cf98f57967caadd457f710e28975907a834f7ad5c6fadb19ec198c7dc2f3cf8af6246dc056b29cf4ce2479b636d9d7a3d006c95
@@ -1,5 +1,5 @@
1
1
  class Controller
2
- include Support
2
+ include(Support)
3
3
 
4
4
  # Set request object as an attribute accessible with @request variable.
5
5
  def initialize(request)
@@ -51,7 +51,7 @@ class Controller
51
51
  end
52
52
 
53
53
  # Set cookie with parameter key:value, then redirect back.
54
- def set_new_cookie(key, value)
54
+ def set_cookie(key, value)
55
55
  Rack::Response.new do |response|
56
56
  response.set_cookie(key, value)
57
57
  response.redirect(@request.referer || @request.path)
@@ -59,9 +59,9 @@ class Controller
59
59
  end
60
60
 
61
61
  # Delete cookie with parameter key and redirect back.
62
- def delete_the_cookie(key)
62
+ def delete_cookie(key)
63
63
  Rack::Response.new do |response|
64
- response.delete_cookie("greet")
64
+ response.delete_cookie(key)
65
65
  response.redirect(@request.referer || @request.path)
66
66
  end
67
67
  end
@@ -2,7 +2,10 @@ require "sqlite3"
2
2
 
3
3
  # Simplistic ORM library using the Active Record pattern
4
4
  module HacktiveRecord
5
+
5
6
  class Base
7
+ # extend(Support)
8
+
6
9
  DB = SQLite3::Database.new("db/development.sqlite3")
7
10
 
8
11
  # Return table name string by transforming the model class's name to lower case plural.
@@ -20,12 +23,15 @@ module HacktiveRecord
20
23
  # Return number of rows by executing a count query on the database for the resource.
21
24
  def self.count
22
25
  rows_count = DB.execute("SELECT COUNT(*) FROM #{table}")[0][0]
26
+ puts("\s #{self} SQL Statement: ".cyan.bold + "SELECT COUNT(*) FROM #{table}".blue.bold)
23
27
  return rows_count
24
28
  end
25
29
 
26
30
  # Return array of all rows in queried from the database table, converted to objects of the resource.
27
31
  def self.all
28
32
  rows = DB.execute("SELECT * FROM #{table}")
33
+ # puts(blue("\s #{self} SQL Statement: SELECT * FROM #{table}"))
34
+ puts("\s #{self} SQL Statement: ".cyan.bold + "SELECT * FROM #{table}".blue.bold)
29
35
  objects = rows.map do |row|
30
36
  attributes = Hash[columns.zip(row)]
31
37
  self.new(attributes)
@@ -35,7 +41,8 @@ module HacktiveRecord
35
41
 
36
42
  # Return an object by querying the database for the requested row searching by id.
37
43
  def self.find(id)
38
- row = DB.execute("SELECT * FROM #{table} WHERE id = ? LIMIT 1", id).first
44
+ row = DB.execute("SELECT * FROM #{table} WHERE id = ? LIMIT 1", id).first
45
+ puts("\s #{self} SQL Statement: ".cyan.bold + "SELECT * FROM #{table} WHERE id = #{id} LIMIT 1".blue.bold)
39
46
  attributes = Hash[columns.zip(row)]
40
47
  object = self.new(attributes)
41
48
  return object
@@ -50,6 +57,7 @@ module HacktiveRecord
50
57
  values = columns.map { |key| self.send(key) }
51
58
  columns = columns.join(",")
52
59
  DB.execute("INSERT INTO #{self.class.table} (#{columns}) VALUES (#{placeholders})", values)
60
+ puts("\s #{self.class} SQL Statement: ".cyan.bold + "INSERT INTO #{self.class.table} (#{columns}) VALUES (#{placeholders})".blue.bold + values.to_s)
53
61
  new_object.id = DB.execute("SELECT last_insert_rowid()")[0][0]
54
62
  return new_object
55
63
  end
@@ -61,11 +69,13 @@ module HacktiveRecord
61
69
  values = attributes.values
62
70
  values << id
63
71
  DB.execute("UPDATE #{self.class.table} SET #{columns} WHERE id = ?", values)
72
+ puts("\s #{self.class} SQL Statement: ".cyan.bold + "UPDATE #{self.class.table} SET #{columns} WHERE id = ?".blue.bold + values.to_s)
64
73
  end
65
74
 
66
75
  # Delete row from database.
67
76
  def destroy
68
77
  DB.execute("DELETE FROM #{self.class.table} WHERE id = ?", id)
78
+ puts("\s #{self.class} SQL Statement: ".cyan.bold + "DELETE FROM #{self.class.table} WHERE id = #{id}".blue.bold)
69
79
  end
70
80
  end
71
81
  end
@@ -1,8 +1,46 @@
1
1
  module Support
2
+
2
3
  # Transform string, downcase all words, capitalize each not on list, capitalize first word.
3
4
  def titleize(string)
4
- words_not_to_capitalize = ["the","a","an","and","but","for","of","to","at","by","from"]
5
- s = string.split.each{|word| word.capitalize! unless words_not_to_capitalize.include? (word.downcase) }
6
- s[0].capitalize + " " + s[1..-1].join(" ")
5
+ do_not_capitalize = ["the","a","an","and","but","or","nor","for","of","to","at","by","from","in","on"]
6
+ array = string.split.each do |word|
7
+ if do_not_capitalize.include?(word.downcase)
8
+ word.downcase!
9
+ else
10
+ word.capitalize!
11
+ end
12
+ end
13
+ array[0].capitalize + " " + array[1..-1].join(" ")
14
+ end
15
+
16
+ # Return count and word properly pluralized.
17
+ def pluralize(count, singular, plural)
18
+ if count == 1
19
+ count.to_s + " " + singular
20
+ else
21
+ count.to_s + " " + plural
22
+ end
23
+ end
24
+
25
+ # Colorize UNIX output - blue
26
+ def blue(string)
27
+ "\e[34m#{string}\e[0m"
7
28
  end
8
29
  end
30
+
31
+ class String
32
+ # colorize UNIX output cyan
33
+ def cyan
34
+ "\e[36m#{self}\e[0m"
35
+ end
36
+
37
+ # colorize UNIX output blue
38
+ def blue
39
+ "\e[34m#{self}\e[0m"
40
+ end
41
+
42
+ # bold UNIX output
43
+ def bold
44
+ "\e[1m#{self}\e[22m"
45
+ end
46
+ end
@@ -1,3 +1,3 @@
1
1
  module Jails
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: jails
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
  - Steve Carey
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-02-20 00:00:00.000000000 Z
11
+ date: 2018-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler