Class: Ardm::ActiveRecord::Record

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Base
Defined in:
lib/ardm/active_record/record.rb

Constant Summary collapse

JSON =
Json

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Validations

extract_options

Methods included from Repository

#repository

Methods included from Query

order

Methods included from Property

#attribute_get, #attribute_set, extended, #fields, #initialize_ardm_property_defaults, #key, #properties, #reset_key

Methods included from Dirty

#dirty?, #dirty_attributes, #method_missing

Methods included from Associations

#assign_attributes, convert_options

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ardm::ActiveRecord::Dirty

Class Method Details

.destroy(*a) ⇒ Object



67
68
69
# File 'lib/ardm/active_record/record.rb', line 67

def self.destroy(*a)
  destroy_all
end

.destroy!(*a) ⇒ Object



71
72
73
# File 'lib/ardm/active_record/record.rb', line 71

def self.destroy!(*a)
  delete_all
end

.execute_sql(sql) ⇒ Object



17
18
19
# File 'lib/ardm/active_record/record.rb', line 17

def self.execute_sql(sql)
  connection.execute(sql)
end

.property(property_name, property_type, options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ardm/active_record/record.rb', line 21

def self.property(property_name, property_type, options={})
  prop = super
  begin
    attr_accessible prop.name
    attr_accessible prop.field
  rescue => e
    puts "WARNING: Error silenced. FIXME before release.\n#{e}" unless $attr_accessible_warning
    $attr_accessible_warning = true
  end
  prop
end

.relationshipsObject

TODO:

improve this if needed with a wrapper

The reflections returned here don’t look like datamapper relationships.



49
50
51
# File 'lib/ardm/active_record/record.rb', line 49

def self.relationships
  reflections
end

.timestamps(at = :at) ⇒ Object

no-op in active record



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ardm/active_record/record.rb', line 34

def self.timestamps(at=:at)
  case at
  when :at
    property :created_at, DateTime
    property :updated_at, DateTime
  when :on
    property :created_on, Date
    property :updated_on, Date
  else
    raise ArgumentError, "Unknown argument: timestamps(#{at.inspect})"
  end
end

.update(*a) ⇒ Object



53
54
55
56
57
58
# File 'lib/ardm/active_record/record.rb', line 53

def self.update(*a)
  options = dump_properties_hash(a.first)
  options = dump_associations_hash(options)
  assert_valid_attributes(options)
  update_all(options) != 0
end

.update!(*a) ⇒ Object



60
61
62
63
64
65
# File 'lib/ardm/active_record/record.rb', line 60

def self.update!(*a)
  options = dump_properties_hash(a.first)
  options = dump_associations_hash(options)
  assert_valid_attributes(options)
  update_all(options) != 0
end

Instance Method Details

#destroyObject



75
76
77
# File 'lib/ardm/active_record/record.rb', line 75

def destroy
  self.class.delete(self.send(self.class.primary_key))
end

#new?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/ardm/active_record/record.rb', line 79

def new?
  new_record?
end

#save!(*args) ⇒ Object



91
92
93
# File 'lib/ardm/active_record/record.rb', line 91

def save!(*args)
  save(*args) || (raise_on_save_failure && raise(Ardm::SaveFailureError, "Save Failed"))
end

#save_self(*args) ⇒ Object



87
88
89
# File 'lib/ardm/active_record/record.rb', line 87

def save_self(*args)
  save(*args)
end

#saved?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'lib/ardm/active_record/record.rb', line 83

def saved?
  !new_record?
end

#update(*a) ⇒ Object



95
96
97
98
99
100
101
# File 'lib/ardm/active_record/record.rb', line 95

def update(*a)
  if a.size == 1
    update_attributes(*a)
  else
    super
  end
end

#update!(*a) ⇒ Object



103
104
105
# File 'lib/ardm/active_record/record.rb', line 103

def update!(*a)
  update_attributes!(*a)
end