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 | gosu/fidgit | https://github.com/gosu/fidgit | examples/message_dialog_example.rb | Ruby | mit | 45 | master | 2,214 | require_relative 'helpers/example_window'
# Example for Button and ToggleButton
class ExampleState < Fidgit::GuiState
def initialize
super
vertical do
my_label = label "Why not open a dialog? You know you want to!", tip: "I'm a label"
button("Open an ok message dialog") do
message "Syst... |
github | gosu/fidgit | https://github.com/gosu/fidgit | examples/text_area_example.rb | Ruby | mit | 45 | master | 809 | require_relative 'helpers/example_window'
class ExampleState < Fidgit::GuiState
def initialize
super
string = "<c=3333ff>Hello, my name</c> is <c=ff0000>Brian</c> the snail!"
horizontal do
vertical do
label 'disabled'
text_area(text: "Can't even select this text", width: 200, enabl... |
github | gosu/fidgit | https://github.com/gosu/fidgit | examples/color_well_example.rb | Ruby | mit | 45 | master | 517 | require_relative 'helpers/example_window'
class ExampleState < Fidgit::GuiState
def initialize
super
vertical do
my_label = label "No color selected."
group do
grid num_columns: 15, padding: 0, spacing: 4 do
150.times do
color_well(color: Gosu::Color.rgb(rand(255),... |
github | gosu/fidgit | https://github.com/gosu/fidgit | examples/splash_example.rb | Ruby | mit | 45 | master | 1,110 | require_relative 'helpers/example_window'
# By using a splash screen of some sort, one can switch to another resolution for the main game.
class ExampleState < Fidgit::GuiState
def initialize
super
vertical do
horizontal do
text = label "Width:"
@width_combo = combo_box(value: [640, 48... |
github | gosu/fidgit | https://github.com/gosu/fidgit | examples/color_picker_example.rb | Ruby | mit | 45 | master | 303 | require_relative 'helpers/example_window'
class ExampleState < Fidgit::GuiState
def initialize
super
vertical do
my_label = label 'No color picked'
color_picker(width: 100) do |sender, color|
my_label.text = color.to_s
end
end
end
end
ExampleWindow.new.show |
github | gosu/fidgit | https://github.com/gosu/fidgit | examples/scroll_window_example.rb | Ruby | mit | 45 | master | 1,354 | require_relative 'helpers/example_window'
# Example for Button and ToggleButton
class ExampleState < Fidgit::GuiState
HEIGHT = 225
WIDTH = 140
def initialize
super
vertical do
horizontal do
[
[20, "All cheer the ascendancy of number "], # Should have both scrollers
... |
github | gosu/fidgit | https://github.com/gosu/fidgit | examples/align_example.rb | Ruby | mit | 45 | master | 1,646 | require_relative 'helpers/example_window'
# Change font and labels in the schema.
Fidgit::Element.schema.merge_elements!(Element: { font_height: 24 }, Label: { background_color: "?dark_blue" })
class ExampleState < Fidgit::GuiState
ROW_BACKGROUND = Gosu::Color.rgb(0, 100, 0)
CELL_BACKGROUND = Gosu::Color.rgb(100,... |
github | gosu/fidgit | https://github.com/gosu/fidgit | examples/radio_button_example.rb | Ruby | mit | 45 | master | 718 | require_relative 'helpers/example_window'
class ExampleState < Fidgit::GuiState
def initialize
super
vertical do
my_label = label "No button selected"
button("Deselect") do
@group.value = nil
end
button("Select #7") do
@group.value = 7
end
@group = grou... |
github | gosu/fidgit | https://github.com/gosu/fidgit | examples/helpers/example_window.rb | Ruby | mit | 45 | master | 562 | require_relative '../../lib/fidgit'
media_dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'media'))
Gosu::Image.autoload_dirs << File.join(media_dir, 'images')
Gosu::Sample.autoload_dirs << File.join(media_dir, 'samples')
Gosu::Font.autoload_dirs << File.join(media_dir, 'fonts')
class ExampleWindow < C... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit.rb | Ruby | mit | 45 | master | 1,875 | require 'chingu'
require 'clipboard'
require_relative "fidgit/cursor"
require_relative "fidgit/event"
require_relative "fidgit/history"
require_relative "fidgit/redirector"
require_relative "fidgit/schema"
require_relative "fidgit/selection"
require_relative "fidgit/version"
require_relative "fidgit/window"
require_r... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/event.rb | Ruby | mit | 45 | master | 5,620 | module Fidgit
# Adds simple event handling methods to an object (subscribe/publish pattern).
#
# @example
# class JumpingBean
# include Event
# event :jump
# end
#
# bean = JumpingBean.new
# bean.subscribe :jump do
# puts "Whee!"
# end
#
# bean.subscribe :jump do |obj... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/cursor.rb | Ruby | mit | 45 | master | 796 | module Fidgit
class Cursor < Chingu::GameObject
ARROW = 'arrow.png'
HAND = 'hand.png'
def initialize(options = {})
options = {
image: Gosu::Image[ARROW],
rotation_center: :top_left,
zorder: Float::INFINITY
}.merge!(options)
super(options)
nil
end
... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/selection.rb | Ruby | mit | 45 | master | 2,081 | module Fidgit
class Selection
MIN_DRAG_DISTANCE = 2
def size; @items.size; end
def empty?; @items.empty?; end
def [](index); @items[index]; end
def each(&block); @items.each(&block); end
def to_a; @items.dup; end
def include?(object); @items.include? object; end
# Current being dragg... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/window.rb | Ruby | mit | 45 | master | 208 | module Fidgit
module Window
def self.included(base)
base.send :include, Methods
end
module Methods
def close
super
GuiState.clear
end
end
end
end |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/redirector.rb | Ruby | mit | 45 | master | 2,553 | module Fidgit
# Redirects methods to an object, but does not mask methods and ivars from the calling context.
module RedirectorMethods
# Evaluate a block accessing methods and ivars from the calling context, but calling public methods
# (not ivars or non-public methods) on this object in preference.
def... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/history.rb | Ruby | mit | 45 | master | 2,635 | module Fidgit
# Manages a history of actions, along with doing, undoing and redoing those actions.
class History
# Maximum number of actions in the History before Actions are deleted.
DEFAULT_MAX_SIZE = 250
# An action in the History. Inherit actions from this in order to add them to a History.
cla... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/schema.rb | Ruby | mit | 45 | master | 4,139 | module Fidgit
# An object that manages Schema values. Usually loaded from a YAML file.
#
# @example
# schema = Schema.new(YAML.load(file.read('default_schema.yml')))
# default_color = schema.default(Element, :disabled, :color)
# schema.merge_schema!(YAML.load(file.read('override_schema.yml'))
# ov... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/radio_button.rb | Ruby | mit | 45 | master | 1,892 | module Fidgit
class RadioButton < Button
attr_reader :group, :value
event :changed
def checked?; @checked; end
# @param (see Button#initialize)
# @param [Object] value
#
# @option (see Button#initialize)
# @option options [Boolean] :checked
def initialize(text, value, options = ... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/grid.rb | Ruby | mit | 45 | master | 7,074 | module Fidgit
# A vertically aligned element packing container.
class Grid < Packer
# @return [Symbol]
attr_reader :type
# @return [Integer]
attr_reader :num_rows
# @return [Integer]
attr_reader :num_columns
# @note Currently only supports +num_columns+ mode (not +num_rows+).
#
... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/text_area.rb | Ruby | mit | 45 | master | 14,071 | module Fidgit
class TextArea < Element
TAGS_PATTERN = %r%<[a-z](?:=[a-f0-9]+)?>|</[a-z]>%i
# @return [Number]
attr_reader :min_height
# @return [Number]
attr_reader :max_height
# @return [Number]
attr_reader :line_spacing
# @param [Boolean] value
# @return [Boolean]
attr_wri... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/text_line.rb | Ruby | mit | 45 | master | 2,255 | module Fidgit
# Used internally by the label.
class TextLine < Element
VALID_JUSTIFICATION = [:left, :right, :center]
attr_reader :color, :justify
def color=(color)
raise ArgumentError.new("Text must be a Gosu::Color") unless color.is_a? Gosu::Color
@color = color.dup
color
end... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/scroll_bar.rb | Ruby | mit | 45 | master | 3,565 | module Fidgit
# @abstract
class ScrollBar < Composite
class Handle < Element
event :begin_drag
event :update_drag
event :end_drag
def drag?(button); button == :left; end
def initialize(options = {})
super options
subscribe :begin_drag do |sender, x, y|
... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/file_browser.rb | Ruby | mit | 45 | master | 4,728 | module Fidgit
class FileBrowser < Composite
VALID_TYPES = [:open, :save]
event :selected
attr_reader :pattern, :base_directory
def show_extension?; @show_extension; end
def directory
dir = File.join(*@directories)
dir = File.join(@base_directory, dir) unless @base_directory.empty?
... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/element.rb | Ruby | mit | 45 | master | 9,385 | # The Fidgit GUI framework for Gosu.
module Fidgit
class << self
attr_accessor :debug_mode
end
self.debug_mode = false
def self.debug_mode?; debug_mode; end
# An element within the GUI environment.
# @abstract
class Element
include Event
event :left_mouse_button
event :holding_left_mou... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/button.rb | Ruby | mit | 45 | master | 3,030 | module Fidgit
class Button < Label
# @param (see Label#initialize)
# @option (see Label#initialize)
# @option options [Symbol] :shortcut (nil) Adds a shortcut key for this element, that activates it. :auto takes the first letter of the text.
def initialize(text, options = {}, &block)
options = {... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/list.rb | Ruby | mit | 45 | master | 932 | module Fidgit
class List < Composite
class Item < RadioButton
end
event :changed
def size; @items.size; end
def clear; @items.clear; end
def initialize(options = {})
options = {
background_color: default(:background_color),
border_color: default(:border_color),
}... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/menu_pane.rb | Ruby | mit | 45 | master | 4,147 | require 'forwardable'
module Fidgit
class MenuPane < Composite
# An item within the menu.
class Item < Button
attr_reader :value, :shortcut_text
# @param (see Button#initialize)
#
# @option (see Button#initialize)
# @param [any] value Value if the user picks this item
# @... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/slider.rb | Ruby | mit | 45 | master | 3,533 | module Fidgit
class Slider < Composite
# @private
class Handle < Element
event :begin_drag
event :end_drag
event :update_drag
def drag?(button); button == :left; end
# @param (see Element#initialize)
#
# @option (see Element#initialize)
def initialize(options ... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/scroll_area.rb | Ruby | mit | 45 | master | 1,802 | module Fidgit
# A basic scrolling area. It is not managed in any way (use ScrollWindow for that).
class ScrollArea < Container
# @return [Vertical] The content shown within this ScrollArea
attr_reader :content
def offset_x; x - @content.x; end
def offset_y; y - @content.y; end
def offset_x=(va... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/group.rb | Ruby | mit | 45 | master | 1,428 | module Fidgit
class Group < Packer
attr_reader :selected
event :changed
def value; @selected ? @selected.value : nil; end
# @example
# group do
# horizontal do
# radio_button 1, text: '1', checked: true
# radio_button 2, text: '2'
# subscribe :changed do ... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/main_packer.rb | Ruby | mit | 45 | master | 591 | require_relative "vertical"
module Fidgit
# Main container that can contains a single "proper" packing element.
class MainPacker < Vertical
def initialize(options = {})
options = {
width: $window.width,
height: $window.height,
}.merge! options
super options
end
d... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/combo_box.rb | Ruby | mit | 45 | master | 2,244 | require 'forwardable'
module Fidgit
class ComboBox < Button
extend Forwardable
ARROW_IMAGE = "combo_arrow.png"
def_delegators :@menu, :each
event :changed
def index; @menu.index(@value) end
def value; @value; end
def value=(value)
if @value != value
@value = value
item = @menu.find... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/packer.rb | Ruby | mit | 45 | master | 1,165 | module Fidgit
# Container that auto-packs elements.
#
# @abstract
class Packer < Container
attr_reader :spacing_h, :spacing_v
# @param (see Container#initialize)
#
# @option (see Container#initialize)
def initialize(options = {})
options = {
}.merge! options
@spacing_h = ... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/container.rb | Ruby | mit | 45 | master | 4,911 | require 'forwardable'
module Fidgit
# A container that contains Elements.
# @abstract
class Container < Element
extend Forwardable
def_delegators :@children, :size, :each, :find, :index, :[], :empty?, :map, :select, :inject
def x=(value)
@children.each {|c| c.x += value - x }
super(valu... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/composite.rb | Ruby | mit | 45 | master | 462 | module Fidgit
# A composite element, made up of other elements (but manages them internally).
class Composite < Packer
DEBUG_BORDER_COLOR = Gosu::Color.rgba(0, 255, 0, 100) # Color to draw an outline in when debugging layout.
# @param (see Element#initialize)
#
# @option (see Element#initialize)
... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/toggle_button.rb | Ruby | mit | 45 | master | 1,743 | module Fidgit
# A button that toggles its value from false<->true when clicked.
class ToggleButton < Button
event :changed
attr_reader :value
def value=(value); @value = value; update_status; end
# @param (see Button#initialize)
#
# @option (see Button#initialize)
def initialize(text, ... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/tool_tip.rb | Ruby | mit | 45 | master | 864 | module Fidgit
class ToolTip < TextLine
def x=(value); super(value); recalc; value; end
def y=(value); super(value); recalc; value; end
def hit?(x, y); false; end
# @param (see Label#initialize)
#
# @option (see Label#initialize)
def initialize(options = {}, &block)
options = {
... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/scroll_window.rb | Ruby | mit | 45 | master | 2,352 | module Fidgit
class ScrollWindow < Composite
def content; @view.content; end
def offset_x; @view.offset_x; end
def offset_x=(value); @view.offset_x = value; end
def offset_y; @view.offset_y; end
def offset_y=(value); @view.offset_y = value; end
def view_width; @view.width; end
def view_he... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/color_picker.rb | Ruby | mit | 45 | master | 1,603 | module Fidgit
class ColorPicker < Composite
CHANNELS = [:red, :green, :blue]
DEFAULT_CHANNEL_NAMES = CHANNELS.map {|c| c.to_s.capitalize }
INDICATOR_HEIGHT = 25
event :changed
def color; @color.dup; end
def color=(value)
@color = value.dup
CHANNELS.each do |channel|
@sl... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/label.rb | Ruby | mit | 45 | master | 2,986 | module Fidgit
class Label < Composite
ICON_POSITIONS = [:top, :bottom, :left, :right]
attr_reader :icon_position
attr_accessor :background_color, :border_color
def_delegators :@text, :text, :color, :font, :color=, :text=
def icon; @icon ? @icon.image : nil; end
def hit_element(x, y)
... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/image_frame.rb | Ruby | mit | 45 | master | 1,593 | module Fidgit
# A wrapper around a Gosu::Image to show it in the GUI.
class ImageFrame < Element
ENABLED_COLOR = Gosu::Color::WHITE
DISABLED_COLOR = Gosu::Color.rgb(150, 150, 150)
attr_reader :image, :factor_x, :factor_y
def thumbnail?; @thumbnail; end
# @param (see Element#initialize)
# ... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/elements/color_well.rb | Ruby | mit | 45 | master | 859 | module Fidgit
class ColorWell < RadioButton
alias_method :color, :value
# @param (see RadioButton#initialize)
# @option (see RadioButton#initialize)
def initialize(options = {}, &block)
options = {
width: default(:width),
height: default(:height),
color: default(:color),... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/states/gui_state.rb | Ruby | mit | 45 | master | 9,831 | require 'forwardable'
module Fidgit
class GuiState < Chingu::GameState
# A 1x1 white pixel used for drawing.
PIXEL_IMAGE = 'pixel.png'
extend Forwardable
def_delegators :@container, :horizontal, :vertical, :grid
# The Container that contains all the elements for this GuiState.
# @return [P... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/states/dialog_state.rb | Ruby | mit | 45 | master | 1,721 | module Fidgit
# A modal dialog.
# @abstract
class DialogState < GuiState
DEFAULT_BACKGROUND_COLOR = Gosu::Color.rgb(75, 75, 75)
DEFAULT_BORDER_COLOR = Gosu::Color.rgb(255, 255, 255)
DEFAULT_SHADOW_COLOR = Gosu::Color.rgba(0, 0, 0, 100)
DEFAULT_SHADOW_OFFSET = 8
def initialize(options = {})
... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/states/file_dialog.rb | Ruby | mit | 45 | master | 636 | module Fidgit
# A simple dialog that manages a message with a set of buttons beneath it.
class FileDialog < DialogState
def initialize(type, options = {}, &block)
options = {
show: true,
background_color: DEFAULT_BACKGROUND_COLOR,
border_color: DEFAULT_BORDER_COLOR,
}.merge! ... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/states/message_dialog.rb | Ruby | mit | 45 | master | 2,090 | module Fidgit
# A simple dialog that manages a message with a set of buttons beneath it.
class MessageDialog < DialogState
VALID_TYPES = [:ok, :ok_cancel, :yes_no, :yes_no_cancel, :quit_cancel, :quit_save_cancel]
attr_reader :type
# @param [String] message
#
# @option options [Symbol] :type (:... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/standard_ext/hash.rb | Ruby | mit | 45 | master | 646 | class Hash
# Merge not only the hashes, but all nested hashes as well.
# Written by Stefan Rusterholz (apeiros) from http://www.ruby-forum.com/topic/142809
def deep_merge!(other)
merger = lambda do |key, a, b|
(a.is_a?(Hash) && b.is_a?(Hash)) ? a.merge!(b, &merger) : b
end
merge!(other, &merger... |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/gosu_ext/image.rb | Ruby | mit | 45 | master | 252 | module Gosu
EmptyImageSource = Struct.new(:columns, :rows) do
def to_blob
"\0\0\0\0" * (columns * rows)
end
end
class Image
def self.create(width, height)
self.new(EmptyImageSource.new(width, height))
end
end
end |
github | gosu/fidgit | https://github.com/gosu/fidgit | lib/fidgit/gosu_ext/color.rb | Ruby | mit | 45 | master | 3,603 | module Gosu
class Color
# Is the color completely transparent?
def transparent?; alpha == 0; end
# Is the color completely opaque?
def opaque?; alpha == 255; end
# RGB in 0..255 format (Alpha assumed 255)
#
# @param [Integer] red
# @param [Integer] green
# @param [Integer] blue
... |
github | gosu/fidgit | https://github.com/gosu/fidgit | spec/fidgit/redirector_spec.rb | Ruby | mit | 45 | master | 2,305 | require_relative 'helpers/helper'
require 'redirector'
include Fidgit
describe RedirectorMethods do
describe "::Object" do
subject { Object.new }
describe '#instance_methods_eval' do
it "should fail if a block is not provided" do
->{ subject.instance_methods_eval }.should raise_error
... |
github | gosu/fidgit | https://github.com/gosu/fidgit | spec/fidgit/event_spec.rb | Ruby | mit | 45 | master | 7,474 | require_relative 'helpers/helper'
require 'event'
module Fidgit
describe Event do
before :each do
class Test
include Event
end
end
after :each do
Fidgit.send :remove_const, :Test
end
subject { Test }
describe "events" do
it "should initially be empty" do
... |
github | gosu/fidgit | https://github.com/gosu/fidgit | spec/fidgit/schema_spec.rb | Ruby | mit | 45 | master | 2,207 | require_relative 'helpers/helper'
require 'fidgit'
SCHEMA_FILE_NAME = File.expand_path(File.join(__FILE__, '..', 'schema_test.yml'))
include Fidgit
describe Schema do
subject { Schema.new(Hash.new) }
context "given the default schema" do
subject { Schema.new(YAML.load(File.read(SCHEMA_FILE_NAME))) }
d... |
github | gosu/fidgit | https://github.com/gosu/fidgit | spec/fidgit/history_spec.rb | Ruby | mit | 45 | master | 3,680 | require_relative 'helpers/helper'
require 'history'
module Fidgit
class History
class Maths < Action
def initialize(value)
@value = value
end
end
class Add < Maths
def do
$x += @value
end
def undo
$x -= @value
end
end
class Sub < Mat... |
github | gosu/fidgit | https://github.com/gosu/fidgit | spec/fidgit/gosu_ext/color_spec.rb | Ruby | mit | 45 | master | 3,797 | require_relative "helpers/helper"
include Gosu
describe Color do
describe "rgb" do
it "should create a color with the correct values from channel values" do
color = Color.rgb(1, 2, 3)
color.red.should equal 1
color.green.should equal 2
color.blue.should equal 3
color.alpha.should e... |
github | gosu/fidgit | https://github.com/gosu/fidgit | spec/fidgit/elements/image_frame_spec.rb | Ruby | mit | 45 | master | 1,806 | require_relative 'helpers/helper'
require 'fidgit'
def check_thumbnail_is_square
{square: [10, 10], tall: [5, 12], wide: [6, 5]}.each_pair do |type, dimensions|
context "with a #{type} image" do
it "should be square and just large enough to contain the image" do
subject = described_class.new(Gosu:... |
github | gosu/fidgit | https://github.com/gosu/fidgit | spec/fidgit/elements/label_spec.rb | Ruby | mit | 45 | master | 810 | require_relative "helpers/helper"
include Fidgit
describe Label do
before :all do
$window = Chingu::Window.new(100, 100, false) unless $window
end
context "with default parameters" do
subject { Label.new( "Hello world!") }
it "should have text value set" do
subject.text.should eq "Hello worl... |
github | skryl/nike | https://github.com/skryl/nike | nike.gemspec | Ruby | mit | 45 | master | 854 | # -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'nike/version'
Gem::Specification.new do |gem|
gem.name = "nike"
gem.version = Nike::VERSION
gem.authors = ["Alex Skryl"]
gem.email = ["rut216@gmail.... |
github | skryl/nike | https://github.com/skryl/nike | lib/nike/client.rb | Ruby | mit | 45 | master | 3,225 | require_relative 'core_ext/hash.rb'
require 'httparty'
require 'hashie'
require 'active_support/core_ext/string/inflections'
class Nike::Client
include HTTParty
# debug_output $stdout
LOGIN_URL = 'https://secure-nikeplus.nike.com/nsl/services/user/login'
BASE_URL = 'http://nikeplus.nike.com/plus'
... |
github | skryl/nike | https://github.com/skryl/nike | lib/nike/mash.rb | Ruby | mit | 45 | master | 2,170 | require 'hashie'
class Nike::Mash < Hashie::Mash
KM_TO_MILE = 0.621371192
CONVERTER_AVAILABILITY = {
distance: [:distance_in_kilometers, :distance_in_miles, :speed_in_mph, :speed_in_kph],
duration: [:duration_in_seconds, :duration_in_minutes, :duration_in_hours, :duration_in_hms],
pace: [:pace_in_... |
github | skryl/nike | https://github.com/skryl/nike | lib/nike/core_ext/hash.rb | Ruby | mit | 45 | master | 648 | class Hash
def deep_merge(other_hash)
dup.deep_merge!(other_hash)
end
def deep_merge!(other_hash)
other_hash.each_pair do |k,v|
tv = self[k]
self[k] = \
if tv.is_a?(Hash) && v.is_a?(Hash)
tv.deep_merge(v)
elsif tv.is_a?(Array) && v.is_a?(Array)
tv + v
... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | sidekiq-debouncer.gemspec | Ruby | mit | 45 | master | 1,521 | # frozen_string_literal: true
lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "sidekiq/debouncer/version"
Gem::Specification.new do |gem|
gem.name = "sidekiq-debouncer"
gem.version = Sidekiq::Debouncer::VERSION
gem.authors = ["Sebastian Zuchmański", "K... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | lib/sidekiq/debouncer.rb | Ruby | mit | 45 | master | 760 | # frozen_string_literal: true
require "sidekiq/debouncer/version"
require "sidekiq/debouncer/errors"
require "sidekiq/debouncer/lua_commands"
require "sidekiq/debouncer/job_builder"
require "sidekiq/debouncer/middleware/client"
require "sidekiq/debouncer/middleware/server"
require "sidekiq/debouncer/job"
module Sidek... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | lib/sidekiq/debouncer/lua_commands.rb | Ruby | mit | 45 | master | 683 | # frozen_string_literal: true
require "digest/sha1"
module Sidekiq
module Debouncer
module LuaCommands
def define_lua_command(command, script)
sha = Digest::SHA1.hexdigest(script)
define_method(command) do |conn, keys, argv|
retryable = true
begin
conn.call(... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | lib/sidekiq/debouncer/job.rb | Ruby | mit | 45 | master | 667 | # frozen_string_literal: true
module Sidekiq
module Debouncer
class Job
attr_reader :key, :score
def initialize(key, score)
@key = key
@score = Float(score)
end
def at
Time.at(score).utc
end
def args
item["args"]
end
def queue
... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | lib/sidekiq/debouncer/launcher.rb | Ruby | mit | 45 | master | 576 | # frozen_string_literal: true
module Sidekiq
module Debouncer
module Launcher
def initialize(config, **kwargs)
@debounce_poller = Sidekiq::Debouncer::Poller.new(config)
super
end
def run
super
@debounce_poller.start
end
def quiet
super
... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | lib/sidekiq/debouncer/job_builder.rb | Ruby | mit | 45 | master | 824 | # frozen_string_literal: true
module Sidekiq
module Debouncer
module JobBuilder
extend Sidekiq::JobUtil
def self.build(job_args, debounce_key)
base_job = nil
final_args = job_args.map do |elem|
if elem.start_with?("{")
base_job = Sidekiq.load_json(elem)
... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | lib/sidekiq/debouncer/enq.rb | Ruby | mit | 45 | master | 933 | # frozen_string_literal: true
require "sidekiq/scheduled"
module Sidekiq
module Debouncer
class Enq < ::Sidekiq::Scheduled::Enq
extend LuaCommands
LUA_ZPOPBYSCORE_WITHSCORE = File.read(File.expand_path("../lua/zpopbyscore_withscore.lua", __FILE__))
LUA_ZPOPBYSCORE_MULTI = File.read(File.expan... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | lib/sidekiq/debouncer/poller.rb | Ruby | mit | 45 | master | 264 | # frozen_string_literal: true
require "sidekiq/scheduled"
module Sidekiq
module Debouncer
class Poller < ::Sidekiq::Scheduled::Poller
def initialize(config)
super
@enq = Sidekiq::Debouncer::Enq.new(config)
end
end
end
end |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | lib/sidekiq/debouncer/web.rb | Ruby | mit | 45 | master | 715 | # frozen_string_literal: true
if defined?(Sidekiq::Web)
require "sidekiq/debouncer/web_extension"
if Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new("8.0.0")
Sidekiq::Web.configure do |config|
config.register(
Sidekiq::Debouncer::WebExtension,
name: "debounces",
tab: "Debo... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | lib/sidekiq/debouncer/web_extension.rb | Ruby | mit | 45 | master | 1,746 | # frozen_string_literal: true
require "base64"
require "sidekiq/api"
require "sidekiq/debouncer/set"
module Sidekiq
module Debouncer
module WebExtension
module Helpers
def get_route_param(key)
if Gem::Version.new(Sidekiq::VERSION) >= Gem::Version.new("8.0.0")
route_params(key... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | lib/sidekiq/debouncer/set.rb | Ruby | mit | 45 | master | 334 | # frozen_string_literal: true
module Sidekiq
module Debouncer
class Set < Sidekiq::JobSet
def initialize
super Sidekiq::Debouncer::SET
end
def fetch_by_key(key)
score = Sidekiq.redis { |conn| conn.zscore(Sidekiq::Debouncer::SET, key) }
Job.new(key, score)
end
... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | lib/sidekiq/debouncer/middleware/server.rb | Ruby | mit | 45 | master | 415 | # frozen_string_literal: true
module Sidekiq
module Debouncer
module Middleware
# wrap args into array because sidekiq uses splat while calling perform
class Server
include Sidekiq::ServerMiddleware
def call(_worker, job, _queue)
if job.key?("debounce_key")
job[... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | lib/sidekiq/debouncer/middleware/client.rb | Ruby | mit | 45 | master | 2,750 | # frozen_string_literal: true
module Sidekiq
module Debouncer
module Middleware
# Middleware used to debounce jobs. If a job has a debounce option it skips normal sidekiq flow and debounces
# job using lua script (thanks to that it's process safe). Script merges new job with existing one and creates
... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | spec/spec_helper.rb | Ruby | mit | 45 | master | 720 | $LOAD_PATH.unshift "lib"
$TESTING = true # standard:disable Style/GlobalVars
require "rspec"
require "timecop"
require "parallel"
require "simplecov"
require "sidekiq/cli"
require "sidekiq/scheduled"
require "sidekiq/processor"
require "sidekiq/api"
require "sidekiq/testing"
require "rack/test"
require "rack/session"... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | spec/support/test_middlewares.rb | Ruby | mit | 45 | master | 638 | # frozen_string_literal: true
class TestMiddleware
def call(_worker_class, job, _queue, _redis_pool)
job["args"][1] = "job 34" if job["args"][1] == "job 33"
yield
end
end
class SecondTestMiddleware
def call(_worker_class, job, _queue, _redis_pool)
job["args"][0] = "ABC" if job["args"][0] == "AB"
... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | spec/support/context.rb | Ruby | mit | 45 | master | 746 | # frozen_string_literal: true
shared_context "sidekiq" do
let(:time_start) { Time.new(2016, 1, 1, 12, 0, 0, 0) }
let(:sidekiq_config) do
Sidekiq.default_configuration.tap do |config|
config.queues = ["default", "sample_queue"]
end
end
let(:queue) { Sidekiq::Queue.new("default") }
let(:sample_qu... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | spec/support/test_workers.rb | Ruby | mit | 45 | master | 973 | # frozen_string_literal: true
class TestWorker
include Sidekiq::Worker
include Sidekiq::Debouncer
sidekiq_options(
queue: "sample_queue",
debounce: {
time: 5 * 60,
by: ->(job_args) {
job_args[0]
}
}
)
def perform(group)
end
end
class TestWorkerWithMultipleArguments
... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | spec/sidekiq/debouncer/enq_spec.rb | Ruby | mit | 45 | master | 4,337 | # frozen_string_literal: true
require "spec_helper"
require_relative "../../support/context"
require_relative "../../support/test_workers"
require_relative "../../support/test_middlewares"
describe Sidekiq::Debouncer::Enq do
include_context "sidekiq"
# Enq is used by puller
context "1 task, 3 minutes break, 1... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | spec/sidekiq/debouncer/set_spec.rb | Ruby | mit | 45 | master | 551 | # frozen_string_literal: true
require "spec_helper"
require_relative "../../support/context"
describe Sidekiq::Debouncer::Set do
include_context "sidekiq"
let(:set) { described_class.new }
describe "#fetch_by_key" do
before do
Sidekiq.redis do |conn|
conn.zadd(Sidekiq::Debouncer::SET, 1, "ke... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | spec/sidekiq/debouncer/launcher_spec.rb | Ruby | mit | 45 | master | 391 | # frozen_string_literal: true
require "sidekiq/cli"
require "spec_helper"
require_relative "../../support/context"
describe Sidekiq::Debouncer::Launcher do
include_context "sidekiq"
it "runs the poller" do
expect_any_instance_of(Sidekiq::Debouncer::Poller).to receive(:start).once
launcher = Sidekiq::Lau... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | spec/sidekiq/debouncer/web_extention_spec.rb | Ruby | mit | 45 | master | 1,374 | # frozen_string_literal: true
require "spec_helper"
require_relative "../../support/context"
require_relative "../../support/test_workers"
describe "Web extension" do
include Rack::Test::Methods
include_context "sidekiq"
let(:app) do
Rack::Builder.new do
use Rack::Session::Pool
run Sidekiq::We... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | spec/sidekiq/debouncer/job_spec.rb | Ruby | mit | 45 | master | 1,003 | # frozen_string_literal: true
require "spec_helper"
require_relative "../../support/context"
require_relative "../../support/test_workers"
describe Sidekiq::Debouncer::Job do
include_context "sidekiq"
let(:job) { described_class.new("debounce/v3/TestWorker/1", 1715472000) }
before do
Sidekiq.redis do |con... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | spec/sidekiq/debouncer/middleware/client_spec.rb | Ruby | mit | 45 | master | 7,117 | # frozen_string_literal: true
require "spec_helper"
require_relative "../../../support/context"
require_relative "../../../support/test_workers"
require_relative "../../../support/test_middlewares"
describe Sidekiq::Debouncer::Middleware::Client do
include_context "sidekiq"
context "task with debounce" do
co... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | spec/sidekiq/debouncer/middleware/server_spec.rb | Ruby | mit | 45 | master | 1,057 | # frozen_string_literal: true
require "spec_helper"
require_relative "../../../support/context"
require_relative "../../../support/test_workers"
require_relative "../../../support/test_middlewares"
describe Sidekiq::Debouncer::Middleware::Server do
include_context "sidekiq"
context "job with debounce" do
it ... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | spec/sidekiq/debouncer/lua/zpopbyscore_withscore_spec.rb | Ruby | mit | 45 | master | 1,030 | # frozen_string_literal: true
require "spec_helper"
require_relative "../../../support/context"
describe "zpopbyscore_withscore" do
include_context "sidekiq"
before do
Sidekiq.redis do |connection|
connection.call("ZADD", "sample_set", "11111111", "key1")
connection.call("ZADD", "sample_set", "11... |
github | paladinsoftware/sidekiq-debouncer | https://github.com/paladinsoftware/sidekiq-debouncer | spec/sidekiq/debouncer/lua/zpopbyscore_multi_spec.rb | Ruby | mit | 45 | master | 1,032 | # frozen_string_literal: true
require "spec_helper"
require_relative "../../../support/context"
describe "zpopbyscore_multi" do
include_context "sidekiq"
before do
Sidekiq.redis do |connection|
connection.call("ZADD", "sample_set", 11111111, "key1")
connection.call("ZADD", "sample_set", 11111112,... |
github | shreyasbharath/cpp-dependency-graph | https://github.com/shreyasbharath/cpp-dependency-graph | Rakefile | Ruby | mit | 45 | master | 230 | # frozen_string_literal: true
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
RuboCop::RakeTask.new
RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = Dir.glob('spec/**/*_spec.rb')
end |
github | shreyasbharath/cpp-dependency-graph | https://github.com/shreyasbharath/cpp-dependency-graph | cpp_dependency_graph.gemspec | Ruby | mit | 45 | master | 1,637 | # frozen_string_literal: true
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'cpp_dependency_graph/version'
Gem::Specification.new do |s|
s.name = 'cpp_dependency_graph'
s.version = CppDependencyGraph::VERSION
s.authors = ['Shreyas Balakrishna']
s.email... |
github | shreyasbharath/cpp-dependency-graph | https://github.com/shreyasbharath/cpp-dependency-graph | spec/spec_helper.rb | Ruby | mit | 45 | master | 546 | # frozen_string_literal: true
require 'bundler/setup'
require 'simplecov'
require 'simplecov-console'
require 'cpp_dependency_graph'
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = '.rspec_status'
# Disable RSpec exposing methods ... |
github | shreyasbharath/cpp-dependency-graph | https://github.com/shreyasbharath/cpp-dependency-graph | spec/test/component_link_spec.rb | Ruby | mit | 45 | master | 948 | # frozen_string_literal: true
require 'cpp_dependency_graph/link'
RSpec.describe Link do
it 'returns correct source attribute' do
expect(Link.new('source', 'target').source).to eq('source')
end
it 'returns correct target attribute' do
expect(Link.new('source', 'target').target).to eq('target')
end
... |
github | shreyasbharath/cpp-dependency-graph | https://github.com/shreyasbharath/cpp-dependency-graph | spec/test/project_spec.rb | Ruby | mit | 45 | master | 1,720 | # frozen_string_literal: true
require 'cpp_dependency_graph/project'
RSpec.describe Project do
it 'parses overall project component' do
component_names = Project.new('spec/test/example_project').project_component.values.map(&:name)
expect(component_names).to contain_exactly('example_project')
end
it 'p... |
github | shreyasbharath/cpp-dependency-graph | https://github.com/shreyasbharath/cpp-dependency-graph | spec/test/include_component_dependency_graph_spec.rb | Ruby | mit | 45 | master | 1,000 | # frozen_string_literal: true
require 'cpp_dependency_graph/include_component_dependency_graph'
require 'cpp_dependency_graph/link'
RSpec.describe IncludeComponentDependencyGraph do
let(:project) { Project.new('spec/test/example_project') }
let(:include_dependency_graph) { IncludeComponentDependencyGraph.new(proj... |
github | shreyasbharath/cpp-dependency-graph | https://github.com/shreyasbharath/cpp-dependency-graph | spec/test/cyclic_link_spec.rb | Ruby | mit | 45 | master | 678 | # frozen_string_literal: true
require 'cpp_dependency_graph/cyclic_link'
RSpec.describe CyclicLink do
it 'returns equal for two objects with the same nodes' do
expect(CyclicLink.new('nodeA', 'nodeB')).to eql(CyclicLink.new('nodeB', 'nodeA'))
end
it 'returns the same hash for two equivalent objects with the... |
github | shreyasbharath/cpp-dependency-graph | https://github.com/shreyasbharath/cpp-dependency-graph | spec/test/source_component_spec.rb | Ruby | mit | 45 | master | 1,127 | # frozen_string_literal: true
require 'cpp_dependency_graph/source_component'
RSpec.describe SourceComponent do
it 'has a name attribute that matches the directory' do
component = SourceComponent.new('spec/test/example_project/Engine')
expect(component.name).to eq('Engine')
end
it 'has a path attribute... |
github | shreyasbharath/cpp-dependency-graph | https://github.com/shreyasbharath/cpp-dependency-graph | spec/test/dir_tree_spec.rb | Ruby | mit | 45 | master | 947 | # frozen_string_literal: true
require 'json'
require 'cpp_dependency_graph/dir_tree'
RSpec.describe DirTree do
let(:dir_tree) { DirTree.new('spec/test/example_project') }
it 'returns empty tree an unknwon directory' do
expect(DirTree.new('asdsadklasd').tree.empty?).to eq(true)
end
it 'returns all direc... |
github | shreyasbharath/cpp-dependency-graph | https://github.com/shreyasbharath/cpp-dependency-graph | spec/test/source_file_spec.rb | Ruby | mit | 45 | master | 1,418 | # frozen_string_literal: true
require 'cpp_dependency_graph/source_file'
RSpec.describe SourceFile do
it 'has a path attribute that matches the path of the file' do
source_file = SourceFile.new('spec/test/example_project/Engine/Engine.cpp')
expect(source_file.path).to eq('spec/test/example_project/Engine/En... |
github | shreyasbharath/cpp-dependency-graph | https://github.com/shreyasbharath/cpp-dependency-graph | spec/test/component_dependency_graph_spec.rb | Ruby | mit | 45 | master | 1,750 | # frozen_string_literal: true
require 'cpp_dependency_graph/component_dependency_graph'
require 'cpp_dependency_graph/link'
RSpec.describe ComponentDependencyGraph do
let(:project) { Project.new('spec/test/example_project') }
let(:dependency_graph) { ComponentDependencyGraph.new(project) }
it 'returns all link... |
github | shreyasbharath/cpp-dependency-graph | https://github.com/shreyasbharath/cpp-dependency-graph | spec/test/include_file_dependency_graph_spec.rb | Ruby | mit | 45 | master | 845 | # frozen_string_literal: true
require 'cpp_dependency_graph/include_file_dependency_graph'
require 'cpp_dependency_graph/link'
RSpec.describe IncludeFileDependencyGraph do
let(:project) { Project.new('spec/test/example_project') }
let(:include_dependency_graph) { IncludeFileDependencyGraph.new(project) }
it 'r... |
github | shreyasbharath/cpp-dependency-graph | https://github.com/shreyasbharath/cpp-dependency-graph | lib/cpp_dependency_graph.rb | Ruby | mit | 45 | master | 3,241 | # frozen_string_literal: true
require_relative "cpp_dependency_graph/circle_packing_visualiser"
require_relative "cpp_dependency_graph/component_dependency_graph"
require_relative "cpp_dependency_graph/dir_tree"
require_relative "cpp_dependency_graph/graph_to_html_visualiser"
require_relative "cpp_dependency_graph/gra... |
github | shreyasbharath/cpp-dependency-graph | https://github.com/shreyasbharath/cpp-dependency-graph | lib/cpp_dependency_graph/source_file.rb | Ruby | mit | 45 | master | 1,147 | # frozen_string_literal: true
# Source file and metadata
class SourceFile
def initialize(file)
@path = file
end
def basename
@basename ||= File.basename(@path)
end
def basename_no_extension
@basename_no_extension ||= File.basename(@path, File.extname(@path))
end
def path
@path ||= File... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.