Module: Fixably::Actions

Included in:
ApplicationResource
Defined in:
lib/fixably/actions.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



9
10
11
# File 'lib/fixably/actions.rb', line 9

def self.included(klass)
  klass.extend(ClassMethods)
end

Instance Method Details

#destroyObject



121
122
123
124
# File 'lib/fixably/actions.rb', line 121

def destroy
  ActionPolicy.new(resource: self).delete!
  super()
end

#save(validate: true) ⇒ Object



126
127
128
129
130
131
132
133
# File 'lib/fixably/actions.rb', line 126

def save(validate: true)
  if validate
    message = new? ? :create! : :update!
    ActionPolicy.new(resource: self).public_send(message)
  end

  super()
end

#save!Object

rubocop:disable Style/RaiseArgs



136
137
138
139
140
141
142
143
144
145
# File 'lib/fixably/actions.rb', line 136

def save!
  if new?
    ActionPolicy.new(resource: self).create!
  else
    ActionPolicy.new(resource: self).update!
  end

  save(validate: false) ||
    raise(::ActiveResource::ResourceInvalid.new(self))
end