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.
@@ -158,6 +158,7 @@ While I (Jeff Dean) wrote all of the code in this repo, the code was inspired by
158
158
 
159
159
  * Mike Dalessio
160
160
  * Peter Jaros
161
+ * Ben Woosely
161
162
 
162
163
  == Development
163
164
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.1
@@ -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.0"
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-07-05}
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.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
+
@@ -1,7 +1,5 @@
1
- require 'rubygems'
2
- require 'activesupport'
1
+ require 'active_support'
3
2
  require 'nokogiri'
4
-
5
3
  require 'uri'
6
4
 
7
5
  require 'active_api/builder'
@@ -8,8 +8,12 @@ module ActiveApi
8
8
  @fields = options[:fields] || []
9
9
  end
10
10
 
11
- def attribute(name, type = :string, options = {})
12
- field options.merge(:name => name, :type => type, :field_type => :attribute)
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 = {})
@@ -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 :title
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]").should be
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='']").should be
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
- :node => :article,
146
- :schema => @schema
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 :id, :value => proc {|element| "foo" }
158
- t.has_many :comments
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 :article_title, :value => proc{|element| element.object.article.title }
163
- t.belongs_to :user
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
- :node => :article,
185
- :schema => @schema
184
+ :node => :article,
185
+ :schema => @schema
186
186
  doc = element.build_xml.doc
187
- doc.xpath("/articles/article[@id=foo]").should be
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
- :node => :article,
193
- :schema => @schema
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
- :node => :article,
201
- :schema => @schema
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
- :node => :article,
209
- :schema => @schema
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
@@ -1,4 +1,5 @@
1
1
  require 'spec'
2
+ require 'spec/autorun'
2
3
 
3
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
4
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
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.0
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-07-05 00:00:00 -04:00
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.3
94
+ rubygems_version: 1.3.5
95
95
  signing_key:
96
96
  specification_version: 3
97
97
  summary: An api layer for ruby