Class: Object

Inherits:
BasicObject
Defined in:
lib/mongo_persist/util.rb,
lib/mongo_persist/util.rb,
lib/mongo_persist/core_ext.rb,
lib/mongo_persist/core_ext.rb

Instance Method Summary collapse

Instance Method Details

#can_mongo_convert?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/mongo_persist/core_ext.rb', line 11

def can_mongo_convert?
  false
end

#dsl_class_method(name, &b) ⇒ Object



16
17
18
# File 'lib/mongo_persist/util.rb', line 16

def dsl_class_method(name,&b)
  self.class.dsl_method(name,&b)
end

#dsl_method(name, &b) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/mongo_persist/util.rb', line 2

def dsl_method(name,&b)
  define_method(name) do |*args|
    if args.empty?
      res = instance_variable_get("@#{name}")
      if res.nil? && block_given?
        res = b.call
        instance_variable_set("@#{name}",res) 
      end
      res
    else
      instance_variable_set("@#{name}",args.first)
    end
  end
end

#from_mongo_keyObject



42
43
44
# File 'lib/mongo_persist/core_ext.rb', line 42

def from_mongo_key
  self
end

#klassObject



33
34
35
# File 'lib/mongo_persist/util.rb', line 33

def klass
  self.class
end

#ngil_obj?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/mongo_persist/core_ext.rb', line 8

def ngil_obj?
  self == MongoPersist::NIL_OBJ
end

#safe_to_mongo_hashObject



2
3
4
# File 'lib/mongo_persist/core_ext.rb', line 2

def safe_to_mongo_hash
  respond_to?(:to_mongo_hash) ? to_mongo_hash : nil
end

#safe_to_mongo_objectObject



5
6
7
# File 'lib/mongo_persist/core_ext.rb', line 5

def safe_to_mongo_object
  to_mongo_object
end

#sos(m) ⇒ Object



30
31
32
# File 'lib/mongo_persist/util.rb', line 30

def sos(m)
  respond_to?(m) ? send(m) : self
end

#to_mongo_keyObject



39
40
41
# File 'lib/mongo_persist/core_ext.rb', line 39

def to_mongo_key
  self
end