Skip to content

Instantly share code, notes, and snippets.

@JAMSUPREME
Last active July 22, 2016 17:13
Show Gist options
  • Save JAMSUPREME/d0b61fdb61af3cc4c560291e7f347921 to your computer and use it in GitHub Desktop.
Save JAMSUPREME/d0b61fdb61af3cc4c560291e7f347921 to your computer and use it in GitHub Desktop.
Command examples
# Common "result" returned by commands
class Result
attr_accessor :successful, :value, :msg
def successful?
@successful
end
def fail(msg)
@successful = false
@msg = msg
end
end
# An isolated command that uploads a file into our assets directory
class UploadMenuCommand
def self.execute(new_file)
@result = Result.new
begin
IO.write(Rails.root + 'app/assets/images/menu.jpg', new_file, mode: 'w+', encoding: 'ASCII-8BIT')
rescue Exception => msg
@result.fail(msg)
end
@result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment