Module: Spyke::Orm

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/spyke/orm.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#destroyObject



74
75
76
# File 'lib/spyke/orm.rb', line 74

def destroy
  self.attributes = delete
end

#persisted?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/spyke/orm.rb', line 61

def persisted?
  id?
end

#reloadObject



84
85
86
# File 'lib/spyke/orm.rb', line 84

def reload
  self.attributes = self.class.find(id).attributes
end

#saveObject



65
66
67
68
69
70
71
72
# File 'lib/spyke/orm.rb', line 65

def save
  run_callbacks :save do
    callback = persisted? ? :update : :create
    run_callbacks(callback) do
      send self.class.method_for(callback), to_params
    end
  end
end

#to_paramsObject



53
54
55
56
57
58
59
# File 'lib/spyke/orm.rb', line 53

def to_params
  if param_root
    { param_root => params_not_embedded_in_url }
  else
    params_not_embedded_in_url
  end
end

#update(new_attributes) ⇒ Object Also known as: update_attributes



78
79
80
81
# File 'lib/spyke/orm.rb', line 78

def update(new_attributes)
  self.attributes = new_attributes
  save
end