cero 0.0.0 → 0.0.0.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 +4 -4
- data/README.md +78 -9
- data/lib/cero/adapters/abstract_adapter.rb +5 -0
- data/lib/cero/adapters/memory_adapter.rb +4 -1
- data/lib/cero/version.rb +1 -1
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fba2db9ef800adb7a1f86e22f79fccf23cbab49c
|
4
|
+
data.tar.gz: 88882a312bb253395ea0992ab41cce3ac8439ee4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eda3731336d6b809fa7a0dde439a3dbdfa00aa3423dd27eeaf9087ea421ea2ab4d78f15eddd5f95c46feb03096235ab820f146a8b4fb9bb9c222dcf7f8576dac
|
7
|
+
data.tar.gz: 5936cf5ecf51cf3a9f674d9601bb790cb7f65aed502de4b444ab9ce46e7f2baed982fc06fe7cf0ff852b31b0e03130c4a78d0cd0b0df4358cec3cbbb1ce3a96e
|
data/README.md
CHANGED
@@ -1,24 +1,93 @@
|
|
1
1
|
# Cero
|
2
2
|
|
3
|
-
|
3
|
+
Cero contains building blocks for constructing ruby applications.
|
4
4
|
|
5
|
-
##
|
5
|
+
## Architecture
|
6
6
|
|
7
|
-
|
7
|
+
An *Entitiy* is little more than a dumb data structure. The only thing unique about it
|
8
|
+
is that an Entity must have an identity field - usually an :id attribute. This is used
|
9
|
+
for comparisons and persistance.
|
8
10
|
|
9
|
-
|
11
|
+
A *Repo* is a class that can be used to mapulate collections of Entities.
|
12
|
+
It knows nothing about persistance.
|
13
|
+
Its interface contains the following methods:
|
10
14
|
|
11
|
-
|
15
|
+
* create(entity)
|
16
|
+
* find(id)
|
17
|
+
* update(entity)
|
18
|
+
* delete(entity)
|
19
|
+
* save(entity)
|
20
|
+
* all
|
21
|
+
* first
|
22
|
+
* last
|
23
|
+
* count
|
24
|
+
* query(&block)
|
25
|
+
* clear
|
12
26
|
|
13
|
-
|
27
|
+
A *RepoQuery* is an interface for constucting complex queries against data in a Repo.
|
28
|
+
|
29
|
+
An *Collection* is a structural mapping that hooks all parts of the System together.
|
30
|
+
It assigns an Adapter to an Entity and a Repo, and sets up fields for type coercians and the peristance layer. For instance
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
Cero::Collections.setup do
|
34
|
+
collection :users do
|
35
|
+
entity User
|
36
|
+
adapter :sql
|
37
|
+
repo UserRepo
|
38
|
+
fields do
|
39
|
+
identity :uuid, String
|
40
|
+
attribute :username, String
|
41
|
+
attribute :email, String
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
collection :user_stats do
|
46
|
+
entity UserStat
|
47
|
+
adapter :redis
|
48
|
+
repo UserStatRepo
|
49
|
+
fields do
|
50
|
+
identity :id, Integer
|
51
|
+
attribute :user_id, Integer
|
52
|
+
attribute :last_login_at, DateTime
|
53
|
+
attribute :site_visits_count, Integer
|
54
|
+
attribute :karma, Float
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
```
|
14
59
|
|
15
|
-
Or install it yourself as:
|
16
60
|
|
17
|
-
$ gem install cero
|
18
61
|
|
19
62
|
## Usage
|
20
63
|
|
21
|
-
|
64
|
+
```ruby
|
65
|
+
class User
|
66
|
+
include Cero::Entity
|
67
|
+
attribute :username, String
|
68
|
+
attribute :email, String
|
69
|
+
attribute :confirmed, Boolean
|
70
|
+
end
|
71
|
+
|
72
|
+
class UserRepo
|
73
|
+
include Cero::Repo
|
74
|
+
|
75
|
+
def self.find_all_confirmed
|
76
|
+
query do
|
77
|
+
where(confirmed: true)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
user = User.new(email: "bob@bob.com", username: "bob")
|
83
|
+
UserRepo.create(user)
|
84
|
+
puts user.id # => 1
|
85
|
+
|
86
|
+
UserRepo.find(1) # => returns <User @email="bob@bob.com" @username="bob">
|
87
|
+
UserRepo.find_all_having_confirmed_of(true)
|
88
|
+
|
89
|
+
end
|
90
|
+
```
|
22
91
|
|
23
92
|
## Contributing
|
24
93
|
|
@@ -6,6 +6,7 @@ module Cero
|
|
6
6
|
super
|
7
7
|
@lock = Monitor.new
|
8
8
|
@collection[collection] = {}
|
9
|
+
setup
|
9
10
|
end
|
10
11
|
|
11
12
|
def create(collection, entity)
|
@@ -60,7 +61,9 @@ module Cero
|
|
60
61
|
|
61
62
|
private
|
62
63
|
def next_id_for(hash)
|
63
|
-
|
64
|
+
@lock.synchronize do
|
65
|
+
hash.empty? ? 1 : hash.keys.count + 1
|
66
|
+
end
|
64
67
|
end
|
65
68
|
end
|
66
69
|
end
|
data/lib/cero/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cero
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.0
|
4
|
+
version: 0.0.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Faucett
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -115,4 +115,3 @@ signing_key:
|
|
115
115
|
specification_version: 4
|
116
116
|
summary: Application Building Blocks
|
117
117
|
test_files: []
|
118
|
-
has_rdoc:
|