epiphy 0.1.1 → 0.3.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 +4 -4
- data/README.md +21 -9
- data/lib/epiphy/adapter/rethinkdb.rb +0 -18
- data/lib/epiphy/entity/timestamp.rb +1 -1
- data/lib/epiphy/model.rb +2 -1
- data/lib/epiphy/repository.rb +26 -40
- data/lib/epiphy/repository/error.rb +16 -0
- data/lib/epiphy/repository/helper.rb +4 -1
- data/lib/epiphy/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 11a0712dc7095310eabf03b49c9e0ab1319eaa17
|
4
|
+
data.tar.gz: bb888733602a4e9df89ec5595e30ef636a5b8d80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef5d6dac3a225bd420e0f9c058d110f5a2234b087d1252b46b93bb5292a8e007a9488bc748b8fe272b3830c87a8f095ad2d26b676e9cb26d26cbbcd797acb04b
|
7
|
+
data.tar.gz: c57cd612e243ddbaabf6546168b6fdb3dc04e0aaf03da46c8d09c03adb1a860de297314e618f88fa20c297d784c4c3bcc66a43b83c5b87179cc746e5ae999836
|
data/README.md
CHANGED
@@ -1,13 +1,16 @@
|
|
1
|
-
# Epiphy
|
1
|
+
# Epiphy
|
2
2
|
|
3
|
-
|
3
|
+
A persistence framework for [RethinkDB](http://rethinkdb.com). The library is used on [phim365.today](http://phim365.today). Its API is based on Lotus::Model.
|
4
|
+
|
5
|
+
# Status
|
6
|
+
|
7
|
+
[](https://app.wercker.com/project/bykey/63dd458158948712a03a00d69a96f67b)
|
8
|
+
|
9
|
+
# Book [Simply RethinkDB](http://leanpub.com/simplyrethink)
|
4
10
|
|
5
11
|
I also write this book to practice RethinkDB. Please consider buying a
|
6
12
|
copy if you want to support the author.
|
7
13
|
|
8
|
-
# Introduction
|
9
|
-
|
10
|
-
A persistence framework for [RethinkDB](http://rethinkdb.com). The library is used on [phim365.today](http://phim365.today). Its API is based on Lotus::Model.
|
11
14
|
|
12
15
|
I love Lotus::Model so much because it's lightweight, does the job, no
|
13
16
|
magic. I also should fork Lotus and add RethinkDB adapter. However, I want
|
@@ -59,7 +62,19 @@ A testing database will be created during the testing. The testing data
|
|
59
62
|
will hit your RethinkDB. Depend on your storge system, test can fast or
|
60
63
|
slow.
|
61
64
|
|
62
|
-
#
|
65
|
+
# Usage
|
66
|
+
|
67
|
+
Entities
|
68
|
+
|
69
|
+
An object that is defined by its identity.
|
70
|
+
|
71
|
+
An entity is the core of an application, where the part of the domain logic is implemented. It's a small, cohesive object that expresses coherent and meaningful behaviors.
|
72
|
+
|
73
|
+
It deals with one and only one responsibility that is pertinent to the domain of the application, without caring about details such as persistence or validations.
|
74
|
+
|
75
|
+
This simplicity of design allows developers to focus on behaviors, or message passing if you will, which is the quintessence of Object Oriented Programming.
|
76
|
+
|
77
|
+
# Usage
|
63
78
|
|
64
79
|
```ruby
|
65
80
|
connection = Epiphy::Connection.create
|
@@ -88,9 +103,6 @@ movie = Movie.new
|
|
88
103
|
movie.title = "A movie"
|
89
104
|
MovieRepository.create movie
|
90
105
|
MovieRepository.update movie
|
91
|
-
|
92
|
-
|
93
|
-
|
94
106
|
```
|
95
107
|
|
96
108
|
# Contributing to epiphy
|
@@ -320,24 +320,6 @@ module Epiphy
|
|
320
320
|
|
321
321
|
end
|
322
322
|
|
323
|
-
private
|
324
|
-
def _find(collection, id)
|
325
|
-
identity = _identity(collection)
|
326
|
-
query(collection).where(identity => _id(collection, identity, id))
|
327
|
-
end
|
328
|
-
|
329
|
-
def _first(query)
|
330
|
-
query.limit(1).first
|
331
|
-
end
|
332
|
-
|
333
|
-
def _identity(collection)
|
334
|
-
_mapped_collection(collection).identity
|
335
|
-
end
|
336
|
-
|
337
|
-
def _id(collection, column, value)
|
338
|
-
_mapped_collection(collection).deserialize_attribute(column, value)
|
339
|
-
end
|
340
|
-
|
341
323
|
protected
|
342
324
|
|
343
325
|
# Return a ReQL wrapper of a table to start query chaining.
|
data/lib/epiphy/model.rb
CHANGED
data/lib/epiphy/repository.rb
CHANGED
@@ -66,11 +66,9 @@ module Epiphy
|
|
66
66
|
#
|
67
67
|
# * Isolates the persistence logic at a low level
|
68
68
|
#
|
69
|
-
# Epiphy::Model is shipped with
|
70
|
-
#
|
71
|
-
# * SqlAdapter
|
72
|
-
# * MemoryAdapter
|
69
|
+
# Epiphy::Model is shipped with adapter:
|
73
70
|
#
|
71
|
+
# * RethinkDB
|
74
72
|
#
|
75
73
|
#
|
76
74
|
# All the queries and commands are private.
|
@@ -161,8 +159,24 @@ module Epiphy
|
|
161
159
|
end
|
162
160
|
|
163
161
|
def get_config
|
162
|
+
if @config.nil?
|
163
|
+
auto_config
|
164
|
+
end
|
164
165
|
@config
|
165
166
|
end
|
167
|
+
|
168
|
+
# Auto configure with default RethinkDB setting. 127.0.0.1, 28015, plain
|
169
|
+
# auth key.
|
170
|
+
#
|
171
|
+
# With this design, people can just drop in and start using it without
|
172
|
+
# worry about setting up and configure.
|
173
|
+
# @since 0.3.0
|
174
|
+
# @api private
|
175
|
+
private def auto_config
|
176
|
+
Epiphy::Repository.configure do |config|
|
177
|
+
config.adapter = Epiphy::Adapter::Rethinkdb.new connection, database: 'test'
|
178
|
+
end
|
179
|
+
end
|
166
180
|
end
|
167
181
|
|
168
182
|
# Inject the public API into the hosting class.
|
@@ -203,8 +217,11 @@ module Epiphy
|
|
203
217
|
# FilmRepository.collection = 'Movie'
|
204
218
|
#
|
205
219
|
def self.included(base)
|
206
|
-
#config = self.get_config
|
207
220
|
config = Epiphy::Repository.get_config
|
221
|
+
|
222
|
+
raise Epiphy::Repository::NotConfigureError if config.nil?
|
223
|
+
raise Epiphy::Repository::MissingAdapterError if config.adapter.nil?
|
224
|
+
|
208
225
|
base.class_eval do
|
209
226
|
extend ClassMethods
|
210
227
|
include Lotus::Utils::ClassAttribute
|
@@ -475,6 +492,10 @@ module Epiphy
|
|
475
492
|
# ArticleRepository.find(9) # => raises Epiphy::Model::EntityNotFound
|
476
493
|
def find(id)
|
477
494
|
entity_id = id
|
495
|
+
if id.is_a? Epiphy::Entity
|
496
|
+
raise TypeError, "Expecting an string, primitve value"
|
497
|
+
end
|
498
|
+
|
478
499
|
if !id.is_a? String
|
479
500
|
raise Epiphy::Model::EntityIdNotFound, "Missing entity id" if !id.respond_to?(:to_s)
|
480
501
|
entity_id = id.to_s
|
@@ -687,41 +708,6 @@ module Epiphy
|
|
687
708
|
end
|
688
709
|
|
689
710
|
|
690
|
-
# Negates the filtering conditions of a given query with the logical
|
691
|
-
# opposite operator.
|
692
|
-
#
|
693
|
-
# This is only supported by the SqlAdapter.
|
694
|
-
#
|
695
|
-
# @param query [Object] a query
|
696
|
-
#
|
697
|
-
# @return a negated query, the type depends on the current adapter
|
698
|
-
#
|
699
|
-
# @api public
|
700
|
-
# @since 0.1.0
|
701
|
-
#
|
702
|
-
# @see Epiphy::Model::Adapters::Sql::Query#negate!
|
703
|
-
#
|
704
|
-
# @example
|
705
|
-
# require 'epiphy/model'
|
706
|
-
#
|
707
|
-
# class ProjectRepository
|
708
|
-
# include Epiphy::Repository
|
709
|
-
#
|
710
|
-
# def self.cool
|
711
|
-
# query do
|
712
|
-
# where(language: 'ruby')
|
713
|
-
# end
|
714
|
-
# end
|
715
|
-
#
|
716
|
-
# def self.not_cool
|
717
|
-
# exclude cool
|
718
|
-
# end
|
719
|
-
# end
|
720
|
-
def exclude(query)
|
721
|
-
query.negate!
|
722
|
-
query
|
723
|
-
end
|
724
|
-
|
725
711
|
# Determine colleciton/table name of this repository. Note that the
|
726
712
|
# repository name has to be the model name, appending Repository
|
727
713
|
#
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Epiphy
|
2
|
+
module Repository
|
3
|
+
# Not configure exception
|
4
|
+
#
|
5
|
+
# This error will be raised when the repository didn't get configured yet.
|
6
|
+
# @since 0.2.0
|
7
|
+
# @api public
|
8
|
+
class NotConfigureError < ::StandardError
|
9
|
+
|
10
|
+
end
|
11
|
+
class MissingAdapterError < ::StandardError
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -1,5 +1,9 @@
|
|
1
1
|
module Epiphy
|
2
2
|
module Repository
|
3
|
+
# Give repository useful helper class to query data.
|
4
|
+
# Only support `find_by` at this moment.
|
5
|
+
#
|
6
|
+
#
|
3
7
|
module Helper
|
4
8
|
|
5
9
|
# Find the first record matching the
|
@@ -21,7 +25,6 @@ module Epiphy
|
|
21
25
|
end
|
22
26
|
end
|
23
27
|
|
24
|
-
#private :where, :desc#, :exlude
|
25
28
|
end
|
26
29
|
end
|
27
30
|
end
|
data/lib/epiphy/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: epiphy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vinh
|
@@ -71,10 +71,11 @@ files:
|
|
71
71
|
- lib/epiphy/repository.rb
|
72
72
|
- lib/epiphy/repository/configuration.rb
|
73
73
|
- lib/epiphy/repository/cursor.rb
|
74
|
+
- lib/epiphy/repository/error.rb
|
74
75
|
- lib/epiphy/repository/helper.rb
|
75
76
|
- lib/epiphy/scheme.rb
|
76
77
|
- lib/epiphy/version.rb
|
77
|
-
homepage: http://rubygems.org/gems/
|
78
|
+
homepage: http://rubygems.org/gems/epiphy
|
78
79
|
licenses:
|
79
80
|
- MIT
|
80
81
|
metadata: {}
|