active_api 0.1.0 → 0.2.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.
- data/README.rdoc +1 -0
- data/VERSION +1 -1
- data/active_api.gemspec +7 -3
- data/lib/active_api.rb +1 -3
- data/lib/active_api/definition.rb +6 -2
- data/spec/api_spec.rb +19 -19
- data/spec/spec_helper.rb +1 -0
- metadata +3 -3
data/README.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1
|
1
|
+
0.2.1
|
data/active_api.gemspec
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
1
4
|
# -*- encoding: utf-8 -*-
|
2
5
|
|
3
6
|
Gem::Specification.new do |s|
|
4
7
|
s.name = %q{active_api}
|
5
|
-
s.version = "0.1
|
8
|
+
s.version = "0.2.1"
|
6
9
|
|
7
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
11
|
s.authors = ["Jeff Dean"]
|
9
|
-
s.date = %q{2009-
|
12
|
+
s.date = %q{2009-12-02}
|
10
13
|
s.email = %q{jeff@zilkey.com}
|
11
14
|
s.extra_rdoc_files = [
|
12
15
|
"LICENSE",
|
@@ -42,7 +45,7 @@ Gem::Specification.new do |s|
|
|
42
45
|
s.homepage = %q{http://github.com/zilkey/active_api}
|
43
46
|
s.rdoc_options = ["--charset=UTF-8"]
|
44
47
|
s.require_paths = ["lib"]
|
45
|
-
s.rubygems_version = %q{1.3.
|
48
|
+
s.rubygems_version = %q{1.3.5}
|
46
49
|
s.summary = %q{An api layer for ruby}
|
47
50
|
s.test_files = [
|
48
51
|
"spec/active_api/complex_type_spec.rb",
|
@@ -71,3 +74,4 @@ Gem::Specification.new do |s|
|
|
71
74
|
s.add_dependency(%q<activesupport>, [">= 2.3.2"])
|
72
75
|
end
|
73
76
|
end
|
77
|
+
|
data/lib/active_api.rb
CHANGED
@@ -8,8 +8,12 @@ module ActiveApi
|
|
8
8
|
@fields = options[:fields] || []
|
9
9
|
end
|
10
10
|
|
11
|
-
def attribute(
|
12
|
-
|
11
|
+
def attribute(*args)
|
12
|
+
options = args.extract_options!
|
13
|
+
options[:type] ||= :string
|
14
|
+
options.merge! :name => args.first,
|
15
|
+
:field_type => :attribute
|
16
|
+
field options
|
13
17
|
end
|
14
18
|
|
15
19
|
def element(name, type = :string, options = {})
|
data/spec/api_spec.rb
CHANGED
@@ -41,7 +41,7 @@ module ActiveApi
|
|
41
41
|
before do
|
42
42
|
@schema = Schema.version(:v1) do |xsl|
|
43
43
|
xsl.define :article do |t|
|
44
|
-
t.string
|
44
|
+
t.string :title
|
45
45
|
end
|
46
46
|
end
|
47
47
|
@article = Article.new :title => Faker::Company.bs
|
@@ -107,7 +107,7 @@ module ActiveApi
|
|
107
107
|
end
|
108
108
|
element = Collection.new [@article], :node => :article, :schema => @schema
|
109
109
|
doc = element.build_xml.doc
|
110
|
-
doc.xpath("/articles/article[@published_on=1956-03-05]").
|
110
|
+
doc.xpath("/articles/article[@published_on='1956-03-05']").should_not be_empty
|
111
111
|
end
|
112
112
|
|
113
113
|
it "emits nil when the attribute value is nil" do
|
@@ -119,7 +119,7 @@ module ActiveApi
|
|
119
119
|
@article.published_on = nil
|
120
120
|
element = Collection.new [@article], :node => :article, :schema => @schema
|
121
121
|
doc = element.build_xml.doc
|
122
|
-
doc.xpath("/articles/article[@published_on='']").
|
122
|
+
doc.xpath("/articles/article[@published_on='']").should_not be_empty
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
@@ -142,8 +142,8 @@ module ActiveApi
|
|
142
142
|
end
|
143
143
|
|
144
144
|
element = Collection.new [@article],
|
145
|
-
|
146
|
-
|
145
|
+
:node => :article,
|
146
|
+
:schema => @schema
|
147
147
|
doc = element.build_xml.doc
|
148
148
|
doc.xpath("/articles/article/comments/comment/text").first.inner_text.should == @comment.text
|
149
149
|
end
|
@@ -153,14 +153,14 @@ module ActiveApi
|
|
153
153
|
before do
|
154
154
|
@schema = Schema.version(:v1) do |xsl|
|
155
155
|
xsl.define :article do |t|
|
156
|
-
t.attribute :id, :value => proc {|attribute| "foo" }
|
157
|
-
t.string
|
158
|
-
t.has_many
|
156
|
+
t.attribute :id, :value => proc {|attribute| "foo attribute" }
|
157
|
+
t.string :id, :value => proc {|element| "foo" }
|
158
|
+
t.has_many :comments
|
159
159
|
end
|
160
160
|
|
161
161
|
xsl.define :comment do |t|
|
162
|
-
t.string
|
163
|
-
t.belongs_to
|
162
|
+
t.string :article_title, :value => proc{|element| element.object.article.title }
|
163
|
+
t.belongs_to :user
|
164
164
|
end
|
165
165
|
|
166
166
|
xsl.define :user do |t|
|
@@ -181,32 +181,32 @@ module ActiveApi
|
|
181
181
|
|
182
182
|
it "emits the value of the value proc for attributes" do
|
183
183
|
element = Collection.new [@article1],
|
184
|
-
|
185
|
-
|
184
|
+
:node => :article,
|
185
|
+
:schema => @schema
|
186
186
|
doc = element.build_xml.doc
|
187
|
-
doc.xpath("/articles/article[@id=foo]").
|
187
|
+
doc.xpath("/articles/article[@id='foo attribute']").should_not be_empty
|
188
188
|
end
|
189
189
|
|
190
190
|
it "emits the value of the value proc for elements" do
|
191
191
|
element = Collection.new [@article1],
|
192
|
-
|
193
|
-
|
192
|
+
:node => :article,
|
193
|
+
:schema => @schema
|
194
194
|
doc = element.build_xml.doc
|
195
195
|
doc.xpath("/articles/article/id").first.inner_text.should == "foo"
|
196
196
|
end
|
197
197
|
|
198
198
|
it "emits the value of the value proc, which is passed an element containing a reference to the object" do
|
199
199
|
element = Collection.new [@article1],
|
200
|
-
|
201
|
-
|
200
|
+
:node => :article,
|
201
|
+
:schema => @schema
|
202
202
|
doc = element.build_xml.doc
|
203
203
|
doc.xpath("/articles/article/comments/comment/article_title").first.inner_text.should == @article1.title
|
204
204
|
end
|
205
205
|
|
206
206
|
it "emits the value of the value proc, which is passed an element containing a reference all ancestor objects" do
|
207
207
|
element = Collection.new [@article1, @article2],
|
208
|
-
|
209
|
-
|
208
|
+
:node => :article,
|
209
|
+
:schema => @schema
|
210
210
|
doc = element.build_xml.doc
|
211
211
|
doc.xpath("/articles/article").length.should == 2
|
212
212
|
doc.xpath("/articles/article/comments/comment/user/title").first.inner_text.should == @article1.title
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Dean
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-12-02 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
91
|
requirements: []
|
92
92
|
|
93
93
|
rubyforge_project:
|
94
|
-
rubygems_version: 1.3.
|
94
|
+
rubygems_version: 1.3.5
|
95
95
|
signing_key:
|
96
96
|
specification_version: 3
|
97
97
|
summary: An api layer for ruby
|