kelredd-resourceful 0.4.6 → 0.4.8

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.
@@ -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] ||= name
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] ||= name
71
+ config[:path] ||= clean_name
71
72
  define_method(name) do
72
- instance_variable_get("@#{name}") || \
73
- instance_variable_set("@#{name}", \
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] ||= name
87
+ config[:path] ||= clean_name
86
88
  define_method(name) do
87
- instance_variable_get("@#{name}") || \
88
- instance_variable_set("@#{name}", \
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] ||= "#{name}_id"
105
+ config[:id] ||= "#{clean_name}_id"
103
106
  define_method(name) do
104
- instance_variable_get("@#{name}") || \
105
- instance_variable_set("@#{name}", \
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
@@ -31,10 +31,6 @@ module Resourceful
31
31
  @data = json
32
32
  end
33
33
 
34
- #def attributes
35
- # @data
36
- #end
37
-
38
34
  protected
39
35
 
40
36
  def attribute(config)
@@ -35,7 +35,7 @@ module Resourceful
35
35
 
36
36
  def attribute(config)
37
37
  begin
38
- get_node("#{config[:path]}").send((config[:content] || 'content').to_s)
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("#{config[:path]}")
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).first
53
+ xml.search(path.to_s)
54
54
  end
55
55
  def get_node(path)
56
56
  self.class.get_node(@data, path)
@@ -3,7 +3,7 @@ module Resourceful
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 4
6
- TINY = 6
6
+ TINY = 8
7
7
 
8
8
  def self.to_s # :nodoc:
9
9
  [MAJOR, MINOR, TINY].join('.')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kelredd-resourceful
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kelly Redding