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 | bolthar/freightrain | https://github.com/bolthar/freightrain | spec/freightrain/ioc/container_spec.rb | Ruby | bsd-2-clause | 94 | master | 1,681 | $:.unshift File.join(File.dirname(__FILE__),'..','lib')
require File.dirname(__FILE__) + '/../../../lib/freightrain/ioc/container_hookable.rb'
require File.dirname(__FILE__) + '/../../../lib/freightrain/ioc/container.rb'
require File.dirname(__FILE__) + '/../../../lib/freightrain/string_patch.rb'
require 'rubygems'
re... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | spec/freightrain/testhelpers/auto_stubber_spec.rb | Ruby | bsd-2-clause | 94 | master | 6,714 | require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe AutoStubber do
describe "stub signals" do
before :each do
@class = stub_everything
@class.stubs(:instance_variable_get).with(:@signals).returns({})
@host = stub_everything
@host.stubs(:class).returns(@clas... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | spec/freightrain/regions/region_host_spec.rb | Ruby | bsd-2-clause | 94 | master | 3,789 | require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe RegionHost do
before :each do
@class = Class.new()
@class.extend(RegionHost)
end
it "should add a 'build_regions' method on istances when extended" do
instance = @class.new
(instance.respond_to? :build_regions).sho... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | spec/freightrain/regions/freight_region_spec.rb | Ruby | bsd-2-clause | 94 | master | 1,790 | require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe FreightRegion do
describe "viewmodel" do
before :each do
Freightrain.stubs(:[]).with(:custom_view_model).returns(2)
Freightrain.stubs(:[]).with(:test_view_model).returns(1)
end
it "should return view... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | spec/freightrain/signals/freight_signal_spec.rb | Ruby | bsd-2-clause | 94 | master | 1,390 | require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe FreightSignal do
before :each do
@signal = FreightSignal.new
end
describe "connect" do
it "should keep only last proc connected" do
@signal.connect lambda { return :first }
@signal.connect lambda { return :s... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | spec/freightrain/signals/signal_host_spec.rb | Ruby | bsd-2-clause | 94 | master | 3,410 | require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe SignalHost do
before :each do
@class = Class.new()
@class.instance_eval("extend SignalHost")
end
describe "signal" do
it "should create variable when first called" do
@class.instance_variable_get(:@signals).shou... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | spec/freightrain/viewmodels/freight_view_model_spec.rb | Ruby | bsd-2-clause | 94 | master | 5,385 | require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe FreightViewModel do
before :each do
@class = Class.new(FreightViewModel)
@view = stub(:hook_to_signals => nil, :data_source= => nil)
Freightrain.stubs(:[]).returns(@view)
end
after :each do
#HACK: shouldn't be nee... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | spec/extensions/gtk/gtk_widget_spec.rb | Ruby | bsd-2-clause | 94 | master | 1,432 | #
#require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
#
#describe Gtk::Widget do
#
# before :each do
# klass = Class.new(Gtk::Widget)
# klass.class_eval("def initialize;end;")
# @widget = klass.new
# end
#
# describe "bind" do
#
# it "should call FreightBinding.new with right para... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | spec/extensions/gtk/gtk_treeviewcolumn_spec.rb | Ruby | bsd-2-clause | 94 | master | 773 | #
#require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
#
#describe Gtk::TreeViewColumn do
#
# before :each do
# @column = Gtk::TreeViewColumn.new("dummy")
# end
#
# it "should have an accessor for path" do
# @column.path = "mypath"
# @column.path.should == "mypath"
# end
#
# it "sho... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | spec/extensions/gtk/dialog_helper_spec.rb | Ruby | bsd-2-clause | 94 | master | 5,073 | require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
describe "Toolkit::DialogHelper" do
before :all do
Freightrain.toolkit = :gtk
Freightrain.load_extensions!
end
describe "open file dialog" do
before :each do
Gtk::FileChooserDialog.stubs(:new).returns(stub_everything)
... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | spec/extensions/gtk/gtk_image_spec.rb | Ruby | bsd-2-clause | 94 | master | 464 | #
#require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
#
#describe Gtk::Image do
#
# before :each do
# FreightBinding.stubs(:new)
# end
#
# describe "bind" do
#
# it "should set converter to PixbufConverter on options if property is pixbuf" do
# options = {:property => :pixbuf}
# ... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | spec/extensions/gtk/gtk_treeview_spec.rb | Ruby | bsd-2-clause | 94 | master | 2,942 | #
#require File.expand_path(File.dirname(__FILE__) + '/../../../spec_helper')
#
#describe Gtk::TreeView do
#
# before :each do
# FreightBinding.stubs(:new)
# end
#
# describe "bind" do
#
# it "should set treeview to ListStoreConverter on options if property is pixbuf" do
# options = {:property => :model}
... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | examples/editor/editor.rb | Ruby | bsd-2-clause | 94 | master | 200 | require 'rubygems'
require 'freightrain'
include Freightrain
Freightrain.app_path = File.join(File.dirname(__FILE__), "lib")
Freightrain.toolkit = :gtk
Freightrain.start(:editor) #shows editor_view |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | examples/editor/lib/services/output_service.rb | Ruby | bsd-2-clause | 94 | master | 214 | class OutputService < FreightService
signal :write
attr_reader :program_output
def write(text)
@program_output += text
fire :write
end
def reset
@program_output = ""
end
end |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | examples/editor/lib/services/program_service.rb | Ruby | bsd-2-clause | 94 | master | 262 | class ProgramService < FreightService
signal :work_completed
def run
begin
eval(@code)
rescue Exception => ex
print ex.message + "\n"
end
fire :work_completed
end
def code=(text)
@code = text
end
end |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | examples/editor/lib/viewmodels/editor_view_model.rb | Ruby | bsd-2-clause | 94 | master | 700 | class EditorViewModel < FreightViewModel
service :output
service :program
attr_reader :idle
attr_reader :state
def initialize
@idle = true
@state = "Execute"
@view.update
$stdout = @output
end
def on_quit
Toolkit.quit
end
def on_run(code)
@program.code ... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | examples/counter/lib/viewmodels/counter_view_model.rb | Ruby | bsd-2-clause | 94 | master | 221 | class CounterViewModel < FreightViewModel
attr_reader :count
def initialize
@count = 0
@view.update
end
def on_quit
Toolkit.quit
end
def on_up_signal
@count += 1
@view.update
end
end |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | examples/fileview/lib/views/fileview_view.rb | Ruby | bsd-2-clause | 94 | master | 238 | class FileviewView < FreightView
signal :quit, :forwards => "fileview.destroy"
signal :display
def search_on_clicked
filename.text = open_file_dialog
end
def display_on_clicked
fire :display, filename.text
end
end |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | examples/fileview/lib/viewmodels/fileview_view_model.rb | Ruby | bsd-2-clause | 94 | master | 229 | class FileviewViewModel < FreightViewModel
attr_reader :file_content
service :file
def on_quit
Toolkit.quit
end
def on_display(filename)
@file_content = @file.load_file(filename)
@view.update
end
end |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain.rb | Ruby | bsd-2-clause | 94 | master | 456 | require 'rubygems'
require 'require_all'
require 'tmpdir'
begin
require 'mocha/api'
require_all File.join(File.dirname(__FILE__), 'freightrain-dev')
rescue Exception
print "info: Mocha gem not found - install it with 'gem install mocha' if you want to use AutoStubber in tests\n"
end
#HACK!!1!!
require File.joi... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/scaffolding/generator.rb | Ruby | bsd-2-clause | 94 | master | 430 | class Generator
def self.create_stub(filename, template, options)
template_content = ""
File.open(File.dirname(__FILE__) + "/templates/#{template}.ftt") do |file|
template_content = file.lines.to_a.join
end
options.keys.each do |param|
template_content.gsub!("$#{param}".upcase, "#{options... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/scaffolding/scaffolding.rb | Ruby | bsd-2-clause | 94 | master | 467 | #TODO: find a good templating system to import and ditch this hack
require "rubygems"
require "require_all"
require_all File.join(File.dirname(__FILE__), "commands")
require File.join(File.dirname(__FILE__), "generator.rb")
begin
klass = eval("#{ARGV[0].capitalize}Command")
rescue
print "No command '#{ARGV[0]}'\... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/scaffolding/commands/triad.rb | Ruby | bsd-2-clause | 94 | master | 1,228 | class TriadCommand
def initialize(*args)
raise "name parameter must be specified" if args.length < 1
@name = args[0]
@path = Dir.pwd
end
def check
raise "not a freightrain application" unless File.exist?(File.join(@path, "views"))
raise "not a freightrain application" unless File.exist?(Fil... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/scaffolding/commands/app.rb | Ruby | bsd-2-clause | 94 | master | 1,159 | class AppCommand
def initialize(*args)
raise "'name' parameter must be specified" if args.length < 1
@name = args[0]
@dir = Dir.pwd
@path = File.join(@dir, @name)
end
def check
raise "Directory #{@name} already exists" if File.exist?(File.join(@dir, @name))
end
def execute
FileUtil... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/wx/wx_bootstrapper.rb | Ruby | bsd-2-clause | 94 | master | 660 | require 'wx'
require File.join(File.dirname(__FILE__), "interface_builder.rb")
require File.join(File.dirname(__FILE__), "dialog_helper.rb")
require File.join(File.dirname(__FILE__), "widgets", "wx_object.rb")
require File.join(File.dirname(__FILE__), "widgets", "wx_panel.rb")
module Freightrain
module Toolkit
... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/wx/interface_builder.rb | Ruby | bsd-2-clause | 94 | master | 2,088 | require 'rexml/document'
module Freightrain
module Toolkit
class InterfaceBuilder
attr_reader :toplevel
def file_found?(file_name)
return get_xrc_files(file_name)
end
def get_xrc_files(file_name)
search_path = File.join(
Freightrain.app_path,
... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/wx/widgets/wx_panel.rb | Ruby | bsd-2-clause | 94 | master | 242 | module Wx
class Panel
def plug_in(region_widget)
self.remove_child(self.get_children.first) if self.get_children.length != 0
region_widget.reparent(self)
region_widget.layout
self.layout
end
end
end |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/gtk/interface_builder.rb | Ruby | bsd-2-clause | 94 | master | 2,489 | require 'rexml/document'
module Freightrain
module Toolkit
class InterfaceBuilder
def initialize
@builder = Gtk::Builder.new
end
def file_found?(file_name)
return get_glade_file(file_name)
end
def create_objects_from_file(file_name)
file = get_glade_file... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/gtk/gtk_bootstrapper.rb | Ruby | bsd-2-clause | 94 | master | 1,183 | #TODO: use require all
require 'gtk2'
require File.join(File.dirname(__FILE__), "widgets/gtk_image.rb")
require File.join(File.dirname(__FILE__), "widgets/gtk_toggle_button.rb")
require File.join(File.dirname(__FILE__), "widgets/gtk_toggle_tool_button.rb")
require File.join(File.dirname(__FILE__), "widgets/gtk_widget.... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/gtk/dialog_helper.rb | Ruby | bsd-2-clause | 94 | master | 2,497 | module Freightrain
module Toolkit
module DialogHelper
def open_file_dialog(description = "Open file...")
raise "toplevel not implemented. If you want to use " +
"DialogHelper inside your class you should provide " +
"a toplevel widget via the toplevel method" unless ... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/gtk/widgets/gtk_widget.rb | Ruby | bsd-2-clause | 94 | master | 1,436 | module Gtk
class Widget
include Freightrain::BindingBase
def defaults
@defaults = {} unless @defaults
return @defaults
end
#made for easier compatibility (other toolkits use show/hide)
def show
self.visible = true
end
def hide
self.visible = false
end
d... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/gtk/widgets/gtk_layout.rb | Ruby | bsd-2-clause | 94 | master | 2,483 | module Gtk
class Layout
include Freightrain::LayoutWidget
attr_writer :viewmodel
attr_reader :elements
def setup
@signals ||= {}
selected_callback = @signals[:selected]
@signals[:selected] = lambda do |value|
elements.each do |item|
... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/gtk/widgets/gtk_image.rb | Ruby | bsd-2-clause | 94 | master | 367 | module Gtk
class Image
def image=(value)
file = File.new(File.join(Dir.tmpdir,"tempimg#{self.object_id.to_s}"),'w')
file << value
file.close
self.pixbuf = Gdk::Pixbuf.new(File.join(Dir.tmpdir,"tempimg#{self.object_id.to_s}"))
end
def image_file=(file_name)
self.image=(File... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/gtk/widgets/gtk_treeview.rb | Ruby | bsd-2-clause | 94 | master | 2,113 | module Gtk
class TreeView
def create_column(column_definition)
renderer = Gtk::CellRendererText.new
title = column_definition.keys.first
attributes = {}
column_definition.values.first.each do |binding|
attributes[binding["property"]] = @paths[binding["path"]]
end
... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/gtk/widgets/gtk_combo_box.rb | Ruby | bsd-2-clause | 94 | master | 895 | module Gtk
class ComboBox
def elements=(enumerable)
list_store = Gtk::ListStore.new(::Object, String)
enumerable.each do |item|
iterator = list_store.append
iterator[0] = item
iterator[1] = item.send(@text)
end
self.model = list_store
end
def sele... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/gtk/widgets/gtk_treeviewcolumn.rb | Ruby | bsd-2-clause | 94 | master | 283 | module Gtk
class TreeViewColumn
attr_accessor :path
attr_writer :property
attr_writer :type
def type
return @type if @type
return String
end
def property
return @property if @property
return :text
end
end
end |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/gtk/widgets/gtk_statusicon.rb | Ruby | bsd-2-clause | 94 | master | 883 | module Gtk
class StatusIcon
include BindingBase
#Gtk::StatusIcon is NOT a Gtk::Widget, but a more basic
#GLib::Object. That implies that statusicons do not have
#a 'name' method, which is necessary for a lot of stuff
#in freightrain, such as method accessor creation and
#binding. Since, in m... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/gtk/widgets/gtk_calendar.rb | Ruby | bsd-2-clause | 94 | master | 255 | module Gtk
class Calendar
def date
return DateTime.civil(self.year, self.month + 1, self.day)
end
def date=(val)
self.day = val.day
self.month = val.month - 1
self.year = val.year
end
end
end |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/qt/interface_builder.rb | Ruby | bsd-2-clause | 94 | master | 1,561 | module Freightrain
module Toolkit
class InterfaceBuilder
attr_reader :toplevel
def file_found?(file_name)
return get_ui_files(file_name)
end
def create_objects_from_file(file_name)
file = Qt::File.new(get_ui_files(file_name))
file.open(Qt::File::ReadOnly)
... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/qt/qt_bootstrapper.rb | Ruby | bsd-2-clause | 94 | master | 822 | require 'Qt4'
require 'qtuitools' unless RUBY_PLATFORM =~ /mswin/
require File.join(File.dirname(__FILE__), "widgets/qt_base.rb")
require File.join(File.dirname(__FILE__), "widgets/qt_abstract_button.rb")
require File.join(File.dirname(__FILE__), "widgets/qt_calendar_widget.rb")
require File.join(File.dirname(__FILE__... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/qt/dialog_helper.rb | Ruby | bsd-2-clause | 94 | master | 363 | module Freightrain
module Toolkit
module DialogHelper
def open_file_dialog(description = "Open file...")
raise "not implemented"
end
def yes_no_dialog(description, title = "Warning!", secondary_text = "It will not be possible to recover the deleted item")
raise "not implemente... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/qt/widgets/qt_base.rb | Ruby | bsd-2-clause | 94 | master | 743 | module Qt
class Base
include Freightrain::BindingBase
def plug_in(region_widget)
region_widget.setParent(self)
region_widget.show
end
def name
return self.objectName
end
def signals
return {}
end
def get_event_signature(event_name)
return signals[even... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/qt/widgets/qt_layout.rb | Ruby | bsd-2-clause | 94 | master | 1,623 | module Qt
class VBoxLayout
include Freightrain::LayoutWidget
def setup
@signals ||= {}
selected_callback = @signals[:selected]
@signals[:selected] = lambda do |value|
elements.each do |item|
item.set_selection(item.value == val... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/qt/widgets/qt_label.rb | Ruby | bsd-2-clause | 94 | master | 416 | module Qt
class Label
def image=(value)
file = ::File.new(::File.join(::Dir.tmpdir,"tempimg#{self.object_id.to_s}"),'w')
file << value
file.close
image = Qt::Image.new(::File.join(::Dir.tmpdir,"tempimg#{self.object_id.to_s}"))
self.pixmap = image
self.resize(self.pixmap.size)... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/qt/widgets/qt_line_edit.rb | Ruby | bsd-2-clause | 94 | master | 218 | module Qt
class LineEdit
def signals
base_list = super
base_list[:textChanged] = "textChanged(QString)"
base_list[:textEdited] = "textEdited(QString)"
return base_list
end
end
end |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/extensions/qt/widgets/qt_calendar_widget.rb | Ruby | bsd-2-clause | 94 | master | 312 | module Qt
class CalendarWidget
def signals
base_list = super
base_list[:clicked] = "clicked(QDate)"
base_list[:activated] = "activated(QDate)"
return base_list
end
def selectedDate=(value)
if value.kind_of? ::Date
super(value)
end
end
end
end |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain-dev/auto_stubber.rb | Ruby | bsd-2-clause | 94 | master | 2,584 | module Freightrain
class AutoStubber
include Mocha::API
#semi-private API
def stub_signals(signal_host)
stub_signals = {}
signal_names = []
signals = signal_host.class.instance_variable_get(:@signals)
signal_names = signals.keys if signals
signal_names.each do |signal_... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/string_patch.rb | Ruby | bsd-2-clause | 94 | master | 738 | class String
#TODO: maybe activesupport has something like this
def to_convention
return "" if self.empty?
clone = self.clone
first_letter = clone.slice!(0)
result = first_letter.chr.downcase
#fix, each_char seems not to be implemented
#before 1.8.7
(0...clone.length).each do |index|
... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/bootstrapper.rb | Ruby | bsd-2-clause | 94 | master | 833 | module Freightrain
attr_accessor :toolkit
attr_accessor :app_path
def views_path
base_path = File.join(@app_path, "views")
toolkit_path = File.join(base_path, @toolkit.to_s)
return toolkit_path if File.exist?(toolkit_path)
return base_path
end
def load_extensions!
begin
require Fi... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/freight_color.rb | Ruby | bsd-2-clause | 94 | master | 209 | class FreightColor
@@colors = {}
@@colors[:red] = [255, 0, 0]
@@colors[:green] = [0, 255, 0]
@@colors[:blue] = [0, 0, 255]
def self.[](color_symbol)
return @@colors[color_symbol]
end
end |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/auto_requirer.rb | Ruby | bsd-2-clause | 94 | master | 614 | module Freightrain
def self.auto_require!
views_folder = self.views_path
viewmodels_folder = File.join(self.app_path, "viewmodels")
services_folder = File.join(self.app_path, "services")
domain_folder = File.join(self.app_path, "domain")
require_all views_folder
require_all viewm... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/viewmodels/freight_view_model.rb | Ruby | bsd-2-clause | 94 | master | 1,319 | module Freightrain
class FreightViewModel
extend ContainerHookable
extend ServiceHost
extend RegionHost
extend SignalHost
def self.container_options
return { :model => :prototype }
end
def dialog(viewmodel_name, *args)
dialog = Freightrain["#{viewmodel_name}_view_model".to_s... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/viewmodels/dialog_extension.rb | Ruby | bsd-2-clause | 94 | master | 387 | module Freightrain
module DialogExtension
def show_dialog(*args)
on_show(*args)
@on_close = lambda { |*params| yield(*params) } if block_given?
@view.update
show
end
def on_show(*args)
#to be overridden
end
def close(*args)
@on_close.call(*args) if @on_close... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/views/callback_wrapper.rb | Ruby | bsd-2-clause | 94 | master | 282 | #TODO: is this really necessary?
class CallbackWrapper
attr_reader :method
def initialize(method)
@method = method
end
def target
return @method.name.to_s.split("_on_")[0]
end
def event
return @method.name.to_s.split("_on_")[1].gsub("_", "-")
end
end |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/views/interface_builder.rb | Ruby | bsd-2-clause | 94 | master | 597 | module Freightrain
def get_interface_builder
return Toolkit::InterfaceBuilder.new
end
module InterfaceBuilder
def load_from_file(file_name, builder)
if builder.file_found?(file_name)
@widgets = builder.create_objects_from_file(file_name)
builder.create_object_accessors(@widg... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/views/freight_view.rb | Ruby | bsd-2-clause | 94 | master | 1,902 | module Freightrain
class FreightView
include InterfaceBuilder
include BindingHost
extend SignalHost
extend ContainerHookable
def widgets
return @widgets.select { |widget| widget.kind_of? BindingBase }
end
def get_all_callbacks
return self.methods.select do |method_name|
... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/views/code_interface_builder.rb | Ruby | bsd-2-clause | 94 | master | 1,312 | module Freightrain
class CodeInterfaceBuilder
def initialize
@builder = Freightrain.get_interface_builder
end
def file_found?(file_name)
return get_code_definition_file(file_name)
end
def create_objects_from_file(file_name)
code_widgets = eval_script(file_found?(file_name))
... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/binding/binding_host.rb | Ruby | bsd-2-clause | 94 | master | 755 | module Freightrain
module BindingHost
def load_bindings_from_file(widgets)
loader = BindingLoader.new(self.class.name)
loader.each_binding do |widget_name, options|
widget = widgets.select { |widget| widget.name == widget_name }.first
widget.bind(options) if widget
... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/binding/freight_binding.rb | Ruby | bsd-2-clause | 94 | master | 1,723 | module Freightrain
class FreightBinding
attr_accessor :data_source
def initialize(widget, options)
@cache = :__NOVALUE #TODO: this is necessary but really ugly - evaluate a possible replacement
@widget = widget
@property = options[:property].to_s.split('.')
@p... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/binding/binding_base.rb | Ruby | bsd-2-clause | 94 | master | 368 | module Freightrain
module BindingBase
def bind(binding_options)
@bindings ||= {}
binding = FreightBinding.new(self, binding_options)
#TODO: send out warning on override?
@bindings[binding_options[:property]] = binding
return binding
end
def bindings
@bindings ||= {}
... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/binding/binding_loader.rb | Ruby | bsd-2-clause | 94 | master | 905 | require 'yaml'
module Freightrain
class BindingLoader
def initialize(class_name)
@search_path = File.join(
Freightrain.views_path,
"**",
class_name.to_convention + ".bnd.yml")
end
def filename
result = Dir.glob(@search_path)
return result[0] ||... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/binding/converters/converter_factory.rb | Ruby | bsd-2-clause | 94 | master | 515 | module Freightrain
class ConverterFactory
def self.create(converter_name)
name = converter_name.to_s.capitalize
#first try to get one of the standard converters
if Freightrain.const_defined? "#{name}Converter"
return Freightrain.const_get("#{name}Converter").new
end
#then, ... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/elements/freight_element_view.rb | Ruby | bsd-2-clause | 94 | master | 316 | module Freightrain
#TODO: make this an extension or even remove it
class FreightElementView < FreightView
extend ContainerHookable
def self.container_options
return { :model => :prototype }
end
def initialize
super
@signals[:selected] = FreightSignal.new
end
end
end |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/elements/freight_element_view_model.rb | Ruby | bsd-2-clause | 94 | master | 659 | module Freightrain
#TODO: make this an extension
class FreightElementViewModel < FreightViewModel
extend ContainerHookable
attr_reader :selected
def self.container_options
return { :model => :prototype }
end
def value=(val)
@value = val
@view.update
end
def value
... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/services/service_host.rb | Ruby | bsd-2-clause | 94 | master | 649 | module Freightrain
module ServiceHost
def self.extended(klass)
klass.class_eval do
def get_services
services = self.class.instance_variable_get(:@services)
services ||= []
services.each do |service|
service_instance = Freightrain["#{service}_service".to_... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/services/freight_service.rb | Ruby | bsd-2-clause | 94 | master | 615 | module Freightrain
class FreightService
extend ContainerHookable
extend ServiceHost
#WARNING! Service, as it is right now, are
#SINGLETONS by default. That means if you consume
#the same service from two different hosts, the LAST
#host hooking to the callback will actually get the calls.
... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/signals/signal_host.rb | Ruby | bsd-2-clause | 94 | master | 1,385 | module Freightrain
module SignalHost
def self.extended(klass)
klass.class_eval do
def fire(signal, *args)
@signals[signal.to_sym].fire(*args)
end
def signals
return @signals
end
def create_signals
@signals = {}
... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/signals/freight_signal.rb | Ruby | bsd-2-clause | 94 | master | 318 | module Freightrain
#TODO: give this more responsibility
class FreightSignal
def fire(*args)
@proc.call(*args) if @proc && !@inactive
end
def connect(proc)
@proc = proc
end
def stifle
@inactive = true
end
def unleash
@inactive = false
end
end
end |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/regions/region_host.rb | Ruby | bsd-2-clause | 94 | master | 906 | module RegionHost
def self.extended(klass)
klass.class_eval do
#TODO: too much stuff here
def build_regions
region_definitions = self.class.instance_variable_get(:@regions)
region_definitions ||= []
@regions = {}
region_definitions.each do |name, options|
@... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/regions/freight_region.rb | Ruby | bsd-2-clause | 94 | master | 563 | module Freightrain
class FreightRegion
def initialize(name, options)
@name = name
viewmodel_name = options[:viewmodel] || @name
@viewmodel = Freightrain[(viewmodel_name.to_s + "_view_model").to_sym]
@container = @name.to_s + "_region"
end
def viewmodel
r... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/ioc/container.rb | Ruby | bsd-2-clause | 94 | master | 384 | module Freightrain
def configure_container!(registry = Freightrain::Registry.new)
@registry = registry
ContainerHookable.classes.each do |klass|
klass.subclasses.each do |subclass|
@registry.register(
subclass, subclass.container_options)
end
end
end
def [](class_nam... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/ioc/container_hookable.rb | Ruby | bsd-2-clause | 94 | master | 524 | module Freightrain
module ContainerHookable
def self.extended(extending_class)
@@classes ||= []
@@classes << extending_class
extending_class.instance_variable_set(:@container_options, {})
end
def self.classes
@@classes ||= []
return @@classes
end
def inherited(sub... |
github | bolthar/freightrain | https://github.com/bolthar/freightrain | lib/freightrain/ioc/registry.rb | Ruby | bsd-2-clause | 94 | master | 530 | module Freightrain
class Registry
def initialize
@classes = {}
@cache = {}
end
def register(klass, options)
@classes[klass.name.to_convention_sym] = klass
@cache[klass.name.to_convention_sym] = klass.new if options[:model] == :singleton
end
... |
github | mbklein/equivalent-xml | https://github.com/mbklein/equivalent-xml | equivalent-xml.gemspec | Ruby | mit | 94 | master | 1,300 | Gem::Specification.new do |s|
s.name = %q{equivalent-xml}
s.version = '1.0.0'
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Michael B. Klein"]
s.description = %q{Compares two XML Nodes (Documents, etc.) for certain semantic equivalencies... |
github | mbklein/equivalent-xml | https://github.com/mbklein/equivalent-xml | Rakefile | Ruby | mit | 94 | master | 641 | require 'rubygems'
require 'bundler'
require "bundler/gem_tasks"
require 'rake/tasklib'
require 'rdoc/task'
begin
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'rake'
req... |
github | mbklein/equivalent-xml | https://github.com/mbklein/equivalent-xml | spec/equivalent-xml_spec.rb | Ruby | mit | 94 | master | 560 | require File.expand_path('../spec_helper.rb',__FILE__)
require 'nokogiri'
require 'oga'
describe EquivalentXml do
before(:all) {
require 'nokogiri'
require 'oga'
}
it "should not compare Nodes of different classes" do
doc1 = Nokogiri::XML("<doc xmlns='foo:bar'><first order='1'>foo bar baz</first>... |
github | mbklein/equivalent-xml | https://github.com/mbklein/equivalent-xml | spec/nokogiri_spec.rb | Ruby | mit | 94 | master | 13,454 | require File.expand_path('../spec_helper.rb',__FILE__)
describe "EquivalentXml (Nokogiri)" do
before(:all) { require 'nokogiri' }
after(:all) { Object.send(:remove_const, :Nokogiri) }
it "should consider a document equivalent to itself" do
doc1 = Nokogiri::XML("<doc xmlns='foo:bar'><first>foo bar baz</... |
github | mbklein/equivalent-xml | https://github.com/mbklein/equivalent-xml | spec/oga_spec.rb | Ruby | mit | 94 | master | 13,512 | require File.expand_path('../spec_helper.rb',__FILE__)
require 'oga'
describe "EquivalentXml (Oga)" do
before(:all) { require 'oga' }
after(:all) { Object.send(:remove_const, :Oga) }
it "should consider a document equivalent to itself" do
doc1 = Oga.parse_xml("<doc xmlns='foo:bar'><first>foo bar baz</fir... |
github | mbklein/equivalent-xml | https://github.com/mbklein/equivalent-xml | spec/spec_helper.rb | Ruby | mit | 94 | master | 229 | if defined?(RUBY_ENGINE) and (RUBY_ENGINE == 'ruby') and (RUBY_VERSION >= '1.9')
require 'simplecov'
SimpleCov.start
end
$:.push(File.join(File.dirname(__FILE__),'..','lib'))
require 'rspec/matchers'
require 'equivalent-xml' |
github | mbklein/equivalent-xml | https://github.com/mbklein/equivalent-xml | lib/equivalent-xml.rb | Ruby | mit | 94 | master | 8,375 | require 'equivalent-xml/node_type'
require 'equivalent-xml/proxy/base'
require 'equivalent-xml/proxy/nokogiri'
require 'equivalent-xml/proxy/oga'
module EquivalentXml
class << self
# Determine if two XML documents or nodes are equivalent
#
# @param [Node, NodeSet] node_1 The first top-level XML node to ... |
github | mbklein/equivalent-xml | https://github.com/mbklein/equivalent-xml | lib/equivalent-xml/node_type.rb | Ruby | mit | 94 | master | 628 | module EquivalentXml
module NodeType
ELEMENT_NODE = 1
ATTRIBUTE_NODE = 2
TEXT_NODE = 3
CDATA_SECTION_NODE = 4
ENTITY_REF_NODE = 5
ENTITY_NODE = 6
PI_NODE = 7
COMMENT_NODE = 8
DOCUMENT_NODE = 9
DOCUMENT_TYPE_NODE = 10
DOCUME... |
github | mbklein/equivalent-xml | https://github.com/mbklein/equivalent-xml | lib/equivalent-xml/rspec_matchers.rb | Ruby | mit | 94 | master | 2,204 | require 'equivalent-xml' unless defined?(::EquivalentXml)
begin
require 'rspec/expectations'
rescue LoadError
end
module EquivalentXml::RSpecMatchers
if defined?(::RSpec::Matchers)
rspec_namespace = ::RSpec::Matchers
elsif defined?(::Spec::Matchers)
rspec_namespace = ::Spec::Matchers
else
raise N... |
github | mbklein/equivalent-xml | https://github.com/mbklein/equivalent-xml | lib/equivalent-xml/proxy/base.rb | Ruby | mit | 94 | master | 1,192 | module EquivalentXml
module Proxy
class Base
attr_reader :thing
def self.driver_name
self.name.split(/::/).last.to_sym
end
def self.parse(source)
raise NameError, "No parsing in the base class."
end
def self.present?
begin
self.p... |
github | mbklein/equivalent-xml | https://github.com/mbklein/equivalent-xml | lib/equivalent-xml/proxy/nokogiri.rb | Ruby | mit | 94 | master | 1,429 | module EquivalentXml
module Proxy
class Nokogiri < Base
def self.parse(source)
::Nokogiri::XML(source)
end
def has_attributes?
@thing.respond_to?(:attribute_nodes)
end
def has_children?
@thing.respond_to?(:children)
end
def is_... |
github | mbklein/equivalent-xml | https://github.com/mbklein/equivalent-xml | lib/equivalent-xml/proxy/oga.rb | Ruby | mit | 94 | master | 2,115 | module EquivalentXml
module Proxy
class Oga < Base
def self.parse(source)
::Oga.parse_xml(source)
end
def initialize(thing)
super
if is_namespaced? and has_attributes?
@thing.attributes.reject! { |a| @thing.namespaces[a.name] and @thing.namespaces[a.name]... |
github | samleb/sexy_scopes | https://github.com/samleb/sexy_scopes | Appraisals | Ruby | mit | 94 | master | 358 | appraise 'activerecord_4_2' do
gem 'activerecord', '~> 4.2.0'
end
appraise 'activerecord_5_0' do
gem 'activerecord', '~> 5.0.0'
end
appraise 'activerecord_5_1' do
gem 'activerecord', '~> 5.1.0'
end
appraise 'activerecord_edge' do
gem 'activerecord', github: 'rails/rails', branch: 'master'
gem 'arel', githu... |
github | samleb/sexy_scopes | https://github.com/samleb/sexy_scopes | sexy_scopes.gemspec | Ruby | mit | 94 | master | 1,644 | # -*- encoding: utf-8 -*-
require File.expand_path('../lib/sexy_scopes/version', __FILE__)
Gem::Specification.new do |gem|
gem.name = 'sexy_scopes'
gem.version = SexyScopes::VERSION
gem.summary = %{Write beautiful and expressive ActiveRecord scopes without SQL.}
gem.description = %{Small DSL to... |
github | samleb/sexy_scopes | https://github.com/samleb/sexy_scopes | Rakefile | Ruby | mit | 94 | master | 611 | require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'appraisal'
desc "Run specifications (using sqlite3)"
RSpec::Core::RakeTask.new(:spec)
desc "Measure test coverage"
task :cov do
ENV['COVERAGE'] = '1'
Rake::Task[:spec].invoke
end
namespace :spec do
databases = %w( postgresql mysql sqlite3 )
... |
github | samleb/sexy_scopes | https://github.com/samleb/sexy_scopes | lib/sexy_scopes.rb | Ruby | mit | 94 | master | 701 | require 'active_support/lazy_load_hooks'
require 'sexy_scopes/version'
module SexyScopes
autoload :Arel, 'sexy_scopes/arel'
class << self
def extend_expression(expression)
expression.extend(Arel::ExpressionMethods)
end
def extend_predicate(predicate)
predicate.extend(Arel::PredicateMethod... |
github | samleb/sexy_scopes | https://github.com/samleb/sexy_scopes | lib/sexy_scopes/version.rb | Ruby | mit | 94 | master | 374 | module SexyScopes
module Version
MAJOR = 1
MINOR = 0
TINY = 0
PRE = 'beta1'
STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
class << self
# Allows {Version} to display ({to_s}) and behave ({to_str}) as a string
def to_str
STRING
end
alias_method :to_s, :... |
github | samleb/sexy_scopes | https://github.com/samleb/sexy_scopes | lib/sexy_scopes/active_record.rb | Ruby | mit | 94 | master | 478 | require 'sexy_scopes/active_record/class_methods'
require 'sexy_scopes/active_record/dynamic_methods'
require 'sexy_scopes/active_record/query_methods'
ActiveRecord::Base.extend SexyScopes::ActiveRecord::ClassMethods
ActiveRecord::Base.extend SexyScopes::ActiveRecord::DynamicMethods
ActiveRecord::Relation.send(:inclu... |
github | samleb/sexy_scopes | https://github.com/samleb/sexy_scopes | lib/sexy_scopes/railtie.rb | Ruby | mit | 94 | master | 208 | module SexyScopes
class Railtie < Rails::Railtie
initializer 'sexy_scopes' do |app|
ActiveSupport.on_load :active_record do
require 'sexy_scopes/active_record'
end
end
end
end |
github | samleb/sexy_scopes | https://github.com/samleb/sexy_scopes | lib/sexy_scopes/arel.rb | Ruby | mit | 94 | master | 478 | require 'arel/visitors_extensions'
module SexyScopes
module Arel
autoload :ExpressionMethods, 'sexy_scopes/arel/expression_methods'
autoload :PredicateMethods, 'sexy_scopes/arel/predicate_methods'
autoload :Predications, 'sexy_scopes/arel/predications'
autoload :Typecasting, 'sexy_scopes/arel/typeca... |
github | samleb/sexy_scopes | https://github.com/samleb/sexy_scopes | lib/sexy_scopes/arel/predicate_methods.rb | Ruby | mit | 94 | master | 708 | module SexyScopes
module Arel
module PredicateMethods
# <tt>Arel::Grouping</tt> nodes didn't include <tt>Arel::Predications</tt> before Arel 3, but <tt>or</tt>
# returns an <tt>Arel::Grouping</tt> node (surrounds the SQL <tt>OR</tt> clause with parenthesis).
# Since ActiveRecord 3.1 depends on A... |
github | samleb/sexy_scopes | https://github.com/samleb/sexy_scopes | lib/sexy_scopes/arel/math.rb | Ruby | mit | 94 | master | 524 | module SexyScopes
module Arel
module Math
include Typecasting
def *(other)
SexyScopes.extend_expression(super)
end
def +(other)
SexyScopes.extend_expression(super)
end
def -(other)
SexyScopes.extend_expression(super)
end
def /(other)
... |
github | samleb/sexy_scopes | https://github.com/samleb/sexy_scopes | lib/sexy_scopes/arel/predications.rb | Ruby | mit | 94 | master | 1,357 | module SexyScopes
module Arel
module Predications
def eq(other)
SexyScopes.extend_predicate(super)
end
alias == eq
def in(other)
SexyScopes.extend_predicate(super)
end
def matches(other, *)
if Regexp === other
matches_regexp(other)
el... |
github | samleb/sexy_scopes | https://github.com/samleb/sexy_scopes | lib/sexy_scopes/arel/typecasting.rb | Ruby | mit | 94 | master | 384 | module SexyScopes
module Arel
module Typecasting
def *(other)
super SexyScopes.type_cast(other, self)
end
def +(other)
super SexyScopes.type_cast(other, self)
end
def -(other)
super SexyScopes.type_cast(other, self)
end
def /(other)
supe... |
github | samleb/sexy_scopes | https://github.com/samleb/sexy_scopes | lib/sexy_scopes/arel/nodes/regexp_matches.rb | Ruby | mit | 94 | master | 295 | module SexyScopes
module Arel
module Nodes
class RegexpMatches < ::Arel::Nodes::InfixOperation
def initialize(left, right)
right = Regexp.try_convert(right) || Regexp.compile(right.to_s)
super(:REGEXP, left, right)
end
end
end
end
end |
github | samleb/sexy_scopes | https://github.com/samleb/sexy_scopes | lib/sexy_scopes/active_record/query_methods.rb | Ruby | mit | 94 | master | 1,950 | module SexyScopes
module ActiveRecord
module QueryMethods
# Adds support for blocks to ActiveRecord `where`.
#
# @example
# User.where { username =~ 'bob%' }
# # is equivalent to:
# User.where(User.username =~ 'bob%')
#
# The block is evaluated in the context ... |
github | samleb/sexy_scopes | https://github.com/samleb/sexy_scopes | lib/sexy_scopes/active_record/class_methods.rb | Ruby | mit | 94 | master | 1,109 | module SexyScopes
module ActiveRecord
module ClassMethods
# Creates and extends an Arel <tt>Attribute</tt> representing the table's column with
# the given <tt>name</tt>.
#
# @param [String, Symbol] name The attribute name
#
# @note Please note that no exception is raised if no... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.