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
def deletable_by? user | |
[ | |
PermissionService.user_owns_any_containing_universe?(user: user, content: resource), | |
[ | |
PermissionService.content_has_no_containing_universe?(content: resource), | |
PermissionService.user_owns_content?(user: user, content: resource) | |
].all?, | |
[ | |
PermissionService.user_can_contribute_to_containing_universe?(user: user, content: resource), | |
PermissionService.user_owns_content?(user: user, content: resource) |
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
class ContentAuthorizer < ApplicationAuthorizer | |
def readable_by? user | |
[ | |
PermissionService.user_owns_content?(user: user, content: resource), | |
PermissionService.content_is_public?(content: resource), | |
PermissionService.content_is_in_a_public_universe?(content: resource), | |
PermissionService.user_can_contribute_to_containing_universe?(user: user, content: resource) | |
].any? | |
end |
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
class UniverseCoreContentAuthorizer < CoreContentAuthorizer | |
def self.creatable_by? user | |
[ | |
PermissionService.user_has_fewer_owned_universes_than_plan_limit?(user: user), | |
].any? | |
end | |
def readable_by? user | |
[ | |
PermissionService.content_is_public?(content: resource), |
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
class UniverseCoreContentAuthorizer < CoreContentAuthorizer | |
def self.creatable_by? user | |
user.universes.count < (user.active_billing_plans.map(&:universe_limit).max || 5) | |
end | |
def readable_by? user | |
[ | |
resource.user_id == user.id, | |
resource.privacy == 'public', | |
user.contributable_universes.pluck(:id).include?(resource.id) |
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
# Example permission schema for whether or not a user is allowed to submit edits to a [book] chapter. | |
# For a user to edit a BookChapter, one of the following must be true: | |
# * That user must own the book the chapter is part of | |
# * That user must be added as a contributor to the book the chapter is part of | |
# * That user must own the chapter if it is not part of a book | |
# * That user must be added as a contributor to the individual chapter itself | |
def user_can_edit_chapter?(user:, chapter:) | |
can_edit_chapter = false |
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
require 'open-uri' | |
open(file_url_to_stream) do |file_stream| | |
while chunk = file_stream.read(STREAM_BLOCK_SIZE) | |
send_data( | |
chunk, | |
filename: filename_to_download_to, | |
stream: true, | |
buffer_size: chunk.size | |
) | |
end |
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
# Lifeform.rb | |
module Tiamat | |
class Lifeform < BaseTiamatObject | |
include AgingProperty # calls `during_tick :age` to trigger aging as a hook on .tick | |
end | |
end | |
# Slime.rb | |
class Slime < Tiamat::Lifeform |
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
[1] pry(main)> wob.fib(7) | |
[INFO] Looking up new method for method fib taking arguments [7]. | |
[DEBUG] Checking found source code for viability. | |
[DEBUG] Code doesn't throw an exception! | |
[INFO] Saving wob_modules/fib.rb cache for future invocations. | |
[INFO] Defining fib in the global scope with 1 arguments passed. | |
[DEBUG] Executing method fib... | |
=> 13 | |
[2] pry(main)> wob.fib(7) | |
=> 13 |
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
# Standard function | |
def divide param_x, param_y | |
return Float::INFINITY if param_y.zero? | |
param_x / param_y.to_f | |
end | |
# Doable block-in-body implementation | |
def divide_with_tests_block param_x, param_y |
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
# Standard function | |
def divide param_x, param_y | |
return Infinity if param_y.zero? | |
param_x.to_f / param_y.to_f | |
end | |
# Doable implementation with tests block in-function | |
def divide_with_tests param_x, param_y | |
return Infinity if param_y.zero? | |
param_x / param_y.to_f |