Module: CouchbaseOrm::ActiveRecordCompat

Extended by:
ActiveSupport::Concern
Included in:
Document
Defined in:
lib/couchbase-orm/base.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#_has_attribute?(attr_name) ⇒ Boolean

Returns:



80
81
82
# File 'lib/couchbase-orm/base.rb', line 80

def _has_attribute?(attr_name)
  attribute_names.include?(attr_name.to_s)
end

#_write_attribute(attr_name, value) ⇒ Object



113
114
115
116
# File 'lib/couchbase-orm/base.rb', line 113

def _write_attribute(attr_name, value)
  @attributes.write_from_user(attr_name.to_s, value)
  value
end

#attribute_for_inspect(attr_name) ⇒ Object



84
85
86
87
# File 'lib/couchbase-orm/base.rb', line 84

def attribute_for_inspect(attr_name)
  value = send(attr_name)
  value.inspect
end

#attribute_namesObject



100
101
102
# File 'lib/couchbase-orm/base.rb', line 100

def attribute_names
  self.class.attribute_names
end

#attribute_present?(attribute) ⇒ Boolean

Returns:



108
109
110
111
# File 'lib/couchbase-orm/base.rb', line 108

def attribute_present?(attribute)
  value = send(attribute)
  !value.nil? && !(value.respond_to?(:empty?) && value.empty?)
end

#format_for_inspect(value) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'lib/couchbase-orm/base.rb', line 90

def format_for_inspect(value)
  if value.is_a?(String) && value.length > 50
    "#{value[0, 50]}...".inspect
  elsif value.is_a?(Date) || value.is_a?(Time)
    %("#{value.to_s(:db)}")
  else
    value.inspect
  end
end

#has_attribute?(attr_name) ⇒ Boolean

Returns:



104
105
106
# File 'lib/couchbase-orm/base.rb', line 104

def has_attribute?(attr_name)
  @attributes.key?(attr_name.to_s)
end

#read_attribute(attr_name, &block) ⇒ Object



118
119
120
121
122
123
124
# File 'lib/couchbase-orm/base.rb', line 118

def read_attribute(attr_name, &block)
  name = attr_name.to_s
  name = self.class.attribute_aliases[name] || name

  name = @primary_key if name == 'id' && @primary_key
  @attributes.fetch_value(name, &block)
end