tads6_robert 0.3.0 → 1.0.0

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: 53fa95eeb15ed0086511712f9142ef0112ccf8929b8d33aa0e607620ea0a7173
4
- data.tar.gz: f3dcd96841ac4165cadd5974441edf1bb323c1a40955e3da4b883d4248981c5a
3
+ metadata.gz: 1a929114eee80a15675707b009d6f193b9837a3bf26dd33df3e1abe26dd914f9
4
+ data.tar.gz: d71a9b53e563b3fed371886cd8317864b2ca63861b96a05e47e47adbca52a3ba
5
5
  SHA512:
6
- metadata.gz: 63366f0787c6910cb24823f604c65ce057229a901a98952ad5e11cce8b7f7e3e10181b8e75b8899cb9b969a700f6bdd5959df2748d3612d25ac3b96a92fb3279
7
- data.tar.gz: 41d083a1d5a13118101fb3c0438c3191e9f7d724788e0676b5dc561e9c41115718101f20096eac783cad525c5b82eee6d176ec8729fc62f9f365f2f9bd71b179
6
+ metadata.gz: d39826afe2db10f2fac749b21d452bc0b2c1b946dd05a667cc3d2ceab19a88833a2d9b61adcde9bfe91492dc10ac0cfee145d80a6c60e88789721d06bd09e888
7
+ data.tar.gz: 555abe9d183cdbc6e098a8363117c824975f7e98290d3048d46798df223852ab1ef6cb3ac5e6ef73595d185502d41e8ff7788bf1c1fe26241471b0658f018515
@@ -0,0 +1,69 @@
1
+ module Tads6Robert
2
+ class ORM
3
+ def self.criar(*atributos)
4
+ id = proximo_id
5
+ File.open("#{path}/#{id}.yml", "a") do |arquivo|
6
+ obj = self.new atributos
7
+ obj.id = id
8
+ arquivo.puts YAML.dump obj
9
+ return id
10
+ end
11
+ end
12
+
13
+ def self.listar
14
+ @objs = []
15
+ $/ = '\n\n'
16
+
17
+ (1..ultimo_id).each do |id|
18
+ _path = "#{path}/#{id}.yml"
19
+ if File.exist?(_path)
20
+ File.open(_path, "r").each do |obj|
21
+ @objs << YAML.load(obj)
22
+ end
23
+ end
24
+ end
25
+
26
+ @objs
27
+ end
28
+
29
+ def self.selecionar(id)
30
+ listar.each do |obj|
31
+ return obj if obj.id == id
32
+ end
33
+ end
34
+
35
+ def self.atualizar(obj)
36
+ FileUtils.rm "#{path}/#{obj.id}.yml"
37
+ File.open("#{path}/#{obj.id}.yml", "a") do |arquivo|
38
+ arquivo.puts YAML.dump obj
39
+ return obj.id
40
+ end
41
+ end
42
+
43
+ def self.remove(id)
44
+ FileUtils.rm "#{path}/#{id}.yml"
45
+ return id
46
+ end
47
+
48
+ private
49
+
50
+ def self.quantidade_registros
51
+ Dir.glob("#{path}/*.yml").size + 1
52
+ end
53
+
54
+ def self.ultimo_id
55
+ files = Dir.entries("#{path}").sort_by do |file|
56
+ File.ctime("#{path}/#{file}")
57
+ end
58
+ File.basename("#{path}/#{files.last}", ".yml").to_i
59
+ end
60
+
61
+ def self.path
62
+ raise "implemente o método self.path com o caminho para seu banco de dados"
63
+ end
64
+
65
+ def self.proximo_id
66
+ ultimo_id.to_i + 1
67
+ end
68
+ end
69
+ end
@@ -1,3 +1,3 @@
1
1
  module Tads6Robert
2
- VERSION = "0.3.0"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/tads6_robert.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require "tads6_robert/version"
2
- require "tads6_robert/hello_world"
2
+ require "tads6_robert/ORM"
3
3
 
4
4
  module Tads6Robert
5
-
5
+
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tads6_robert
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Santos
@@ -71,7 +71,7 @@ files:
71
71
  - bin/console
72
72
  - bin/setup
73
73
  - lib/tads6_robert.rb
74
- - lib/tads6_robert/hello_world.rb
74
+ - lib/tads6_robert/ORM.rb
75
75
  - lib/tads6_robert/version.rb
76
76
  - tads6_robert.gemspec
77
77
  homepage: http://www.ifms.edu.br
@@ -1,7 +0,0 @@
1
- module Tads6Robert
2
- class HelloWorld
3
- def self.say(word)
4
- word
5
- end
6
- end
7
- end