Sha256: 6800e77ce2f7c3fda43a608e8ba7a24bb521becbb159a002a4f8cbab00dd51b1
Contents?: true
Size: 1.74 KB
Versions: 1
Compression:
Stored size: 1.74 KB
Contents
module OrientDB class Document def values field_names.map { |field_name| [field_name, self[field_name]] } end alias :db :database def [](field_name) field field_name.to_s end def []=(field_name, value) field field_name.to_s, value end def field?(name) contains_field(name.to_s) || schema_class.exists_property?(name.to_s) end def respond_to?(method_name) return true if field?(method_name.to_s) match = method_name.to_s.match(/(.*?)([?=!]?)$/) return true if match[2] == '=' return true if match[2] == '?' && field?(match[1]) super end def method_missing(method_name, *args, &blk) return self[method_name] if contains_field(method_name.to_s) return nil if schema_class.exists_property?(method_name.to_s) match = method_name.to_s.match(/(.*?)([?=!]?)$/) case match[2] when "=" self[match[1]] = args.first when "?" field(match[1]) ? !!self[match[1]] : super else super end end def rid identity.to_s end def inspect props = values.map { |k, v| "#{k}:#{v.inspect}" }.join(' ') %{#<OrientDB::Document:#{class_name}:#{rid}#{props.empty? ? '' : ' ' + props}>} end alias :to_s :inspect class << self alias_method :native_new, :new def new(db, klass_name, fields = {}) puts "new : #{db} : #{klass_name} : #{fields.inspect}" obj = native_new db, klass_name.to_s fields.each do |name, value| obj.field name.to_s, value end obj end def create(db, klass_name, fields = {}) obj = new db, klass_name, fields obj.save obj end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
orientdb-0.0.7-jruby | lib/orientdb/document.rb |