Class: ActiveXML::Collection

Inherits:
Object
  • Object
show all
Includes:
ActiveXML, Enumerable
Defined in:
lib/active_xml/collection.rb,
lib/active_xml/collection/query.rb,
lib/active_xml/collection/route.rb

Direct Known Subclasses

Query

Defined Under Namespace

Classes: Query, Route

Constant Summary

Constants included from ActiveXML

VERSION

Instance Attribute Summary

Attributes included from ActiveXML

#path

Instance Method Summary collapse

Methods included from ActiveXML

#delete_node, #initialize, #save, #set_root!, #xml

Instance Method Details

#delete_nodes(keys) ⇒ Object



40
41
42
# File 'lib/active_xml/collection.rb', line 40

def delete_nodes(keys)
  keys.each { |key| xml.search(key).first.remove }
end

#pluck(key) ⇒ Object



6
7
8
9
10
# File 'lib/active_xml/collection.rb', line 6

def pluck(key)
  map do |elem|
    fetch_contents(elem.elements, key).first
  end
end

#split(route_path) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/active_xml/collection.rb', line 17

def split(route_path)
  hash = Hash.new

  each do |elem|
    route = Route.new(route_path, elem)
    hashed_path = route.to_hash
    path = Pathname.new(hashed_path.values[0].join("/"))
    create_file(path, elem.to_xml)
    hash.merge!(hashed_path) { |key,old,new| old.class == Array ? old << new[0] : [new,old] }
  end

  hash
end

#split_to_array(route_path) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/active_xml/collection.rb', line 31

def split_to_array(route_path)
  map do |elem|
    route = Route.new(route_path, elem)
    path = Pathname.new(route.generate)
    create_file(path, elem.to_xml)
    path
  end
end

#where(where_values) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
# File 'lib/active_xml/collection.rb', line 12

def where(where_values)
  raise ArgumentError.new("Passing more then 1 where value is currently not possible") if where_values.size > 1
  Query.new(@path, where_values)
end