storage_room 0.3.7 → 0.3.8
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.
- data/History.txt +3 -0
- data/VERSION +1 -1
- data/examples/search_entries.rb +11 -2
- data/lib/storage_room.rb +1 -0
- data/lib/storage_room/extensions/const_defined.rb +17 -8
- data/lib/storage_room/extensions/symbol.rb +91 -0
- data/lib/storage_room/models/entry.rb +10 -0
- data/spec/storage_room/extensions/symbol_spec.rb +15 -0
- data/spec/storage_room/models/entry_spec.rb +5 -5
- data/storage_room.gemspec +4 -2
- metadata +5 -3
data/History.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.8
|
data/examples/search_entries.rb
CHANGED
@@ -3,11 +3,20 @@
|
|
3
3
|
require File.join(File.dirname(__FILE__), 'authentication')
|
4
4
|
|
5
5
|
collection = StorageRoom::Collection.find('4dda7761b65245fde100005d')
|
6
|
+
Book = collection.entry_class
|
6
7
|
|
7
|
-
entries =
|
8
|
+
entries = Book.search(:title => 'Hitchhikers Guide to the Galaxy')
|
8
9
|
|
9
10
|
puts "Entries with title 'Hitchhikers Guide to the Galaxy':"
|
10
11
|
|
11
12
|
entries.resources.each do |entry|
|
12
13
|
puts "- #{entry.title} : #{entry[:@url]}"
|
13
|
-
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Some more example for searches
|
17
|
+
|
18
|
+
Book.search(:tags => ['fiction', 'future', 'novel']) # search for Books *with any* of these tags
|
19
|
+
Book.search(:tags.all => ['french', 'fiction']) # search for Books *with all* of these tags
|
20
|
+
Book.search(:tags.nin => ['german', 'chinese']) # search for Books *without any* of these tags
|
21
|
+
|
22
|
+
Book.find_by_urls('book_url1', 'book_url2', 'book_url3') # load multiple Books at once by their @url
|
data/lib/storage_room.rb
CHANGED
@@ -1,12 +1,21 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module StorageRoom
|
2
|
+
module Extensions
|
3
|
+
module ConstDefined
|
4
|
+
def is_constant_defined?(const)
|
5
|
+
if ::RUBY_VERSION =~ /1.9/
|
6
|
+
const_defined?(const, false)
|
7
|
+
else
|
8
|
+
const_defined?(const)
|
9
|
+
end
|
10
|
+
end
|
7
11
|
end
|
8
12
|
end
|
9
13
|
end
|
10
14
|
|
11
|
-
Object
|
12
|
-
|
15
|
+
class Object
|
16
|
+
include StorageRoom::Extensions::ConstDefined
|
17
|
+
end
|
18
|
+
|
19
|
+
class Module
|
20
|
+
include StorageRoom::Extensions::ConstDefined
|
21
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
module StorageRoom
|
4
|
+
module Extensions
|
5
|
+
|
6
|
+
# With inspiration from John Nunemaker's MongoMapper/Plucky
|
7
|
+
module Symbol
|
8
|
+
def gt
|
9
|
+
SymbolOperator.new(self, 'gt')
|
10
|
+
end
|
11
|
+
|
12
|
+
def lt
|
13
|
+
SymbolOperator.new(self, 'lt')
|
14
|
+
end
|
15
|
+
|
16
|
+
def gte
|
17
|
+
SymbolOperator.new(self, 'gte')
|
18
|
+
end
|
19
|
+
|
20
|
+
def lte
|
21
|
+
SymbolOperator.new(self, 'lte')
|
22
|
+
end
|
23
|
+
|
24
|
+
def ne
|
25
|
+
SymbolOperator.new(self, 'ne')
|
26
|
+
end
|
27
|
+
|
28
|
+
def in
|
29
|
+
SymbolOperator.new(self, 'in')
|
30
|
+
end
|
31
|
+
|
32
|
+
def nin
|
33
|
+
SymbolOperator.new(self, 'nin')
|
34
|
+
end
|
35
|
+
|
36
|
+
# def mod
|
37
|
+
# SymbolOperator.new(self, 'mod')
|
38
|
+
# end
|
39
|
+
|
40
|
+
def all
|
41
|
+
SymbolOperator.new(self, 'all')
|
42
|
+
end
|
43
|
+
|
44
|
+
# def size
|
45
|
+
# SymbolOperator.new(self, 'size')
|
46
|
+
# end unless Symbol.instance_methods.include?(:size) # Ruby 1.9 defines symbol size
|
47
|
+
|
48
|
+
# def exists
|
49
|
+
# SymbolOperator.new(self, 'exists')
|
50
|
+
# end
|
51
|
+
#
|
52
|
+
# def asc
|
53
|
+
# SymbolOperator.new(self, 'asc')
|
54
|
+
# end
|
55
|
+
#
|
56
|
+
# def desc
|
57
|
+
# SymbolOperator.new(self, 'desc')
|
58
|
+
# end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class SymbolOperator
|
64
|
+
include Comparable
|
65
|
+
|
66
|
+
attr_reader :field, :operator
|
67
|
+
|
68
|
+
def initialize(field, operator, options={})
|
69
|
+
@field, @operator = field, operator
|
70
|
+
end unless method_defined?(:initialize)
|
71
|
+
|
72
|
+
def <=>(other)
|
73
|
+
if field == other.field
|
74
|
+
operator <=> other.operator
|
75
|
+
else
|
76
|
+
field.to_s <=> other.field.to_s
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def ==(other)
|
81
|
+
field == other.field && operator == other.operator
|
82
|
+
end
|
83
|
+
|
84
|
+
def to_s
|
85
|
+
"#{field}!#{operator}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
class Symbol
|
90
|
+
include StorageRoom::Extensions::Symbol
|
91
|
+
end
|
@@ -23,6 +23,16 @@ module StorageRoom
|
|
23
23
|
def search(parameters = {})
|
24
24
|
Array.load(search_path(parameters))
|
25
25
|
end
|
26
|
+
|
27
|
+
# Find multiple Entries by their IDs with one query
|
28
|
+
def find_by_ids(*ids)
|
29
|
+
find_by_urls(*ids.map{|id| show_path(id)})
|
30
|
+
end
|
31
|
+
|
32
|
+
# Find multiple Entries by their URLs with one query
|
33
|
+
def find_by_urls(*urls)
|
34
|
+
search(:@url.in => urls)
|
35
|
+
end
|
26
36
|
end
|
27
37
|
|
28
38
|
# The collection of a entry
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'storage_room/extensions/symbol'
|
4
|
+
|
5
|
+
describe StorageRoom::Extensions::Symbol do
|
6
|
+
it "should transform a known symbol with operator to string" do
|
7
|
+
:something.in.to_s.should == 'something!in'
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should raise an error for an unknown operator" do
|
11
|
+
lambda {
|
12
|
+
:something.asdf
|
13
|
+
}.should raise_error(NoMethodError)
|
14
|
+
end
|
15
|
+
end
|
data/storage_room.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{storage_room}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.8"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Sascha Konietzke"]
|
12
|
-
s.date = %q{2011-07-
|
12
|
+
s.date = %q{2011-07-25}
|
13
13
|
s.description = %q{StorageRoom is a CMS system for Mobile Applications (iPhone, Android, BlackBerry, ...). This library gives you an ActiveModel-like interface to your data.}
|
14
14
|
s.email = %q{sascha@thriventures.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -63,6 +63,7 @@ Gem::Specification.new do |s|
|
|
63
63
|
"lib/storage_room/embeddeds/location.rb",
|
64
64
|
"lib/storage_room/embeddeds/webhook_definition.rb",
|
65
65
|
"lib/storage_room/extensions/const_defined.rb",
|
66
|
+
"lib/storage_room/extensions/symbol.rb",
|
66
67
|
"lib/storage_room/identity_map.rb",
|
67
68
|
"lib/storage_room/model.rb",
|
68
69
|
"lib/storage_room/models/collection.rb",
|
@@ -106,6 +107,7 @@ Gem::Specification.new do |s|
|
|
106
107
|
"spec/storage_room/embeddeds/image_version_spec.rb",
|
107
108
|
"spec/storage_room/embeddeds/location_spec.rb",
|
108
109
|
"spec/storage_room/embeddeds/webhook_definition_spec.rb",
|
110
|
+
"spec/storage_room/extensions/symbol_spec.rb",
|
109
111
|
"spec/storage_room/identity_map_spec.rb",
|
110
112
|
"spec/storage_room/model_spec.rb",
|
111
113
|
"spec/storage_room/models/collection_spec.rb",
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 8
|
9
|
+
version: 0.3.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Sascha Konietzke
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-07-
|
17
|
+
date: 2011-07-25 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -144,6 +144,7 @@ files:
|
|
144
144
|
- lib/storage_room/embeddeds/location.rb
|
145
145
|
- lib/storage_room/embeddeds/webhook_definition.rb
|
146
146
|
- lib/storage_room/extensions/const_defined.rb
|
147
|
+
- lib/storage_room/extensions/symbol.rb
|
147
148
|
- lib/storage_room/identity_map.rb
|
148
149
|
- lib/storage_room/model.rb
|
149
150
|
- lib/storage_room/models/collection.rb
|
@@ -187,6 +188,7 @@ files:
|
|
187
188
|
- spec/storage_room/embeddeds/image_version_spec.rb
|
188
189
|
- spec/storage_room/embeddeds/location_spec.rb
|
189
190
|
- spec/storage_room/embeddeds/webhook_definition_spec.rb
|
191
|
+
- spec/storage_room/extensions/symbol_spec.rb
|
190
192
|
- spec/storage_room/identity_map_spec.rb
|
191
193
|
- spec/storage_room/model_spec.rb
|
192
194
|
- spec/storage_room/models/collection_spec.rb
|