Class: ExistDB::Resource::Base

Inherits:
Object
  • Object
show all
Extended by:
ClassWrappingForwardable
Defined in:
lib/existdb/resource/base.rb

Direct Known Subclasses

Binary, Xml

Instance Method Summary collapse

Methods included from ClassWrappingForwardable

delegate_to_java

Constructor Details

#initialize(*opts) ⇒ Base

Returns a new instance of Base.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/existdb/resource/base.rb', line 34

def initialize(*opts)
    options = Hash.new
    if opts.size == 1 and not opts.first.is_a?(Hash) then
        @obj = opts.first
    else
        opts.each do |opt|
            if opt.is_a?(Hash) then
               options.merge!(opt)
            end
        end

        collection = ClassUnwrap[ options[:parent] ]
        data = nil
        if options[:binary]
            type = "BinaryResource"
            data = options[:binary]
        elsif options[:xml]
            type = "XMLResource"
            data = options[:xml]
        else
            type = options[:type]
            data = options[:content]
        end
        type ||= "XMLResource"
        
        @obj = collection.createResource(options[:name], type)
        if data then
            self.content = data
            self.save
        end
    end

end

Instance Method Details

#deleteObject



78
79
80
# File 'lib/existdb/resource/base.rb', line 78

def delete
    parent.delete(self)
end

#inspectObject



68
69
70
# File 'lib/existdb/resource/base.rb', line 68

def inspect
    "#<#{self.class}:0x#{self.hash.to_s(16)} name=#{self.name.inspect}>"
end

#saveObject



72
73
74
75
76
# File 'lib/existdb/resource/base.rb', line 72

def save
    collection = @obj.getParentCollection
    collection.storeResource( @obj )
    true
end