source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | infinitered/redpotion | https://github.com/infinitered/redpotion | app/stylesheets/collection_cell_stylesheet.rb | Ruby | mit | 233 | master | 312 | module CollectionCellStylesheet
def cell_size
{w: 96, h: 96}
end
def collection_cell(st)
st.frame = cell_size
st.background_color = color.random
# Style overall view here
end
def title(st)
st.frame = :full
st.color = color.white
st.text_alignment = :center
end
end |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | app/stylesheets/application_stylesheet.rb | Ruby | mit | 233 | master | 876 | class ApplicationStylesheet < RubyMotionQuery::Stylesheet
def application_setup
# Change the default grid if desired
# rmq.app.grid.tap do |g|
# g.num_columns = 12
# g.column_gutter = 10
# g.num_rows = 18
# g.row_gutter = 10
# g.content_left_margin = 10
# g... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | app/stylesheets/collection_screen_stylesheet.rb | Ruby | mit | 233 | master | 759 | class CollectionScreenStylesheet < ApplicationStylesheet
include CollectionCellStylesheet
def setup
# Add stylesheet specific setup stuff here.
# Add application specific setup stuff in application_stylesheet.rb
@margin = ipad? ? 12 : 8
end
def collection_view(st)
st.view.contentInset = [@ma... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | app/shared/contributors_module.rb | Ruby | mit | 233 | master | 546 | module ContributorsModule
def contributors
[{
name: 'twerth',
city: "San Francisco"
}, {
name: 'squidpunch',
city: nil
}, {
name: 'GantMan',
city: "New Orleans, LA"
}, {
name: 'shreeve',
city: nil
}, {
name: 'chunlea',
city: 'Shandong,... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | app/controllers/example_controller.rb | Ruby | mit | 233 | master | 696 | # It's prefered you use a screen. But you can also use normal controllers. If you want
# to turn any controller into a screen, see metal_table_screen for an example.
class ExampleController < UIViewController
# You can't use any of the ProMotion screen stuff here, but you can use the RedPotion stuff, and
# RedPoti... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | app/screens/home_screen.rb | Ruby | mit | 233 | master | 1,627 | class HomeScreen < PM::Screen
title "RedPotion"
stylesheet HomeScreenStylesheet
def on_load
set_nav_bar_button :left, system_item: :camera, action: :nav_left_button
set_nav_bar_button :right, title: "Right", action: :nav_right_button
@hello_world_label = append!(UILabel, :hello_world)
append ... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | app/screens/tasks_screen.rb | Ruby | mit | 233 | master | 727 | class TasksScreen < PM::TableScreen
title "Tasks"
refreshable
stylesheet TasksScreenStylesheet
searchable placeholder: "Search tasks"
def on_load
end
def on_refresh
end
def table_data
[{
title: "Tasks",
cells: [
{
cell_class: TaskCell,
properties: {
... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | app/screens/contributor_screen.rb | Ruby | mit | 233 | master | 432 | class ContributorScreen < PM::DataTableScreen
title "RedPotion Contributors"
stylesheet ContributorScreenStylesheet
model Contributor
refreshable
searchable fields: [:name, :city]
def on_load
@refreshed = false
end
def on_refresh
stop_refreshing
@refreshed = true
end
# Remove if yo... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | app/screens/metal_table_screen.rb | Ruby | mit | 233 | master | 1,425 | class MetalTableScreen < UITableViewController
include ProMotion::ScreenModule
title "Down to the metal table"
stylesheet MetalTableScreenStylesheet
CELL_ID = "MetalTableCell"
# Needed to be a ProMotion screen. Many controllers have different inits, so you need
# to provide the correct one here
def s... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | app/screens/collection_screen.rb | Ruby | mit | 233 | master | 1,437 | class CollectionScreen < UICollectionViewController
include ProMotion::ScreenModule
stylesheet CollectionScreenStylesheet
title 'Collection View'
COLLECTION_CELL_ID = "CollectionCell"
def self.new(args = {})
layout = UICollectionViewFlowLayout.alloc.init
s = self.alloc.initWithCollectionViewLayout(... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | app/test_objects/delegate_test_attributes.rb | Ruby | mit | 233 | master | 809 | module DelegateTestAttributes
attr_accessor :view_did_load_count
attr_accessor :view_will_appear_count
attr_accessor :view_did_appear_count
attr_accessor :view_will_disappear_count
attr_accessor :view_did_disappear_count
def view_did_load
self.view_did_load_count ||= 0
self.view_did_load_count +... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | lib/redpotion.rb | Ruby | mit | 233 | master | 533 | # encoding: utf-8
unless defined?(Motion::Project::Config)
raise "This file must be required within a RubyMotion project Rakefile."
end
require 'ruby_motion_query'
require 'ProMotion'
require 'motion_print'
require 'RedAlert'
lib_dir_path = File.dirname(File.expand_path(__FILE__))
Motion::Project::App.setup do |ap... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | lib/project/ext/ui_image_view.rb | Ruby | mit | 233 | master | 1,903 | class UIImageView
def remote_image=(args)
url = args.respond_to?(:fetch) ? args.fetch(:url) : args
callback = args.respond_to?(:fetch) ? args.fetch(:on_load, -> {}) : -> {}
load_remote_image(url, callback)
end
private
def load_remote_image(url, callback = nil)
if defined?(SDWebImageManager)
... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | lib/project/ext/kernel.rb | Ruby | mit | 233 | master | 393 | if RUBYMOTION_ENV == "development"
class TopLevel
def live(interval = 1.0, debug=false)
rmq_live_stylesheets interval, debug
end
def enable_live_stylesheets(interval)
enable_rmq_live_stylesheets interval
end
def open(screen, args={})
find.screen.open(screen, args)
end
... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | lib/project/ext/ui_color.rb | Ruby | mit | 233 | master | 478 | class UIColor
def with(options)
type = CGSize.type[/(f|d)/]
r, g, b, a = Pointer.new(type), Pointer.new(type), Pointer.new(type), Pointer.new(type)
self.getRed(r, green: g, blue: b, alpha: a)
r = options[:r] || options[:red] || r.value
g = options[:g] || options[:green] || g.value
b = opti... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | lib/project/ext/ui_view_controller.rb | Ruby | mit | 233 | master | 3,447 | class UIViewController
def append(view_or_constant, style=nil, opts = {})
self.rmq.append(view_or_constant, style, opts)
end
def append!(view_or_constant, style=nil, opts = {})
self.rmq.append!(view_or_constant, style, opts)
end
def prepend(view_or_constant, style=nil, opts = {})
self.rmq.prep... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | lib/project/ext/object.rb | Ruby | mit | 233 | master | 352 | class Object
def app
rmq.app
end
def device
rmq.device
end
def blank?
self.respond_to?(:empty?) ? self.empty? : !self
end
def find(*args) # Do not alias this, strange bugs happen where classes don't have methods
rmq(*args)
end
def find!(*args)
rmq(*args).get
end
def scr... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | lib/project/ext/pm_delegate.rb | Ruby | mit | 233 | master | 631 | # FXFormViewController is a top level class
class FXFormViewController < UIViewController
end
# Defines which ProMotion classes handle delegates
module ProMotion
class ViewController < UIViewController
def class_handles_delegates?
true
end
end
class TableViewController < UITableViewContr... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | lib/project/ext/ui_collection_view_cell.rb | Ruby | mit | 233 | master | 385 | class UICollectionViewCell
# You can use either rmq_build or on_load, not both. If you have both, on_load will be ignored,
# you can however call it from rmq_build. They are the same, on_load follows the ProMotion style
# and is recommended.
def rmq_build
self.on_load
end
def reused
@reused
end
... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | lib/project/ext/ui_table_view_cell.rb | Ruby | mit | 233 | master | 292 | class UITableViewCell
# You can use either rmq_build or on_load, not both. If you have both, on_load will be ignored,
# you can however call it from rmq_build. They are the same, on_load follows the ProMotion style
# and is recommended.
def rmq_build
self.on_load
end
end |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | lib/project/ext/ui_view.rb | Ruby | mit | 233 | master | 2,113 | class UIView
# You can use either rmq_build or on_load, not both. If you have both, on_load will be ignored,
# you can however call it from rmq_build. They are the same, on_load follows the ProMotion style
# and is recommended.
def rmq_build
on_load
end
def on_load
end
def on_styled
end
# Yo... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | lib/project/pro_motion/data_table_screen.rb | Ruby | mit | 233 | master | 542 | module ProMotion
class DataTableScreen < TableViewController
include ProMotion::ScreenModule
include ProMotion::DataTable
class << self
def model(value, opts = {})
if value.method_defined?(:cell)
@opts = {
model: value,
scope: :all,
}.merge(o... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | lib/project/pro_motion/table.rb | Ruby | mit | 233 | master | 695 | module ProMotion
class TableScreen < TableViewController
# Don't call super -- would result in two on_load calls to the cell.
def on_cell_created(cell, data)
self.rmq.build(cell)
end
end
# This is duplicated from ProMotion in order to be call
# make_data_table_searchable instead of make_sear... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | lib/project/pro_motion/data_table_search_delegate.rb | Ruby | mit | 233 | master | 659 | class DataTableSeachDelegate
attr_accessor :parent
# UISearchControllerDelegate methods
def willPresentSearchController(search_controller)
parent.dt_searchDisplayControllerWillBeginSearch(search_controller)
end
def willDismissSearchController(search_controller)
parent.dt_searchDisplayControllerWill... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | lib/project/pro_motion/data_table.rb | Ruby | mit | 233 | master | 6,163 | module ProMotion
module DataTable
include TableClassMethods
include ProMotion::Styling
include ProMotion::Table
include ProMotion::TableBuilder
include ProMotion::TableDataBuilder
include ProMotion::Table::Utils
include ProMotion::Table::Searchable
include ProMotion::Table::Refre... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | lib/project/pro_motion/data_table_searchable.rb | Ruby | mit | 233 | master | 2,966 | module ProMotion
module Table
module Searchable
def make_data_table_searchable(params={})
if params[:search_bar][:fields].nil?
raise "ERROR: You must specify fields:[:example] for your searchable DataTableScreen. It should be an array of fields you want searched in CDQ."
else
... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | lib/project/pro_motion/collection_screen.rb | Ruby | mit | 233 | master | 288 | module ProMotion
class CollectionScreen
def set_stylesheet
super.tap do
if self.class.rmq_style_sheet_class
self.collection_view.rmq.apply_style(:collection_view) if self.rmq.stylesheet.respond_to?(:collection_view)
end
end
end
end
end |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | lib/project/ruby_motion_query/app.rb | Ruby | mit | 233 | master | 867 | module RubyMotionQuery
class App
class << self
def current_screen(root_view_controller = nil)
current_view_controller root_view_controller
end
def data(*args) # Do not alias this
CDQ.cdq(*args)
end
def reset_image_cache!
if !!defined?(SDWebImageManager)
... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | lib/project/ruby_motion_query/stylers/ui_image_view.rb | Ruby | mit | 233 | master | 310 | module RubyMotionQuery
module Stylers
class UIImageViewStyler < UIViewStyler
def remote_image=(value)
@view.remote_image = value
end
# This is the same functionality as image=
def placeholder_image=(value)
@view.image = value
end
end
end
end |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | spec/ext/ui_view_controller_spec.rb | Ruby | mit | 233 | master | 5,743 | describe 'UIViewController' do
class FakeView < UIView; end
after do
#cleanup between tests
controller.find(FakeView).remove
end
shared 'proper delegate caller' do
it 'should call view_will_appear only once' do
controller.view_will_appear_count.should.equal(1)
end
it 'should call... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | spec/ext/object_spec.rb | Ruby | mit | 233 | master | 580 | describe 'Object' do
before { @subject = Object.new }
it "should return the RMQ App when Object#app is called" do
@subject.app.should.equal(RubyMotionQuery::App)
end
it "should return the RMQ Device when Object#device is called" do
@subject.device.should.equal(RubyMotionQuery::Device)
end
it "... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | spec/ext/ui_color_spec.rb | Ruby | mit | 233 | master | 258 | describe 'UIColor' do
it "should allow you to get a new color from an existing color with 'with'" do
trans_black = UIColor.blackColor.with(alpha: 0.5)
trans_black.should.equal(UIColor.colorWithRed(0, green: 0, blue: 0, alpha: 0.5))
end
end |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | spec/ext/ui_view_spec.rb | Ruby | mit | 233 | master | 9,038 | describe 'UIView' do
it "should call on_load instead of rmq_build if rmq_build does not exist in the view" do
rmq.create(TestView).get.on_loaded.should == true
test_view = TestView.alloc.initWithFrame([[0,0],[10,10]])
test_view.on_loaded.should.be.nil
rmq.build(test_view)
test_view.on_loaded.s... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | spec/ruby_motion_query/app_spec.rb | Ruby | mit | 233 | master | 357 | describe 'RubyMotionQuery app' do
it "should return the current_view_controller for the current_screen" do
expected = RubyMotionQuery::App.current_view_controller
RubyMotionQuery::App.current_screen.should.equal(expected)
end
it "should retun cdq object when using app.data" do
RubyMotionQuery::App... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | spec/ruby_motion_query/stylers/ui_image_view_spec.rb | Ruby | mit | 233 | master | 4,317 | class StyleSheetForUIImageViewStylerTests < RubyMotionQuery::Stylesheet
def ui_image_view_placeholder(st)
st.placeholder_image = rmq.image.resource('grumpy_cat')
end
def ui_image_view_remote(st)
ui_image_view_placeholder(st)
st.remote_image = 'http://somehost/image'
end
def ui_image_view_remote... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | spec/pro_motion/screen_module_spec.rb | Ruby | mit | 233 | master | 816 | describe 'ScreenModule' do
class TestScreenStylesheet < ApplicationStylesheet
def root_view(st)
st.background_color = color.white
end
end
class TestScreen < PM::Screen
stylesheet TestScreenStylesheet
def grab_app
app
end
end
tests TestScreen
it "should set the rmq styl... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | spec/pro_motion/data_table_screen_spec.rb | Ruby | mit | 233 | master | 9,661 | describe 'DataTableScreen' do
extend ContributorsModule
class TestDataTableScreen < ProMotion::DataTableScreen
stylesheet ContributorScreenStylesheet
model Contributor
end
class TestDataTableScreenScope < ProMotion::DataTableScreen
stylesheet ContributorScreenStylesheet
model Contributor, s... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | spec/screens/ui_collection_view.rb | Ruby | mit | 233 | master | 894 | describe 'UICollectionViewController' do
before do
@controller = CollectionScreen.new
end
it "should have sections" do
@controller.numberOfSectionsInCollectionView(@controller.collectionView).should == 1
end
it "should have cells" do
@controller.collectionView(@controller.collectionView, number... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | templates/collection_view_screen/app/views/name_cell.rb | Ruby | mit | 233 | master | 242 | class <%= @name_camel_case %>Cell < UICollectionViewCell
def on_load
find(self).apply_style :<%= @name %>_cell
q = find(self.contentView)
# Add your subviews, init stuff here
# @foo = q.append!(UILabel, :foo)
end
end |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | templates/collection_view_screen/app/stylesheets/name_screen_stylesheet.rb | Ruby | mit | 233 | master | 781 | class <%= @name_camel_case %>ScreenStylesheet < ApplicationStylesheet
include <%= @name_camel_case %>CellStylesheet
def setup
# Add stylesheet specific setup stuff here.
# Add application specific setup stuff in application_stylesheet.rb
@margin = ipad? ? 12 : 8
end
def collection_view(st)
s... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | templates/collection_view_screen/app/stylesheets/name_cell_stylesheet.rb | Ruby | mit | 233 | master | 224 | module <%= @name_camel_case %>CellStylesheet
def cell_size
{w: 96, h: 96}
end
def <%= @name %>_cell(st)
st.frame = cell_size
st.background_color = color.random
# Style overall view here
end
end |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | templates/collection_view_screen/app/screens/name_screen.rb | Ruby | mit | 233 | master | 1,544 | class <%= @name_camel_case %>Screen < UICollectionViewController
include ProMotion::ScreenModule
title "Your title here"
stylesheet <%= @name_camel_case %>ScreenStylesheet
<%= @name.upcase %>_CELL_ID = "<%= @name_camel_case %>Cell"
def self.new(args = {})
# Set layout
layout = UICollectionViewFlow... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | templates/metal_table_screen/app/stylesheets/name_screen_stylesheet.rb | Ruby | mit | 233 | master | 522 | class <%= @name_camel_case %>ScreenStylesheet < ApplicationStylesheet
def setup
# Add stylesheet specific setup stuff here.
# Add application specific setup stuff in application_stylesheet.rb
end
def root_view(st)
st.background_color = color.gray
end
def cell(st)
# Style overall cell here
... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | templates/metal_table_screen/app/views/name_cell.rb | Ruby | mit | 233 | master | 250 | class <%= @name_camel_case %>Cell < UITableViewCell
def on_load
find(self.contentView).tap do |q|
@name = q.append!(UILabel, :cell_name)
end
end
def update(data)
@name.text = "#{data[:name]} is #{data[:num]}"
end
end |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | templates/metal_table_screen/app/screens/name_screen.rb | Ruby | mit | 233 | master | 2,220 | class <%= @name_camel_case %>Screen < UITableViewController
include ProMotion::ScreenModule
title "Your title here"
stylesheet <%= @name_camel_case %>ScreenStylesheet
<%= @name.upcase %>_CELL_ID = "<%= @name_camel_case %>Cell"
# Needed to be a ProMotion screen. Many controllers have different inits, so yo... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | templates/view/app/stylesheets/name_stylesheet.rb | Ruby | mit | 233 | master | 636 | # To style this view include its stylesheet at the top of each controller's
# stylesheet that is going to use it:
# class SomeStylesheet < ApplicationStylesheet
# include <%= @name_camel_case %>Stylesheet
# Another option is to use your controller's stylesheet to style this view. This
# works well if only one co... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | templates/view/app/views/name.rb | Ruby | mit | 233 | master | 736 | class <%= @name_camel_case %> < UIView
def on_load
apply_style :<%= @name %>
# Add subviews here, like so:
# append UILabel, :label_style_here
# -or-
# @submit_button = append(UIButton, :submit).get
# -or-
# @submit_button = append! UIButton, :submit
end
end
# To style this view incl... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | templates/table_screen_cell/app/views/name.rb | Ruby | mit | 233 | master | 1,263 | class <%= @name_camel_case %> < PM::TableViewCell
def on_load
apply_style :<%= @name %>
content = find(self.contentView)
@title = content.append! UILabel, :<%= @name %>_title
# Add subviews here, like so:
# content.append UILabel, :label_style_here
# -or-
# @submit_button = content.appe... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | templates/table_screen_cell/app/stylesheets/name_stylesheet.rb | Ruby | mit | 233 | master | 840 | # To style this view include its stylesheet at the top of each controller's
# stylesheet that is going to use it:
# class SomeStylesheet < ApplicationStylesheet
# include <%= @name_camel_case %>Stylesheet
# Another option is to use your controller's stylesheet to style this view. This
# works well if only one co... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | templates/screen/app/stylesheets/name_screen_stylesheet.rb | Ruby | mit | 233 | master | 395 | class <%= @name_camel_case %>ScreenStylesheet < ApplicationStylesheet
# Add your view stylesheets here. You can then override styles if needed,
# example: include FooStylesheet
def setup
# Add stylesheet specific setup stuff here.
# Add application specific setup stuff in application_stylesheet.rb
e... |
github | infinitered/redpotion | https://github.com/infinitered/redpotion | templates/screen/app/screens/name_screen.rb | Ruby | mit | 233 | master | 848 | class <%= @name_camel_case %>Screen < PM::<%= @screen_base %>
title "Your title here"
stylesheet <%= @name_camel_case %>ScreenStylesheet
def on_load
end
<% if @screen_base == 'TableScreen' %>
def table_data
[]
end
<% end %>
# You don't have to reapply styles to all UIViews, if you want to opt... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | n1_loader.gemspec | Ruby | mit | 233 | master | 1,448 | # frozen_string_literal: true
require_relative "lib/n1_loader/version"
Gem::Specification.new do |spec|
spec.name = "n1_loader"
spec.version = N1Loader::VERSION
spec.authors = ["Evgeniy Demin"]
spec.email = ["lawliet.djez@gmail.com"]
spec.summary = "Loader to solve N+1 is... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | Gemfile | Ruby | mit | 233 | master | 614 | # frozen_string_literal: true
source "https://rubygems.org"
# Specify your gem's dependencies in n1_loader.gemspec
gemspec
# Hack to make Github work with Circle CI job names with slashes
gemfiles = []
gemfiles << "activerecord-gemfiles/#{ENV["ACTIVERECORD_GEMFILE"]}.gemfile" if ENV["ACTIVERECORD_GEMFILE"]
gemfiles ... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader.rb | Ruby | mit | 233 | master | 572 | # frozen_string_literal: true
require_relative "n1_loader/version"
require_relative "n1_loader/core/loader_builder"
require_relative "n1_loader/core/loader"
require_relative "n1_loader/core/loader_collection"
require_relative "n1_loader/core/loadable"
require_relative "n1_loader/core/preloader"
module N1Loader # :no... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/ar_lazy_preload.rb | Ruby | mit | 233 | master | 858 | # frozen_string_literal: true
# Load core library
require_relative "active_record"
# Load integration dependency
require "rails"
require "ar_lazy_preload"
# Library integration
require_relative "ar_lazy_preload/loadable"
require_relative "ar_lazy_preload/context_adapter"
require_relative "ar_lazy_preload/associated_... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/active_record.rb | Ruby | mit | 233 | master | 1,060 | # frozen_string_literal: true
# Load core library
require_relative "../n1_loader"
# Load integration dependency
require "active_record"
module N1Loader
module ActiveRecord
class InvalidPreloading < N1Loader::Error; end
end
end
# Library integration
ActiveSupport.on_load(:active_record) do
require_relative... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/goldiloader.rb | Ruby | mit | 233 | master | 740 | # frozen_string_literal: true
# Load core library
require_relative "active_record"
# Load integration dependency
require "goldiloader"
# Library integration
require_relative "goldiloader/loadable"
require_relative "goldiloader/context_adapter"
require_relative "goldiloader/loader_collection_patch"
require_relative "... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/ar_lazy_preload/context_adapter.rb | Ruby | mit | 233 | master | 1,105 | # frozen_string_literal: true
module N1Loader
module ArLazyPreload
# Context adapter for injected N1Loader loaders.
class ContextAdapter
attr_reader :context
delegate_missing_to :context
def initialize(context)
@context = context
end
# Assign initialized preloader to ... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/ar_lazy_preload/associated_context_builder.rb | Ruby | mit | 233 | master | 705 | # frozen_string_literal: true
module N1Loader
module ArLazyPreload
# Context builder for N1Loader
class AssociatedContextBuilder < ::ArLazyPreload::AssociatedContextBuilder
attr_reader :records
def initialize(parent_context:, association_name:, records:)
super(parent_context: parent_cont... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/ar_lazy_preload/loader_patch.rb | Ruby | mit | 233 | master | 595 | # frozen_string_literal: true
module N1Loader
module ArLazyPreload
# A patch to {N1Loader::Loader} to setup lazy context lazily.
module LoaderPatch
attr_accessor :context_setup
def loaded?
return true if @already_loaded && @already_context
super
synchronize { non_thread... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/ar_lazy_preload/preloader_patch.rb | Ruby | mit | 233 | master | 502 | # frozen_string_literal: true
module N1Loader
module ArLazyPreload
# A patch to {N1Loader::Preloader} setup lazy context lazily.
module PreloaderPatch
def initialize(elements, context_setup = nil)
super(elements)
@context_setup = context_setup
end
def preload(*keys)
... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/ar_lazy_preload/loader.rb | Ruby | mit | 233 | master | 1,396 | # frozen_string_literal: true
# Raised when a single object without ArLazyPreload context support was passed to an isolated loader.
N1Loader::Loader::UnsupportedArLazyPreload = Class.new(StandardError)
# Defines a singleton method method that allows isolated loaders
# to use ArLazyPreload context without passing sibl... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/ar_lazy_preload/context.rb | Ruby | mit | 233 | master | 322 | # frozen_string_literal: true
# Returns cached N1Loader::LoaderCollection from context for a loader.
# In case there is none yet, saves passed block to a cache.
ArLazyPreload::Contexts::BaseContext.define_method :fetch_n1_loader_collection do |loader, &block|
(@n1_loader_collections ||= {})[loader] ||= block.call
en... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/ar_lazy_preload/loadable.rb | Ruby | mit | 233 | master | 334 | # frozen_string_literal: true
module N1Loader
module ArLazyPreload
module Loadable # :nodoc:
def n1_loader(name)
return n1_loaders[name] if n1_loaders[name]
ContextAdapter.new(lazy_preload_context).try_preload_lazily(name) if respond_to?(:lazy_preload_context)
super
end
... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/ar_lazy_preload/loader_collection_patch.rb | Ruby | mit | 233 | master | 397 | # frozen_string_literal: true
module N1Loader
module ArLazyPreload
# A patch to {N1Loader::LoaderCollection} to setup lazy context lazily.
module LoaderCollectionPatch
attr_accessor :context_setup
def with(**args)
result = super
result.context_setup = context_setup if context_se... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/active_record/associations_preloader_v6.rb | Ruby | mit | 233 | master | 929 | # frozen_string_literal: true
module N1Loader
module ActiveRecord
module Associations
module Preloader # :nodoc:
N1LoaderReflection = Struct.new(:name, :loader) do
def options
{}
end
end
def preloaders_for_reflection(reflection, records, scope)
... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/active_record/associations_preloader_v5.rb | Ruby | mit | 233 | master | 1,185 | # frozen_string_literal: true
module N1Loader
module ActiveRecord
module Associations
module Preloader # :nodoc:
N1LoaderReflection = Struct.new(:name, :loader) do
def options
{}
end
end
def preloaders_for_one(association, records, scope)
g... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/active_record/base.rb | Ruby | mit | 233 | master | 340 | # frozen_string_literal: true
module N1Loader
module ActiveRecord
# Extension module for ActiveRecord::Base
module Base
extend ActiveSupport::Concern
include N1Loader::Loadable
# Clear N1Loader cache on reloading the object
def reload(*)
n1_clear_cache
super
en... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/active_record/associations_preloader.rb | Ruby | mit | 233 | master | 1,436 | # frozen_string_literal: true
module N1Loader
module ActiveRecord
module Associations
module Preloader # :nodoc:
N1LoaderReflection = Struct.new(:name, :loader) do
def options
{}
end
def deprecated?
false
end
def through_re... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/active_record/loader_collection.rb | Ruby | mit | 233 | master | 448 | # frozen_string_literal: true
N1Loader::LoaderCollection.define_method :preloaded_records do
raise N1Loader::ActiveRecord::InvalidPreloading, "Cannot preload loader with arguments" if loader_class.arguments
with.preloaded_records
end
N1Loader::LoaderCollection.define_method :runnable_loaders do
[self]
end
N1L... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/goldiloader/context.rb | Ruby | mit | 233 | master | 317 | # frozen_string_literal: true
# Returns cached N1Loader::LoaderCollection from context for a loader.
# In case there is none yet, saves passed block to a cache.
Goldiloader::AutoIncludeContext.define_method :fetch_n1_loader_collection do |loader, &block|
(@n1_loader_collections ||= {})[loader] ||= block.call
end |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/goldiloader/loader_collection_patch.rb | Ruby | mit | 233 | master | 395 | # frozen_string_literal: true
module N1Loader
module Goldiloader
# A patch to {N1Loader::LoaderCollection} to setup lazy context lazily.
module LoaderCollectionPatch
attr_accessor :context_setup
def with(**args)
result = super
result.context_setup = context_setup if context_setu... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/goldiloader/loader_patch.rb | Ruby | mit | 233 | master | 593 | # frozen_string_literal: true
module N1Loader
module Goldiloader
# A patch to {N1Loader::Loader} to setup lazy context lazily.
module LoaderPatch
attr_accessor :context_setup
def loaded?
return true if @already_loaded && @already_context
super
synchronize { non_thread_s... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/goldiloader/loader.rb | Ruby | mit | 233 | master | 1,168 | # frozen_string_literal: true
# Raised when a single object without Goldiloader context support was passed to an isolated loader.
N1Loader::Loader::UnsupportedGoldiloader = Class.new(StandardError)
# Defines a singleton method that allows isolated loaders
# to use Goldiloader context without passing sibling records.
... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/goldiloader/loadable.rb | Ruby | mit | 233 | master | 332 | # frozen_string_literal: true
module N1Loader
module Goldiloader
module Loadable # :nodoc:
def n1_loader(name)
return n1_loaders[name] if n1_loaders[name]
ContextAdapter.new(auto_include_context).try_preload_lazily(name) if respond_to?(:auto_include_context)
super
end
en... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/goldiloader/context_adapter.rb | Ruby | mit | 233 | master | 1,006 | # frozen_string_literal: true
module N1Loader
module Goldiloader
# Context adapter for injected N1Loader loaders.
class ContextAdapter
attr_reader :context
def initialize(context)
@context = context
end
# Trigger preloading for +association_name+ across all models in the con... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/goldiloader/preloader_patch.rb | Ruby | mit | 233 | master | 503 | # frozen_string_literal: true
module N1Loader
module Goldiloader
# A patch to {N1Loader::Preloader} to setup lazy context lazily.
module PreloaderPatch
def initialize(elements, context_setup = nil)
super(elements)
@context_setup = context_setup
end
def preload(*keys)
... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/core/loadable.rb | Ruby | mit | 233 | master | 2,167 | # frozen_string_literal: true
module N1Loader
# The module to be included to the class to define associated loaders.
#
# class Example
# include N1Loader::Loadable
#
# # with inline loader
# n1_optimized :something do
# def perform(elements)
# elements.each { |element| ful... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/core/loader_builder.rb | Ruby | mit | 233 | master | 325 | # frozen_string_literal: true
module N1Loader
# The class builds {N1Loader::Loader}
class LoaderBuilder
def self.build(&block)
Class.new(N1Loader::Loader) do
if block.arity == 1
define_method(:perform, &block)
else
class_eval(&block)
end
end
end
end... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/core/preloader.rb | Ruby | mit | 233 | master | 1,063 | # frozen_string_literal: true
module N1Loader
# Preloader that lazily preloads data to every element.
#
# It supports multiple keys.
#
# It supports elements that have different loaders under the same key.
# It will properly preload data to each of the element of the similar group.
class Preloader
at... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/core/loader.rb | Ruby | mit | 233 | master | 4,084 | # frozen_string_literal: true
module N1Loader
# Loader that performs the loading.
#
# Subclasses must define +perform+ method that accepts single argument
# and returns hash where key is the element and value is what we want to load.
class Loader
prepend MonitorMixin
class << self
attr_reader ... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | lib/n1_loader/core/loader_collection.rb | Ruby | mit | 233 | master | 513 | # frozen_string_literal: true
module N1Loader
# The class is used for storing collections of loaders for elements per set of arguments.
class LoaderCollection
attr_reader :loader_class, :elements
def initialize(loader_class, elements)
@loader_class = loader_class
@elements = elements
end
... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | spec/goldiloader_spec.rb | Ruby | mit | 233 | master | 6,631 | # frozen_string_literal: true
RSpec.describe "N1Loader Goldiloader integration" do
require_relative "../lib/n1_loader/goldiloader"
before do
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.connection.tables.each do |table|
ActiveRecord::Base.conne... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | spec/ar_lazy_preload_spec.rb | Ruby | mit | 233 | master | 8,291 | # frozen_string_literal: true
RSpec.describe "N1Loader AR Lazy Preload integration" do
require_relative "../lib/n1_loader/ar_lazy_preload"
ActiveSupport.on_load(:active_record) do
ActiveRecord::Base.include(ArLazyPreload::Base)
ActiveRecord::Relation.prepend(ArLazyPreload::Relation)
ActiveRecord::Ass... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | spec/activerecord_spec.rb | Ruby | mit | 233 | master | 9,818 | # frozen_string_literal: true
RSpec.describe "N1Loader ActiveRecord integration" do
require_relative "../lib/n1_loader/active_record"
before do
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Base.connection.tables.each do |table|
ActiveRecord::Base.co... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | spec/n1_loader_spec.rb | Ruby | mit | 233 | master | 17,212 | # frozen_string_literal: true
RSpec.describe N1Loader do
let(:loader) do
Class.new(N1Loader::Loader) do
def perform(elements)
elements.each { |element| fulfill(element, [element]) }
end
end
end
let(:klass) do
custom_loader = loader
Class.new do
include N1Loader::Loadab... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | spec/spec_helper.rb | Ruby | mit | 233 | master | 593 | # frozen_string_literal: true
require "n1_loader"
require "db-query-matchers"
DBQueryMatchers.configure do |config|
config.schemaless = true
end
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
# Disable RSpec ex... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | examples/goldiloader_integration.rb | Ruby | mit | 233 | master | 706 | # frozen_string_literal: true
require "n1_loader/goldiloader"
require_relative "context/setup_database"
class User < ActiveRecord::Base
has_many :payments
n1_optimized :payments_total do |users|
total_per_user = Payment.group(:user_id).where(user: users).sum(:amount).tap { |h| h.default = 0 }
users.eac... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | examples/isolated_loader.rb | Ruby | mit | 233 | master | 335 | require 'n1_loader'
class IsolatedLoader < N1Loader::Loader
def perform(elements)
elements.each { |element| fulfill(element, [element]) }
end
end
objects = [1, 2, 3, 4]
loader = IsolatedLoader.new(objects)
objects.each do |object|
loader.for(object) # => it has no N+1 and it doesn't require to be injected i... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | examples/shared_loader.rb | Ruby | mit | 233 | master | 721 | require 'n1_loader'
require_relative 'context/service'
# Loader that will be shared between multiple classes
class SharedLoader < N1Loader::Loader
def perform(objects)
data = Service.receive(objects)
objects.each_with_index do |user, index|
fulfill(user, data[index])
end
end
end
class User
i... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | examples/ar_lazy_integration_with_isolated_loader.rb | Ruby | mit | 233 | master | 880 | # frozen_string_literal: true
require "n1_loader/ar_lazy_preload"
require_relative 'context/setup_ar_lazy'
require_relative 'context/setup_database'
class Loader < N1Loader::Loader
def perform(users)
total_per_user = Payment.group(:user_id).where(user: users).sum(:amount).tap { |h| h.default = 0 }
users.e... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | examples/goldiloader_integration_with_isolated_loader.rb | Ruby | mit | 233 | master | 757 | # frozen_string_literal: true
require "n1_loader/goldiloader"
require_relative "context/setup_database"
class Loader < N1Loader::Loader
def perform(users)
total_per_user = Payment.group(:user_id).where(user: users).sum(:amount).tap { |h| h.default = 0 }
users.each do |user|
total = total_per_user[us... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | examples/arguments_support.rb | Ruby | mit | 233 | master | 1,736 | # frozen_string_literal: true
require "n1_loader/active_record"
require_relative 'context/setup_database'
class User < ActiveRecord::Base
has_many :payments
n1_optimized :payments_total do
# Arguments can be:
# argument :something, optional: true
# argument :something, default: -> { 100 }
#
... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | examples/core.rb | Ruby | mit | 233 | master | 1,162 | # frozen_string_literal: true
require "n1_loader"
require_relative 'context/service'
# Class that wants to request 3rd party service without N+1
class User
include N1Loader::Loadable
def unoptimized_call
Service.receive(self)[0]
end
n1_optimized :optimized_call do |users|
data = Service.receive(use... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | examples/lazy_loading.rb | Ruby | mit | 233 | master | 607 | require 'n1_loader'
require_relative 'context/service'
# Class that wants to request 3rd party service without N+1
class User
include N1Loader::Loadable
n1_optimized :optimized_call do |users|
data = Service.receive(users)
users.each_with_index do |user, index|
fulfill(user, data[index])
end
... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | examples/ar_lazy_integration.rb | Ruby | mit | 233 | master | 813 | # frozen_string_literal: true
require "n1_loader/ar_lazy_preload"
require_relative 'context/setup_ar_lazy'
require_relative 'context/setup_database'
class User < ActiveRecord::Base
has_many :payments
n1_optimized :payments_total do |users|
total_per_user = Payment.group(:user_id).where(user: users).sum(:amo... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | examples/graphql.rb | Ruby | mit | 233 | master | 1,183 | # frozen_string_literal: true
require "n1_loader/ar_lazy_preload"
require 'graphql'
require_relative 'context/setup_database'
require_relative 'context/setup_ar_lazy'
class User < ActiveRecord::Base
has_many :payments
n1_optimized :payments_total do |users|
total_per_user = Payment.group(:user_id).where(use... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | examples/single_case.rb | Ruby | mit | 233 | master | 706 | require 'n1_loader'
require_relative 'context/service'
# Loader that will be shared between multiple classes
class OptimizedLoader < N1Loader::Loader
def perform(objects)
data = Service.receive(objects)
objects.each_with_index do |user, index|
fulfill(user, data[index])
end
end
def single(ob... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | examples/active_record_integration.rb | Ruby | mit | 233 | master | 835 | # frozen_string_literal: true
require "n1_loader/active_record"
require_relative 'context/setup_database'
class User < ActiveRecord::Base
has_many :payments
n1_optimized :payments_total do |users|
total_per_user = Payment.group(:user_id).where(user: users).sum(:amount).tap { |h| h.default = 0 }
users.e... |
github | djezzzl/n1_loader | https://github.com/djezzzl/n1_loader | examples/n1_bind_to.rb | Ruby | mit | 233 | master | 879 | # frozen_string_literal: true
require "n1_loader"
require_relative 'context/service'
# Class that wants to request 3rd party service without N+1
class User
include N1Loader::Loadable
n1_optimized :optimized_call do |users|
data = Service.receive(users)
users.each_with_index do |user, index|
fulfi... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.