fap 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Manifest.txt +1 -1
- data/README.rdoc +2 -2
- data/lib/fap.rb +2 -2
- data/lib/fap/collection.rb +1 -1
- data/lib/fap/mixins/properties.rb +1 -1
- data/lib/fap/mixins/relations.rb +4 -4
- data/lib/fap/{fap.rb → paw.rb} +4 -4
- data/lib/fap/property.rb +1 -1
- data/spec/fap_spec.rb +7 -7
- metadata +3 -3
data/Manifest.txt
CHANGED
data/README.rdoc
CHANGED
@@ -18,7 +18,7 @@ acronym. :)
|
|
18
18
|
|
19
19
|
== SYNOPSIS:
|
20
20
|
|
21
|
-
class Atom < FAP::
|
21
|
+
class Atom < FAP::Paw
|
22
22
|
string :title, :xpath => '//feed/title'
|
23
23
|
uri :url, :xpath => '//feed/link[@rel="self"]', :get => :href
|
24
24
|
date :updated, :xpath => '//feed/updated'
|
@@ -26,7 +26,7 @@ acronym. :)
|
|
26
26
|
has_many :articles, :class => 'Article', :xpath => '//feed/entry'
|
27
27
|
end
|
28
28
|
|
29
|
-
class Article < FAP::
|
29
|
+
class Article < FAP::Paw
|
30
30
|
string :title # It is assumed here, that you want a string mapped on a <title> element
|
31
31
|
uri :url, :xpath => 'link[@rel="alternate"]', :get => :href # Fetch the :href attribute
|
32
32
|
string :content
|
data/lib/fap.rb
CHANGED
@@ -4,9 +4,9 @@ $:.unshift(File.dirname(__FILE__)) unless
|
|
4
4
|
require 'nokogiri'
|
5
5
|
|
6
6
|
module FAP
|
7
|
-
VERSION = '0.0.
|
7
|
+
VERSION = '0.0.3'
|
8
8
|
|
9
|
-
autoload :
|
9
|
+
autoload :Paw, 'fap/paw'
|
10
10
|
autoload :Property, 'fap/property'
|
11
11
|
autoload :Relation, 'fap/relation'
|
12
12
|
autoload :Mixins, 'fap/mixins'
|
data/lib/fap/collection.rb
CHANGED
@@ -35,7 +35,7 @@ module FAP
|
|
35
35
|
opts = {}
|
36
36
|
opts.merge!(:type => args.shift) if args[0].class == String
|
37
37
|
opts.merge!(*args) unless args.empty?
|
38
|
-
property =
|
38
|
+
property = FAP::Property.new name, opts
|
39
39
|
self.properties << property
|
40
40
|
define_property_getter property
|
41
41
|
end
|
data/lib/fap/mixins/relations.rb
CHANGED
@@ -17,7 +17,7 @@ module FAP
|
|
17
17
|
# Load a relation by its nane
|
18
18
|
#
|
19
19
|
# @return [FAP::Collection] for "has_many" relations
|
20
|
-
# @return [FAP::
|
20
|
+
# @return [FAP::Paw] "father" object for "belongs_to" relations
|
21
21
|
def _load_relation name
|
22
22
|
relation = self.relations.select { |rel| rel.name == name }.first
|
23
23
|
if relation.type == :has_many
|
@@ -31,7 +31,7 @@ module FAP
|
|
31
31
|
|
32
32
|
def _load_has_many relation
|
33
33
|
relation.from = self
|
34
|
-
|
34
|
+
FAP::Collection.new relation, @_node
|
35
35
|
end
|
36
36
|
|
37
37
|
def _load_belongs_to relation
|
@@ -45,7 +45,7 @@ module FAP
|
|
45
45
|
#
|
46
46
|
def has_many name, opts={}
|
47
47
|
opts.merge! :type => :has_many, :from => self
|
48
|
-
relation =
|
48
|
+
relation = FAP::Relation.new name, opts
|
49
49
|
self.relations << relation
|
50
50
|
define_relation_getter relation
|
51
51
|
end
|
@@ -55,7 +55,7 @@ module FAP
|
|
55
55
|
#
|
56
56
|
def belongs_to name, opts={}
|
57
57
|
opts.merge! :type => :belongs_to, :from => self
|
58
|
-
relation =
|
58
|
+
relation = FAP::Relation.new name, opts
|
59
59
|
self.relations << relation
|
60
60
|
define_relation_getter relation
|
61
61
|
end
|
data/lib/fap/{fap.rb → paw.rb}
RENAMED
@@ -1,11 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
module FAP
|
4
|
-
class
|
4
|
+
class Paw
|
5
5
|
|
6
6
|
def self.inherited subclass
|
7
|
-
subclass.send :include,
|
8
|
-
subclass.send :include,
|
7
|
+
subclass.send :include, FAP::Mixins::Properties
|
8
|
+
subclass.send :include, FAP::Mixins::Relations
|
9
9
|
subclass.class_eval <<-EOS, __FILE__, __LINE__ + 1
|
10
10
|
def self.inherited subclass
|
11
11
|
super
|
@@ -27,7 +27,7 @@ module FAP
|
|
27
27
|
# @see FAP::Collection
|
28
28
|
# @param [FAP::Relation] Object relation
|
29
29
|
# @param [Nokogiri::XML::Element] starting node
|
30
|
-
# @retun [FAP::
|
30
|
+
# @retun [FAP::Paw]
|
31
31
|
def from_relation relation, node
|
32
32
|
relation.from.class
|
33
33
|
owners = self.relations.select { |rel| rel.type == :belongs_to && rel.klass == relation.from.class.to_s }
|
data/lib/fap/property.rb
CHANGED
data/spec/fap_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
|
|
2
2
|
|
3
3
|
describe "a very light FAP" do
|
4
4
|
before :all do
|
5
|
-
class Foo < FAP::
|
5
|
+
class Foo < FAP::Paw ; end
|
6
6
|
end
|
7
7
|
|
8
8
|
it "should define #properties #accessor" do
|
@@ -18,7 +18,7 @@ end
|
|
18
18
|
|
19
19
|
describe "a very light FAP with properties" do
|
20
20
|
before :all do
|
21
|
-
class Foo < FAP::
|
21
|
+
class Foo < FAP::Paw
|
22
22
|
property :str_name
|
23
23
|
property :str_prop, 'String'
|
24
24
|
property :xpath_prop, 'Fixnum', :xpath => '//foobar'
|
@@ -60,11 +60,11 @@ end
|
|
60
60
|
|
61
61
|
describe "a FAP with some relations" do
|
62
62
|
before :all do
|
63
|
-
class Foo < FAP::
|
63
|
+
class Foo < FAP::Paw
|
64
64
|
has_many :bars, :class => 'Bar', :xpath => '//foo/bars'
|
65
65
|
end
|
66
66
|
|
67
|
-
class Bar < FAP::
|
67
|
+
class Bar < FAP::Paw
|
68
68
|
belongs_to :foo, :class => 'Foo'
|
69
69
|
end
|
70
70
|
end
|
@@ -89,7 +89,7 @@ end
|
|
89
89
|
|
90
90
|
describe "a simple FAP to read a stream" do
|
91
91
|
before :all do
|
92
|
-
class Foo < FAP::
|
92
|
+
class Foo < FAP::Paw ; end
|
93
93
|
end
|
94
94
|
|
95
95
|
it "should load a File object" do
|
@@ -100,7 +100,7 @@ end
|
|
100
100
|
describe "a simple FAP to parse an atom feed" do
|
101
101
|
before :all do
|
102
102
|
# Define a simple Atom parser for twitter searches.
|
103
|
-
class Atom < FAP::
|
103
|
+
class Atom < FAP::Paw
|
104
104
|
string :title, :xpath => '//feed/title'
|
105
105
|
uri :url, :xpath => '//feed/link[@rel="self"]', :get => :href
|
106
106
|
date :updated, :xpath => '//feed/updated'
|
@@ -108,7 +108,7 @@ describe "a simple FAP to parse an atom feed" do
|
|
108
108
|
has_many :articles, :class => 'Article', :xpath => '//feed/entry'
|
109
109
|
end
|
110
110
|
|
111
|
-
class Article < FAP::
|
111
|
+
class Article < FAP::Paw
|
112
112
|
string :title
|
113
113
|
uri :url, :xpath => 'link[@rel="alternate"]', :get => :href
|
114
114
|
string :content
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arnaud Berthomier
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-04-01 00:00:00 +02:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -71,7 +71,7 @@ files:
|
|
71
71
|
- lib/fap.rb
|
72
72
|
- lib/fap/relation.rb
|
73
73
|
- lib/fap/support/class.rb
|
74
|
-
- lib/fap/
|
74
|
+
- lib/fap/paw.rb
|
75
75
|
- lib/fap/mixins/properties.rb
|
76
76
|
- lib/fap/mixins/relations.rb
|
77
77
|
- lib/fap/mixins.rb
|