purzelrakete-restful 0.2.5 → 0.2.6

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/README.markdown CHANGED
@@ -36,6 +36,13 @@ restful_publish :name, :pets, :restful_options => { :force_expanded => [:pets, :
36
36
  # Pet
37
37
  restful_publish :name, :person # expands person per default because it is on the second level. Does not expand person.pets.first.person, since this is higher than second level.
38
38
 
39
+ Options
40
+ =======
41
+
42
+ You can add includes to your call like this:
43
+
44
+ pet.to_restful_json :include => :owner.
45
+
39
46
  Rails-like
40
47
  ==========
41
48
 
@@ -16,15 +16,15 @@ module Restful
16
16
  end
17
17
 
18
18
  def links
19
- values.select { |attribute| attribute.type == :link }
19
+ self.values.select { |attribute| attribute.type == :link }
20
20
  end
21
21
 
22
22
  def simple_attributes
23
- values.select { |attribute| attribute.type == :simple_attribute }
23
+ self.values.select { |attribute| attribute.type == :simple_attribute }
24
24
  end
25
25
 
26
26
  def collections
27
- values.select { |attribute| attribute.type == :collection }
27
+ self.values.select { |attribute| attribute.type == :collection }
28
28
  end
29
29
 
30
30
  # invoke serialization
@@ -36,6 +36,13 @@ module Restful
36
36
  # by passing in something like @pet.to_restful(:name, :species).
37
37
  #
38
38
  def to_restful(config = nil)
39
+ add_to_whitelist = []
40
+
41
+ if config && config.is_a?(Hash) && config.keys.size == 1 && includes = config[:include]
42
+ add_to_whitelist = [*includes]
43
+ config = nil
44
+ end
45
+
39
46
  config ||= self.class.restful_config if self.class.respond_to?(:restful_config)
40
47
  config ||= []
41
48
 
@@ -48,6 +55,8 @@ module Restful
48
55
  config.restful_options.merge! self.class.restful_config.restful_options
49
56
  end
50
57
 
58
+ config.whitelisted += add_to_whitelist
59
+
51
60
  # array
52
61
  if self.is_a?(Array)
53
62
  elements = self.map do |el|
data/restful.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "restful"
3
- s.version = "0.2.5"
3
+ s.version = "0.2.6"
4
4
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
5
5
  s.authors = ["Daniel Bornkessel", "Rany Keddo"]
6
6
  s.date = "2009-08-11"
@@ -27,10 +27,6 @@ context "Configuration" do
27
27
  config.nested(:two).whitelisted.should.== [:a,:b]
28
28
  end
29
29
 
30
- specify "should set restful options when set in to_restful method" do
31
-
32
- end
33
-
34
30
  specify "should know which attributes are published" do
35
31
  config = Restful.cfg(:one, :two => [:a, :b])
36
32
  config.published?(:two).should.== true
@@ -17,6 +17,16 @@ context "restful publish" do
17
17
  Person.restful_publish(:name, :pets => [:name, :species])
18
18
  Person.restful_config.restful_options.should.==({})
19
19
  end
20
+
21
+ specify "should include attributes when publishe parameter is passed to to_restful" do
22
+ Person.restful_publish(:name)
23
+ Pet.restful_publish(:name)
24
+
25
+ @person = Person.create
26
+ @pet = @person.pets.create(:name => "Mietze")
27
+
28
+ @pet.to_restful(:include => :owner).values.map(&:name).should.include :owner
29
+ end
20
30
  end
21
31
 
22
32
  context "api publishing with nesting" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: purzelrakete-restful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Bornkessel