kelredd-resourceful 0.4.6 → 0.4.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/resourceful/model/base.rb +13 -10
- data/lib/resourceful/model/json.rb +0 -4
- data/lib/resourceful/model/xml.rb +3 -3
- data/lib/resourceful/version.rb +1 -1
- metadata +1 -1
@@ -34,7 +34,7 @@ module Resourceful
|
|
34
34
|
clean_name = name.to_s.gsub(/\W/,'')
|
35
35
|
add_to_attributes(name.to_s)
|
36
36
|
config ||= {}
|
37
|
-
config[:path] ||=
|
37
|
+
config[:path] ||= clean_name
|
38
38
|
content_method = case type.to_sym
|
39
39
|
when :string
|
40
40
|
'to_s'
|
@@ -66,11 +66,12 @@ module Resourceful
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def self.has_one(name, config={})
|
69
|
+
clean_name = name.to_s.gsub(/\W/,'')
|
69
70
|
config ||= {}
|
70
|
-
config[:path] ||=
|
71
|
+
config[:path] ||= clean_name
|
71
72
|
define_method(name) do
|
72
|
-
instance_variable_get("@#{
|
73
|
-
instance_variable_set("@#{
|
73
|
+
instance_variable_get("@#{clean_name}") || \
|
74
|
+
instance_variable_set("@#{clean_name}", \
|
74
75
|
if (c = child(config))
|
75
76
|
config[:klass].constantize.new(c) rescue c
|
76
77
|
else
|
@@ -81,11 +82,12 @@ module Resourceful
|
|
81
82
|
end
|
82
83
|
|
83
84
|
def self.has_many(name, config={})
|
85
|
+
clean_name = name.to_s.gsub(/\W/,'')
|
84
86
|
config ||= {}
|
85
|
-
config[:path] ||=
|
87
|
+
config[:path] ||= clean_name
|
86
88
|
define_method(name) do
|
87
|
-
instance_variable_get("@#{
|
88
|
-
instance_variable_set("@#{
|
89
|
+
instance_variable_get("@#{clean_name}") || \
|
90
|
+
instance_variable_set("@#{clean_name}", \
|
89
91
|
if ((c = child(config)) && c.respond_to?(:collect))
|
90
92
|
c.collect do |item|
|
91
93
|
config[:klass].constantize.new(item) rescue item
|
@@ -98,11 +100,12 @@ module Resourceful
|
|
98
100
|
end
|
99
101
|
|
100
102
|
def self.belongs_to(name, config={})
|
103
|
+
clean_name = name.to_s.gsub(/\W/,'')
|
101
104
|
config ||= {}
|
102
|
-
config[:id] ||= "#{
|
105
|
+
config[:id] ||= "#{clean_name}_id"
|
103
106
|
define_method(name) do
|
104
|
-
instance_variable_get("@#{
|
105
|
-
instance_variable_set("@#{
|
107
|
+
instance_variable_get("@#{clean_name}") || \
|
108
|
+
instance_variable_set("@#{clean_name}", \
|
106
109
|
if ((k = config[:klass].constantize) && k.respond_to?(:find))
|
107
110
|
self.respond_to?(config[:id]) ? k.find(self.send(config[:id])) : nil
|
108
111
|
else
|
@@ -35,7 +35,7 @@ module Resourceful
|
|
35
35
|
|
36
36
|
def attribute(config)
|
37
37
|
begin
|
38
|
-
get_node(
|
38
|
+
get_node(config[:path]).first.send((config[:content] || 'content').to_s)
|
39
39
|
rescue Exception => err
|
40
40
|
nil
|
41
41
|
end
|
@@ -43,14 +43,14 @@ module Resourceful
|
|
43
43
|
|
44
44
|
def child(config)
|
45
45
|
begin
|
46
|
-
get_node(
|
46
|
+
get_node(config[:path])
|
47
47
|
rescue Exception => err
|
48
48
|
nil
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
52
|
def self.get_node(xml, path)
|
53
|
-
xml.search(path.to_s)
|
53
|
+
xml.search(path.to_s)
|
54
54
|
end
|
55
55
|
def get_node(path)
|
56
56
|
self.class.get_node(@data, path)
|
data/lib/resourceful/version.rb
CHANGED