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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bf7b0ab42440cec12df54c647510bdfe07934a81
4
- data.tar.gz: 694de73764dba04bd1c15ef606e6a69d27130de9
3
+ metadata.gz: fba2db9ef800adb7a1f86e22f79fccf23cbab49c
4
+ data.tar.gz: 88882a312bb253395ea0992ab41cce3ac8439ee4
5
5
  SHA512:
6
- metadata.gz: bb52c2f45c1bb29a0d9e5df1feb783d4df50e818b0f94ec2b795fe87e22f9e50542714485feb407f23af50efea488e3dfed4c80da7329b995053e1a19065124b
7
- data.tar.gz: 162eb4ae53464c4bd247beef4a744c76856d115da73095b137e7585278d7995ba9756ac6558bf7cb8ebe1f3f69007abd2654652f158e56065e10bd4e442d91fe
6
+ metadata.gz: eda3731336d6b809fa7a0dde439a3dbdfa00aa3423dd27eeaf9087ea421ea2ab4d78f15eddd5f95c46feb03096235ab820f146a8b4fb9bb9c222dcf7f8576dac
7
+ data.tar.gz: 5936cf5ecf51cf3a9f674d9601bb790cb7f65aed502de4b444ab9ce46e7f2baed982fc06fe7cf0ff852b31b0e03130c4a78d0cd0b0df4358cec3cbbb1ce3a96e
data/README.md CHANGED
@@ -1,24 +1,93 @@
1
1
  # Cero
2
2
 
3
- TODO: Write a gem description
3
+ Cero contains building blocks for constructing ruby applications.
4
4
 
5
- ## Installation
5
+ ## Architecture
6
6
 
7
- Add this line to your application's Gemfile:
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
- gem 'cero'
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
- And then execute:
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
- $ bundle
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
- TODO: Write usage instructions here
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
 
@@ -52,6 +52,11 @@ module Cero
52
52
  raise Errors::AbstractMethodError
53
53
  end
54
54
 
55
+ private
56
+ def setup
57
+ # setup hook inside initialize for adapters
58
+ end
59
+
55
60
  end
56
61
  end
57
62
  end
@@ -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
- hash.empty? ? 1 : hash.keys.count + 1
64
+ @lock.synchronize do
65
+ hash.empty? ? 1 : hash.keys.count + 1
66
+ end
64
67
  end
65
68
  end
66
69
  end
@@ -7,7 +7,7 @@ module Cero
7
7
  MAJOR = 0
8
8
  MINOR = 0
9
9
  PATCH = 0
10
- PRE = nil
10
+ PRE = 1
11
11
  STRING = [MAJOR, MINOR, PATCH, PRE].compact.join('.').freeze
12
12
  end
13
13
  end
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-19 00:00:00.000000000 Z
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: