Skip to content
Browse files

Improve documentation and make has_one :author work

  • Loading branch information...
1 parent 6fadd55 commit 0ab4ab1f77c118a999d46c76d8d9d0723642a03b @wycats committed Apr 10, 2010
Showing with 15 additions and 5 deletions.
  1. +7 −0 lib/alexandria.rb
  2. +6 −3 lib/alexandria/response_document.rb
  3. +2 −2 lib/alexandria/response_document/feed.rb
View
7 lib/alexandria.rb
@@ -1,5 +1,12 @@
require "time"
require "resourceful"
+
+require "active_support"
+require "active_support/core_ext/class/attribute"
+require "active_support/core_ext/module/introspection"
+require "active_support/inflector/inflections"
+require "active_support/inflections"
+
require "alexandria/resourceful_backend"
require "alexandria/constants"
require "alexandria/response_document"
View
9 lib/alexandria/response_document.rb
@@ -1,6 +1,5 @@
require "date"
require "nokogiri"
-require "active_support/core_ext/class/attribute"
class Alexandria
class ResponseDocument
@@ -52,7 +51,8 @@ def self.#{type}(name, selector = name.to_s, attribute = nil)
# of a child node:
#
# @param [Symbol] name The name of the child model
- # @param [Class] type The class of the child model
+ # @param [Class] type The class of the child model. By default
+ # this is #{parent_name}::#{name.to_s.camelize}
# @param [String] selector The selector, relative to the root
# of the current model, that describes how to get to
# the location of the node containing the child model's
@@ -87,7 +87,10 @@ def self.#{type}(name, selector = name.to_s, attribute = nil)
#
# If the root node does not exist, the child model's method
# on the parent will return nil
- def self.has_one(name, type, selector = name.to_s)
+ def self.has_one(name, type = nil, selector = name.to_s)
+ inflect = ActiveSupport::Inflector
+ type ||= inflect.constantize("#{parent_name}::#{inflect.camelize(name.to_s)}")
+
self.children ||= []
self.children << [name, type, selector]
attr_accessor name
View
4 lib/alexandria/response_document/feed.rb
@@ -11,7 +11,7 @@ class Feed < ResponseDocument
time :published
time :updated
- has_one :author, Author
- has_one :category, Category
+ has_one :author
+ has_one :category
end
end

0 comments on commit 0ab4ab1

Please sign in to comment.
Something went wrong with that request. Please try again.