mikejones-reposit 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +1 -0
- data/README +1 -0
- data/lib/reposit.rb +7 -0
- data/lib/reposit/repository.rb +84 -0
- data/lib/reposit/storable.rb +20 -0
- data/reposit.gemspec +20 -0
- metadata +64 -0
data/COPYING
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
wasever
|
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
vasever
|
data/lib/reposit.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
module Repository
|
2
|
+
|
3
|
+
def initialize
|
4
|
+
class_name = self.class.name.split("::").last
|
5
|
+
@table_name = class_name.underscore.to_sym
|
6
|
+
@columns = ds.columns!
|
7
|
+
@domain_class = self.class.const_get(class_name.singularize)
|
8
|
+
end
|
9
|
+
|
10
|
+
def ds ; Repository.db[@table_name] end
|
11
|
+
|
12
|
+
def self.db=(database)
|
13
|
+
@database = database
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.db
|
17
|
+
@database ||= Sequel.sqlite
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.configure(database_dot_yaml_path, env)
|
21
|
+
db_config = YAML.load_file(database_dot_yaml_path)
|
22
|
+
self.db = Sequel.connect(db_config[env])
|
23
|
+
end
|
24
|
+
|
25
|
+
def get(pk)
|
26
|
+
self.find_one(:id => pk)
|
27
|
+
end
|
28
|
+
|
29
|
+
def all
|
30
|
+
query = ds
|
31
|
+
query.row_proc = row_proc
|
32
|
+
query.all
|
33
|
+
end
|
34
|
+
|
35
|
+
def delete(opts={})
|
36
|
+
ds.filter(opts).delete
|
37
|
+
end
|
38
|
+
|
39
|
+
def put(entry)
|
40
|
+
before_put(entry)
|
41
|
+
hash = @columns.inject({}) do |h, c|
|
42
|
+
h[c] = entry.send(c)
|
43
|
+
h
|
44
|
+
end
|
45
|
+
entry.new? ? entry.id = ds << hash : ds.filter(:id => entry.id).update(hash)
|
46
|
+
after_put(entry)
|
47
|
+
entry
|
48
|
+
end
|
49
|
+
|
50
|
+
def first
|
51
|
+
query = ds
|
52
|
+
query.row_proc = row_proc
|
53
|
+
query.first
|
54
|
+
end
|
55
|
+
|
56
|
+
def find_one(opts)
|
57
|
+
query = ds.filter(opts)
|
58
|
+
query.row_proc = self.row_proc
|
59
|
+
query.first
|
60
|
+
end
|
61
|
+
|
62
|
+
def find(opts)
|
63
|
+
query = ds.filter(opts)
|
64
|
+
query.row_proc = self.row_proc
|
65
|
+
query.all
|
66
|
+
end
|
67
|
+
|
68
|
+
def count ; ds.count end
|
69
|
+
|
70
|
+
def exists?(opts={})
|
71
|
+
!!ds.filter(opts).first
|
72
|
+
end
|
73
|
+
|
74
|
+
def row_proc
|
75
|
+
proc do |h|
|
76
|
+
entry = @domain_class.new
|
77
|
+
h.each { |k, v| entry.send("#{k}=", v) }
|
78
|
+
entry
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def after_put(entry);end
|
83
|
+
def before_put(entry);end
|
84
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Storable
|
2
|
+
attr_accessor :id
|
3
|
+
|
4
|
+
def new? ; !id end
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def assemble(opts={})
|
8
|
+
domain_class = self.new
|
9
|
+
opts.each do |k,v|
|
10
|
+
domain_class.send("#{k}=", v) if domain_class.respond_to?(k)
|
11
|
+
end
|
12
|
+
domain_class
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.included(receiver)
|
17
|
+
receiver.extend ClassMethods
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/reposit.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
GEMSPEC =Gem::Specification.new do |s|
|
2
|
+
s.name = 'reposit'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.platform = Gem::Platform::RUBY
|
5
|
+
s.rubyforge_project = "reposit"
|
6
|
+
s.summary, s.description = 'ruby sequel repositories'
|
7
|
+
s.authors = 'Mike Jones, George Malamidis'
|
8
|
+
s.email = 'george@nutrun.com'
|
9
|
+
s.has_rdoc = false
|
10
|
+
s.rdoc_options += ['--quiet', '--title', 'reposit', '--main', 'README']
|
11
|
+
s.extra_rdoc_files = ['README', 'COPYING']
|
12
|
+
s.files = [
|
13
|
+
"README",
|
14
|
+
"COPYING",
|
15
|
+
"reposit.gemspec",
|
16
|
+
"lib/reposit.rb",
|
17
|
+
"lib/reposit/repository.rb",
|
18
|
+
"lib/reposit/storable.rb",
|
19
|
+
]
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mikejones-reposit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Jones, George Malamidis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-16 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: george@nutrun.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README
|
24
|
+
- COPYING
|
25
|
+
files:
|
26
|
+
- README
|
27
|
+
- COPYING
|
28
|
+
- reposit.gemspec
|
29
|
+
- lib/reposit.rb
|
30
|
+
- lib/reposit/repository.rb
|
31
|
+
- lib/reposit/storable.rb
|
32
|
+
has_rdoc: false
|
33
|
+
homepage:
|
34
|
+
licenses:
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options:
|
37
|
+
- --quiet
|
38
|
+
- --title
|
39
|
+
- reposit
|
40
|
+
- --main
|
41
|
+
- README
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project: reposit
|
59
|
+
rubygems_version: 1.3.5
|
60
|
+
signing_key:
|
61
|
+
specification_version: 2
|
62
|
+
summary: ruby sequel repositories
|
63
|
+
test_files: []
|
64
|
+
|