Last active
July 22, 2016 17:13
-
-
Save JAMSUPREME/d0b61fdb61af3cc4c560291e7f347921 to your computer and use it in GitHub Desktop.
Command examples
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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