Class: Zena::Remote::Node
- Inherits:
-
Object
- Object
- Zena::Remote::Node
- Includes:
- Interface::InstanceMethods
- Defined in:
- lib/zena/remote/node.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#errors ⇒ Object
Returns the value of attribute errors.
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(connection, hash) ⇒ Node
constructor
A new instance of Node.
- #method_missing(method, *args) ⇒ Object
- #parent_id=(v) ⇒ Object
- #tag_names=(list) ⇒ Object
Methods included from Interface::Delete::InstanceMethods
Methods included from Interface::Update::InstanceMethods
#create_url, #new_record?, #node_url, #put, #save, #save!, #update_attributes, #update_url
Methods included from Interface::Read::InstanceMethods
Methods included from Interface::Read
#all, #count, #find, #first, #search
Methods included from Interface::Create::InstanceMethods
Methods included from Interface::Logger
Constructor Details
#initialize(connection, hash) ⇒ Node
Returns a new instance of Node.
7 8 9 10 11 |
# File 'lib/zena/remote/node.rb', line 7 def initialize(connection, hash) @connection = connection @attributes = {} self.attributes = hash end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/zena/remote/node.rb', line 55 def method_missing(method, *args) method = method.to_s if args.size == 1 && method =~ /(.*)=$/ key = $1 elem = args.first if elem.kind_of?(Remote::Node) key = "#{key}_id" unless key =~ /_ids?$/ @attributes[key] = elem.id elsif elem.kind_of?(Array) key = "#{key}_ids" unless key =~ /_ids?$/ if elem == [] # Fix for strange handling of empty array by to_xml and such. @attributes[key] = nil else @attributes[key] = elem.map do |value| value.kind_of?(Remote::Node) ? value.id : value end end else @attributes[$1] = elem end elsif args.size == 0 if @attributes.has_key?(method) @attributes[method] elsif method =~ /_ids?$/ @attributes[method] ||= [] else # build query if method.pluralize == method res = all(method) else res = first(method) end end else super end end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/zena/remote/node.rb', line 5 def attributes @attributes end |
#connection ⇒ Object
Returns the value of attribute connection.
5 6 7 |
# File 'lib/zena/remote/node.rb', line 5 def connection @connection end |
#errors ⇒ Object
Returns the value of attribute errors.
5 6 7 |
# File 'lib/zena/remote/node.rb', line 5 def errors @errors end |
Instance Method Details
#id ⇒ Object
51 52 53 |
# File 'lib/zena/remote/node.rb', line 51 def id @attributes['id'] end |
#parent_id=(v) ⇒ Object
44 45 46 47 48 49 |
# File 'lib/zena/remote/node.rb', line 44 def parent_id=(v) if v then # Cannot have nil values here (root node special case). @attributes['parent_id'] = v end end |
#tag_names=(list) ⇒ Object
40 41 42 |
# File 'lib/zena/remote/node.rb', line 40 def tag_names=(list) @attributes['tag_names'] = SerializableArray.new('tag_names', 'tag', list) end |