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 "minitest/autorun" | |
require "minitest/spec" | |
class Pager | |
def initialize(results:, rows_per_page:) | |
@results = results | |
@rows_per_page = rows_per_page | |
end | |
def total_pages |
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
# Controller | |
recipes = Recipe.all | |
@pager = Pager.new(results: recipes, rows_per_page: 10, page: 1) | |
# ERB template | |
<% @pager.rows.each do |row| %> | |
<%= row.name %> | |
<% 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
# Assuming we have 33 rows. | |
pager = Pager.new(rows: rows, rows_per_page: 10) | |
pager.rows(1) # The first 10 rows | |
pager.rows(2) # The next 10 rows | |
pager.rows(3) # The next 10 rows | |
pager.rows(4) # The last 3 rows |
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 "minitest/autorun" | |
require "minitest/spec" | |
require "ostruct" | |
class Pager | |
def initialize(rows:, rows_per_page:) | |
@rows = rows | |
@rows_per_page = rows_per_page | |
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
require "minitest/autorun" | |
require "minitest/spec" | |
class Pager | |
def initialize(rows:, rows_per_page:) | |
@rows = rows | |
@rows_per_page = rows_per_page | |
end | |
def total_pages |
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
> rows_per_page = 10 | |
=> 10 | |
> total_rows = 33 | |
=> 33 | |
> total_rows/rows_per_page | |
=> 3 | |
> total_rows/rows_per_page.to_f |
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 "minitest/autorun" | |
require "minitest/spec" | |
class Pager | |
def initialize(total_rows:, rows_per_page:) | |
@total_rows = total_rows | |
@rows_per_page = rows_per_page | |
end | |
def total_pages |
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 Configuration | |
def method_missing(name) | |
self.class.instance_variable_get("@#{name}") | |
end | |
def self.set(name, value) | |
instance_variable_set("@#{name}", value) | |
end | |
def self.default(name, value) |
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
```ruby | |
class Foo; 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 TodoSummaryJob | |
def self.send_daily_summary | |
zones_to_search = User.unique_time_zone_names | |
zones_ready_for_email = TimeZoneSearch.new(zones_to_search).zones_with_local_hour(8) | |
User.in_time_zones(zones_ready_for_email).each do |user| | |
UserMailer.daily_summary(user, user.todos.unfinished).deliver | |
end | |
end | |
end |
NewerOlder