flexible_api 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/flexible_api.rb +5 -1
- data/lib/flexible_api/request_level.rb +6 -1
- data/lib/flexible_api/version.rb +1 -1
- metadata +4 -4
data/lib/flexible_api.rb
CHANGED
@@ -42,7 +42,11 @@ module FlexibleApi
|
|
42
42
|
def find_all_hash(options = {})
|
43
43
|
options.assert_valid_keys(:request_level)
|
44
44
|
level = find_level(options[:request_level])
|
45
|
-
|
45
|
+
|
46
|
+
query = self
|
47
|
+
level.scopes.each { |s, args| query = query.send(s, *args) }
|
48
|
+
|
49
|
+
records = query.all(:select => level.select_field.join(', '), :include => level.include_field)
|
46
50
|
records.map { |r| level.receive(r) }
|
47
51
|
end
|
48
52
|
|
@@ -7,13 +7,14 @@ module FlexibleApi
|
|
7
7
|
@klass = klass
|
8
8
|
@display_fields = Set.new
|
9
9
|
@select_fields = Set.new
|
10
|
+
@scopes = []
|
10
11
|
@includes = []
|
11
12
|
@notations = {}
|
12
13
|
@eaten_levels = []
|
13
14
|
@select_fields << "`#{@klass.table_name}`.#{@klass.primary_key}" # auto-select primary key
|
14
15
|
end
|
15
16
|
|
16
|
-
attr_reader :display_fields, :name, :notations
|
17
|
+
attr_reader :display_fields, :name, :notations, :scopes
|
17
18
|
|
18
19
|
def to_hash
|
19
20
|
{
|
@@ -29,6 +30,10 @@ module FlexibleApi
|
|
29
30
|
@eaten_levels << @klass.find_level(name)
|
30
31
|
end
|
31
32
|
|
33
|
+
def scope(name, args)
|
34
|
+
@scopes << [name, args]
|
35
|
+
end
|
36
|
+
|
32
37
|
def notation(notation_name, options = {}, &block)
|
33
38
|
options.assert_valid_keys :requires
|
34
39
|
requires *options[:requires]
|
data/lib/flexible_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flexible_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 21
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 5
|
10
|
+
version: 0.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- John Crepezzi
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-03-
|
18
|
+
date: 2011-03-30 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|