repo_name
stringlengths
6
97
path
stringlengths
3
341
text
stringlengths
8
1.02M
majesty2450/whip
lib/whip/cli/parser.rb
<gh_stars>0 require_relative "option" require_relative "flag" require_relative "argument" module Whip end module Whip::CLI end ############################################################################### # ############################################################################### class Whip::CLI::Parser ...
majesty2450/whip
lib/whip/cli/flag.rb
<gh_stars>0 module Whip end module Whip::CLI end ############################################################################### # ############################################################################### class Whip::CLI::Flag def initialize (name) @name = name end def name @name ...
majesty2450/whip
lib/whip/cli/option.rb
<filename>lib/whip/cli/option.rb require_relative "flag" require_relative "argument" module Whip end module Whip::CLI end ############################################################################### # ############################################################################### class Whip::CLI::Option def i...
majesty2450/whip
lib/whip/cli/argument.rb
<filename>lib/whip/cli/argument.rb module Whip end module Whip::CLI end ############################################################################### # ############################################################################### class Whip::CLI::Argument def initialize (value) @value = value end...
majesty2450/whip
lib/whip/token.rb
<filename>lib/whip/token.rb module Whip end # Base token class class Whip::Token def initialize (pos) @starts = pos @ends = pos end def ends= (pos) @ends = pos end def ends @ends end def starts @starts end end
majesty2450/whip
lib/whip/watcher.rb
<reponame>majesty2450/whip require_relative "file" require_relative "watch" require_relative "compiler" module Whip end # Watches files for changes in themselves or their dependencies, then parses # and compiles it and fixes dependencies class Whip::Watcher def initialize (files) @watches = Array.new ...
dgamboaestrada/rails-skeleton
src/spec/controllers/users_controller_spec.rb
<reponame>dgamboaestrada/rails-skeleton<filename>src/spec/controllers/users_controller_spec.rb require 'rails_helper' require 'faker' require 'json_matchers/rspec' RSpec.describe UsersController, type: :controller do # This should return the minimal set of attributes required to create a valid # User. As you add ...
dgamboaestrada/rails-skeleton
src/app/controllers/users_controller.rb
class UsersController < InheritedResources::Base before_action :set_user, only: %i[show update destroy] def index @users = User.order(params[:sort]).per_page_kaminari(params[:page]).per params[:limit] respond_to do |format| format.json { render json: @users } end end def show respond_to...
dgamboaestrada/rails-skeleton
src/app/controllers/application_controller.rb
class ApplicationController < ActionController::Base before_action :apijson_pagination, if: :json_request? # action to jwt authorization before_action :set_locale # Setting the Locale from param skip_before_action :verify_authenticity_token, if: :json_request? # Skip csrf to api private def set_locale I...
mvali95/logster
lib/logster/configuration.rb
<reponame>mvali95/logster # frozen_string_literal: true module Logster class Configuration attr_accessor( :allow_grouping, :application_version, :current_context, :env_expandable_keys, :enable_custom_patterns_via_ui, :enable_js_error_reporting, :environments, :rate...
mvali95/logster
lib/logster/version.rb
# frozen_string_literal: true module Logster VERSION = "2.4.2" end
mvali95/logster
lib/logster/redis_store.rb
<gh_stars>0 # frozen_string_literal: true require 'json' require 'logster/base_store' require 'logster/redis_rate_limiter' module Logster class RedisStore < BaseStore attr_accessor :redis, :max_backlog, :redis_raw_connection attr_writer :redis_prefix def initialize(redis = nil) super() @re...
mvali95/logster
test/logster/test_pattern.rb
require_relative '../test_helper' require 'logster/redis_store' require 'logster/pattern' class TestPattern < Minitest::Test class FakePattern < Logster::Pattern def self.set_name "__LOGSTER__fake_patterns_set".freeze end end Logster::PATTERNS << FakePattern class TestRedisStore < Logster::Base...
mvali95/logster
lib/logster/base_store.rb
<reponame>mvali95/logster # frozen_string_literal: true module Logster class BaseStore attr_accessor :level, :max_retention, :skip_empty, :ignore, :allow_custom_patterns def initialize @max_retention = 60 * 60 * 24 * 7 @skip_empty = true @allow_custom_patterns = false @patterns_cach...
mvali95/logster
test/logster/test_message.rb
<reponame>mvali95/logster require_relative '../test_helper' require 'logster/message' class TestMessage < MiniTest::Test def test_merge_similar msg1 = Logster::Message.new(0, '', 'test', 10) msg1.populate_from_env(a: "1", b: "2") msg2 = Logster::Message.new(0, '', 'test', 20) msg2.populate_from_env...
mvali95/logster
lib/logster/ignore_pattern.rb
<filename>lib/logster/ignore_pattern.rb module Logster class IgnorePattern def initialize(message_pattern = nil, env_patterns = nil) @msg_match = message_pattern @env_match = env_patterns end def self.from_message_and_request_uri(msg, request) IgnorePattern.new(msg, REQUEST_URI: reques...
mvali95/logster
lib/logster/message.rb
<reponame>mvali95/logster require 'digest/sha1' require 'securerandom' module Logster MAX_GROUPING_LENGTH = 50 MAX_MESSAGE_LENGTH = 600 class Message LOGSTER_ENV = "_logster_env".freeze ALLOWED_ENV = %w{ HTTP_HOST REQUEST_URI REQUEST_METHOD HTTP_USER_AGENT HTTP_ACCEPT ...
mvali95/logster
lib/logster/pattern.rb
<filename>lib/logster/pattern.rb<gh_stars>0 module Logster class Pattern class PatternError < StandardError; end def self.set_name raise "Please override the `set_name` method and specify and a name for this set" end def self.parse_pattern(string) return string if Regexp === string ...
mvali95/logster
lib/logster/cache.rb
module Logster class Cache def initialize(age = 2) @age = age @hash = { created_at: Process.clock_gettime(Process::CLOCK_MONOTONIC) } end def fetch if !@hash.key?(:data) || @hash[:created_at] + @age < Process.clock_gettime(Process::CLOCK_MONOTONIC) @hash[:data] = yield @...
mvali95/logster
test/logster/test_logger.rb
<filename>test/logster/test_logger.rb require_relative '../test_helper' require 'logster/logger' require 'logger' class TestStore attr_accessor :calls def report(*args) (@calls ||= []) << args end end class TestLogger < Minitest::Test def setup @store = TestStore.new @logger = Logster::Logger.ne...
mvali95/logster
test/logster/test_redis_store.rb
<gh_stars>0 require_relative '../test_helper' require 'logster/redis_store' require 'rack' class TestRedisStore < Minitest::Test def setup @store = Logster::RedisStore.new(Redis.new) @store.clear_all end def teardown @store.clear_all end def test_delete env = { test_env: "this is env" } ...
Nabster2104/MyFirstLib
MyFirstLib.podspec
<reponame>Nabster2104/MyFirstLib Pod::Spec.new do |s| s.name = "MyFirstLib" s.version = "1.0.7" s.summary = "This is my First Lib" s.description = "This is my First Lib, check it out." s.homepage = "https://github.com/Nabster2104/" s....
ready4god2513/readable_message
lib/readable_message.rb
require "readable_message/version" module ReadableMessage class Formatter def initialize(message, *args) @message = message @messages = args.concat([:class, :message, :backtrace, :inspect]).flatten.collect { |arg| Message.new(@message, arg) } end def to_s wr...
ready4god2513/readable_message
spec/readable_message_spec.rb
<filename>spec/readable_message_spec.rb require "spec_helper" describe ReadableMessage do subject { "my string" } it { should respond_to(:to_readable) } end
ready4god2513/readable_message
spec/spec_helper.rb
require "rubygems" require "bundler/setup" require "readable_message" RSpec.configure do |config| config.color_enabled = true config.formatter = "documentation" end
cwoz117/cookbooks
recipes/default.rb
package 'bind' package 'bind-utils' service 'named' do action [:start, :enable] end file '/etc/named.conf' do mode 0755 user 'named' group 'named' end
cwoz117/cookbooks
test/integration/default/default_test.rb
describe package 'bind' do it {should be_installed} end describe service 'named' do it {should be_enabled} end describe file '/etc/named.conf' do it {should exist} end
immersionroom/vee
scratch/homebrew_deps.rb
require 'json' $:.unshift('/usr/local/Library/Homebrew') require 'global' require 'formula' f = Formulary.factory('ffmpeg') info = f.to_hash info['dependencies'] = deps = {} f.deps.each {|dep| dep_class = 'build' if dep.build? dep_class ||= 'optional' if dep.optional? dep_class ||= 'required' ...
espenhogbakk/chamber
app/models/user.rb
<reponame>espenhogbakk/chamber class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, ...
espenhogbakk/chamber
app/controllers/attachments_controller.rb
<filename>app/controllers/attachments_controller.rb class AttachmentsController < ApplicationController before_filter :authenticate_user! def index @attachments = Attachment.all respond_to do |format| format.json { render json: @attachments } end end def show @attachment = Attachme...
espenhogbakk/chamber
app/controllers/participants_controller.rb
class ParticipantsController < ApplicationController before_filter :authenticate_user! def index if params.include? :room_id room = Room.find(params[:room_id]) @participants = room.participants else @participants = Participant.all end respond_to do |format| format.json { ...
espenhogbakk/chamber
app/models/roster.rb
<reponame>espenhogbakk/chamber class Roster < SuperModel::Base include SuperModel::Redis::Model include SuperModel::Timestamp::Model attributes :count belongs_to :user validates_presence_of :user_id belongs_to :room indexes :user_id class << self def subscribe Juggernaut.subscribe do...
espenhogbakk/chamber
test/unit/helpers/room_helper_test.rb
<reponame>espenhogbakk/chamber require 'test_helper' class RoomHelperTest < ActionView::TestCase end
espenhogbakk/chamber
app/controllers/app_controller.rb
<filename>app/controllers/app_controller.rb class AppController < ApplicationController before_filter :authenticate_user! def index # TODO Move this to a scope # TODO Include them if the current_user is a participant of the room @rooms = Room.where(invite_only: [nil, false]) end end
espenhogbakk/chamber
app/observers/roster_observer.rb
<filename>app/observers/roster_observer.rb class RosterObserver < ActiveRecord::Observer observe :roster def after_create(roster) publish :create, roster end def after_update(roster) publish :update, roster end def after_destroy(roster) publish :destroy, roster end private def publish(...
espenhogbakk/chamber
app/observers/participant_observer.rb
class ParticipantObserver < ActiveRecord::Observer observe :participant def after_create(participant) publish :create, participant end def after_update(participant) publish :update, participant end def after_destroy(participant) publish :destroy, participant end private def publish(ac...
espenhogbakk/chamber
config/routes.rb
<reponame>espenhogbakk/chamber<gh_stars>0 Chamber::Application.routes.draw do devise_for :users resources :users resources :messages resources :rooms do resources :messages resources :participants end resources :attachments resources :app root :to => "app#index" end
espenhogbakk/chamber
app/controllers/rooms_controller.rb
<gh_stars>0 class RoomsController < ApplicationController before_filter :authenticate_user! before_filter :find_room, :only =>[:show, :update, :destroy, :edit] def index @rooms = Room.all respond_to do |format| format.html format.json { render json: @rooms } end end def show ...
espenhogbakk/chamber
db/migrate/20120203202458_relate_message_to_user.rb
class RelateMessageToUser < ActiveRecord::Migration def change change_table :messages do |t| t.references :user end end end
espenhogbakk/chamber
app/models/message.rb
class Message < ActiveRecord::Base has_one :attachment belongs_to :user belongs_to :room validates_presence_of :body, :room_id, :user_id def serializable_hash(options = nil) { id: id, body: body, room: room, user: user, updated_at: updated_at, created_at: cre...
espenhogbakk/chamber
db/migrate/20120205133842_add_attachment_to_attachment.rb
<reponame>espenhogbakk/chamber<gh_stars>0 class AddAttachmentToAttachment < ActiveRecord::Migration def self.up change_table :attachments do |t| t.has_attached_file :attachment end end def self.down drop_attached_file :attachments, :attachment end end
espenhogbakk/chamber
db/migrate/20120207173255_add_invite_only_to_rooms.rb
class AddInviteOnlyToRooms < ActiveRecord::Migration def change add_column :rooms, :invite_only, :boolean end end
espenhogbakk/chamber
db/migrate/20120204121918_create_participants.rb
class CreateParticipants < ActiveRecord::Migration def change create_table :participants do |t| t.references :room t.references :user t.timestamps end add_index :participants, :room_id add_index :participants, :user_id end end
espenhogbakk/chamber
app/observers/message_observer.rb
class MessageObserver < ActiveRecord::Observer observe :message def after_create(message) publish :create, message end def after_update(message) publish :update, message end def after_destroy(message) publish :destroy, message end private def publish(action, message) Juggernaut.pu...
espenhogbakk/chamber
app/models/room.rb
class Room < ActiveRecord::Base has_many :messages, :dependent => :destroy has_many :participants has_many :users, :through => :participants attr_accessible :id, :name, :topic, :invite_only end
espenhogbakk/chamber
app/views/rooms/show.json.jbuilder
<gh_stars>0 json.(@room, :id, :name, :messages)
espenhogbakk/chamber
db/migrate/20120203144249_create_attachments.rb
class CreateAttachments < ActiveRecord::Migration def change create_table :attachments do |t| t.references :message t.timestamps end end def self.up change_table :attachments do |t| t.has_attached_file :file end end def self.down drop_attached_file :attachments, :file ...
espenhogbakk/chamber
app/models/attachment.rb
class Attachment < ActiveRecord::Base has_attached_file :attachment belongs_to :message #validates_presence_of :message_id def attachment_url self.attachment.url end def serializable_hash(options = nil) { id: id, message_id: message_id, updated_at: updated_at, ...
espenhogbakk/chamber
app/helpers/app_helper.rb
module AppHelper # def script_template(name, id = nil) # id ||= name # id += "_template" # id = id.camelize(:lower) # content_tag(:script, :type => "text/template", :id => id) do # render :partial => name # end # end # # def meta_tag(name, value) # %(<meta name="#{name}" content="#{Rack::Uti...
espenhogbakk/chamber
app/models/participant.rb
class Participant < ActiveRecord::Base belongs_to :room belongs_to :user def serializable_hash(options = nil) { id: id, room: room, user: user, updated_at: updated_at, created_at: created_at } end end
iamjoshbinder/irwebmachine
lib/irwebmachine/stack.rb
<reponame>iamjoshbinder/irwebmachine<gh_stars>1-10 class IRWebmachine::Stack def initialize(stack = []) @stack = stack @index = 0 @tracer = IRWebmachine::Tracer.new @tracer.events = ["call", "return"] @tracer.targets = [Webmachine::Resource::Callbacks] end def push(*args) @stack.push(*ar...
iamjoshbinder/irwebmachine
lib/irwebmachine.rb
<filename>lib/irwebmachine.rb<gh_stars>1-10 module IRWebmachine require "uri/query_params" require "graph" require_relative "irwebmachine/application" require_relative "irwebmachine/traced_request" require_relative "irwebmachine/frame" require_relative "irwebmachine/tracer" require_relative "irwebmachine/...
iamjoshbinder/irwebmachine
test/fixtures/resource.rb
<gh_stars>1-10 class Resource < Webmachine::Resource def content_types_provided [["plain/text", :to_text]] end def content_types_accepted [["*/*", :accept]] end def allowed_methods %w(GET POST DELETE PUT) end # POST def process_post response.body = "POST OK" end # GET def to_te...
iamjoshbinder/irwebmachine
lib/irwebmachine/traced_request.rb
<reponame>iamjoshbinder/irwebmachine<gh_stars>1-10 class IRWebmachine::TracedRequest def initialize(app) @app = app @req = nil @res = nil @stack = IRWebmachine::Stack.new end def stack @stack end def dispatch(*args) dispatch!(*args) while frame = @stack.tracer.continue @sta...
iamjoshbinder/irwebmachine
test/setup.rb
<filename>test/setup.rb require "bundler/setup" require "webmachine" require "irwebmachine" require "json" require "test/unit" Dir["test/fixtures/*.rb"].each do |file| require "./#{file}" end
iamjoshbinder/irwebmachine
lib/irwebmachine/pry.rb
<filename>lib/irwebmachine/pry.rb module IRWebmachine::Pry require "pry" require_relative "pry/print_stack" require_relative "pry/enter_stack" require_relative "pry/nav" end def app IRWebmachine.app || raise(RuntimeError, "No app set. Use IRWebmachine.app= to set one.", []) end
iamjoshbinder/irwebmachine
lib/irwebmachine/pry/enter_stack.rb
<reponame>iamjoshbinder/irwebmachine class IRWebmachine::Pry::EnterStack < Pry::ClassCommand match 'enter-stack' group 'irwebmachine' description 'Enters the context of a method on the call stack for a webmachine request.' banner <<-BANNER enter-stack BREAKPOINT Enters into the context of a...
iamjoshbinder/irwebmachine
lib/irwebmachine/pry/nav.rb
<reponame>iamjoshbinder/irwebmachine module IRWebmachine::Pry Nav = Pry::CommandSet.new do command("continue") { throw(:breakout, :continue) } alias_command "c", "continue" command("next") { throw(:breakout, :next) } alias_command "n", "next" command("prev") { throw(:breakout, :previous) } a...
iamjoshbinder/irwebmachine
test/irwebmachine_application_test.rb
<filename>test/irwebmachine_application_test.rb require_relative "setup" class IRWebmachine::ApplicationTest < Test::Unit::TestCase def setup IRWebmachine.app = app @app = IRWebmachine.app end def test_get res = @app.get "/mock_application" assert_equal "GET OK", res.body end def test_post ...
iamjoshbinder/irwebmachine
lib/irwebmachine/application.rb
<filename>lib/irwebmachine/application.rb class IRWebmachine::Application def initialize(app) @app = to_app app @req = nil @res = nil end def unbox @app end def last_response @res || raise(RuntimeError, "No active request.", []) end def last_request @req || raise(RuntimeError, "...
iamjoshbinder/irwebmachine
lib/irwebmachine/irb.rb
<reponame>iamjoshbinder/irwebmachine module IRWebmachine::IRB require 'irb' require_relative "irb/bundle" end module IRB::ExtendCommandBundle include IRWebmachine::IRB::Bundle end
iamjoshbinder/irwebmachine
lib/irwebmachine/frame.rb
class IRWebmachine::Frame def initialize(binding,event) @binding = binding @event = event @file = binding.eval "__FILE__" @lineno = binding.eval "__LINE__" @method = binding.eval "__method__" @klass = binding.eval("self").method(@method).owner end def ruby_call? "call" == @ev...
iamjoshbinder/irwebmachine
lib/irwebmachine/pry/print_stack.rb
<filename>lib/irwebmachine/pry/print_stack.rb class IRWebmachine::Pry::PrintStack < Pry::ClassCommand match 'print-stack' description 'Prints the call stack for the previous webmachine request.' group 'irwebmachine' banner <<-BANNER print-stack [OPTIONS] Prints the stack of method calls(in...
iamjoshbinder/irwebmachine
lib/irwebmachine/irb/bundle.rb
module IRWebmachine::IRB::Bundle def app IRWebmachine.app || raise(RuntimeError, "No app set. Use IRWebmachine.app= to set one.", []) end def show_stack(filter = //) request = app.last_request request.stack.each_with_index do |trace, int| puts "#{int}> #{trace}" if trace.to_s =~ filter en...
iamjoshbinder/irwebmachine
lib/irwebmachine/tracer.rb
<filename>lib/irwebmachine/tracer.rb require 'thread' class IRWebmachine::Tracer def initialize @thread = nil @queue = SizedQueue.new(1) @targets = [BasicObject] @events = ["call", "c-call", "return", "c-return", "class", "end", "line", "raise"] end # # The [set\_trace\_func](http://api...
bini-i/Tic-Tac-Toe
lib/board.rb
<reponame>bini-i/Tic-Tac-Toe class Board attr_accessor :board def initialize @board = Array.new(3) { Array.new(3, '_') } end def update(value, pos) @board[pos[0]][pos[1]] = value end # Check if user input is legal def legal_input?(pos) arr = pos.split('') x_axis = arr[1] y_axis = ar...
bini-i/Tic-Tac-Toe
bin/main.rb
#!/usr/bin/env ruby require_relative '../lib/game' require_relative '../lib/player' require_relative '../lib/board' system('clear') puts ' _____ _ _____ _____ ' puts '|_ _(_) |_ _| |_ _| ' puts ' | | _ ___ | | __ _ ___ | | ___ ___ ' puts ' | | | |/ ...
bini-i/Tic-Tac-Toe
lib/game.rb
<filename>lib/game.rb class Game def initialize(player1_name, player2_name) @player1 = Player.new(player1_name) @player1.type = 'X' @player2 = Player.new(player2_name) @player2.type = 'O' @board = Board.new end def play loop do @board.draw input(@player1) system('clear')...
aaronsama/in_or_out
lib/in_or_out/geocode.rb
require 'pry' require 'geocoder' require 'in_or_out/template' module InOrOut class Geocode def self.geocode records, address_template template = InOrOut::Template.new(address_template, records.headers) records.map do |r| r["latitude"], r["longitude"] = Geocoder.coordinates(template.build_ad...
aaronsama/in_or_out
lib/in_or_out/template.rb
<filename>lib/in_or_out/template.rb module InOrOut class AddressTemplateError < StandardError end class Template def initialize(template_string, headers) @template_string = template_string unless parse_column_names(headers) raise AddressTemplateError.new, "Some keys in the address templ...
aaronsama/in_or_out
lib/in_or_out/group.rb
<gh_stars>0 require 'border_patrol' module InOrOut class Group def self.label_records records, polygons, latitude_column, longitude_column output = [] records.each do |record| group_found = false point = BorderPatrol::Point.new(record[longitude_column].to_f, record[latitude_column]....
aaronsama/in_or_out
lib/in_or_out.rb
require 'thor' require 'border_patrol' require 'csv' require 'in_or_out/placemark_name' require 'in_or_out/group' require 'in_or_out/geocode' # require 'in_or_out/placemark_name' # require 'pry' module InOrOut class Main < Thor desc "group CSV_FILE KML_FILE OUTPUT_FILE", "Assigns a group to each point in a CSV...
aaronsama/in_or_out
spec/geocoder_spec.rb
require 'spec_helper' describe InOrOut::Geocode do describe 'build_address_string_for' do let(:data) { { "street"=>"via Sommarive", "number"=>"18", "zip"=>"38123", "city"=>"Trento", "state"=>"TN" } } describe "when a valid template is provided" do let(:template) { InOrOut::Template.new "%{street} %{n...
aaronsama/in_or_out
in_or_out.gemspec
# coding: utf-8 lib = File.expand_path('../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require File.expand_path('../lib/in_or_out/version', __FILE__) Gem::Specification.new do |gem| gem.name = "in_or_out" gem.authors = ["<NAME>"] gem.email = ["<EMAIL>"] gem.s...
aaronsama/in_or_out
lib/in_or_out/placemark_name.rb
<filename>lib/in_or_out/placemark_name.rb # This is partially copied from https://github.com/square/border_patrol/blob/master/lib/border_patrol.rb # because the gem on rubygems is outdated! module BorderPatrol class Polygon attr_reader :placemark_name def with_placemark_name(placemark) @placemark_name...
alexey-protopopov/ruber_dialog
lib/ruber_dialog/parser/description_parser.rb
<reponame>alexey-protopopov/ruber_dialog<gh_stars>0 # frozen_string_literal: true require_relative "errors" require_relative "tokens" require_relative "parser" module RuberDialog module Parser # Single Description parser from string class DescriptionLineParser < TokenParser include Parser::Tokens ...
alexey-protopopov/ruber_dialog
lib/ruber_dialog/parser/description_block_parser.rb
# frozen_string_literal: true require_relative "errors" require_relative "tokens" require_relative "description_parser" require_relative "block_parser" module RuberDialog module Parser # class for parsing block of Descriptions class DescriptionBlockParser < BlockParser attr_reader :block_start_regexp,...
alexey-protopopov/ruber_dialog
test/description_block_parser_test.rb
<gh_stars>0 # frozen_string_literal: true require "test_helper" class DescriptionBlockParserTest < Minitest::Test include RuberDialog::Parser include RuberDialog::Parser::Tokens def val_err(err, line) ValidationError.new(err, line) end def test_description_block_parser_returns_characters descripti...
alexey-protopopov/ruber_dialog
test/description_parser_test.rb
<filename>test/description_parser_test.rb<gh_stars>0 # frozen_string_literal: true require "test_helper" class DescriptionLineParserTest < Minitest::Test include RuberDialog::Parser include RuberDialog::Parser::Tokens def val_err(err, line = 1) ValidationError.new(err, line) end def test_description_p...
alexey-protopopov/ruber_dialog
lib/ruber_dialog.rb
# frozen_string_literal: true require_relative "ruber_dialog/version" require_relative "ruber_dialog/parser/errors" require_relative "ruber_dialog/parser/tokens" require_relative "ruber_dialog/parser/character_block_parser" require_relative "ruber_dialog/parser/block_parser" require_relative "ruber_dialog/parser/descr...
ambethia/LuckyPrincessNitro
lib/screens/test_screen.rb
class TestScreen < BaseScreen def setup @systems = %w[ Input Test ] end end
ambethia/LuckyPrincessNitro
lib/factories/particle_factory.rb
class ParticleFactory < EntitySystem::Factory::Base build :particle using :px, :py, :type, :attach_to def construct entity = manager.create(:particle) manager.attach(entity, ParticleComponent.new({ effect: type, attach_to: attach_to })) manager.attach(entity, SpatialComponent.new({ px...
ambethia/LuckyPrincessNitro
lib/systems/enemy_system.rb
class EnemySystem < EntitySystem::System RATE_OF_FIRE = 0.33 MIN_FIRE_DISTANCE = 120 MAX_FIRE_DISTANCE = 180 def update(delta) each(EnemyComponent) do |entity, component| enemy = manager.component(SpatialComponent, entity) camera = manager.component(SpatialComponent, manager.find(:camera)) ...
ambethia/LuckyPrincessNitro
lib/factories/item_factory.rb
<filename>lib/factories/item_factory.rb class ItemFactory < EntitySystem::Factory::Base build :item using :type, :x, :y RADIUS = { gem: 64 } def construct entity = manager.create(:item) manager.attach(entity, ItemComponent.new({ type: type, })) manager.attach(entity, CollisionCompo...
ambethia/LuckyPrincessNitro
lib/systems/input_system.rb
class InputSystem < EntitySystem::System def update(delta) if Gdx.input.is_key_pressed(Input::Keys::Q) Gdx.app.exit elsif Gdx.input.is_key_pressed(Input::Keys::F) $game.toggle_fullscreen end case $game.screen when SplashScreen if Gdx.input.is_key_pressed(Input::Keys::SPACE) ...
ambethia/LuckyPrincessNitro
lib/factories/bullet_factory.rb
class BulletFactory < EntitySystem::Factory::Base SPEED = { player: 240, enemy_a: 300 } RADIUS = 8 CULL_RANGE = 400 build :bullet using :px, :py, :bearing, :type, :owner def construct bullet = manager.create(:bullet) manager.attach(bullet, SpatialComponent.new({ px: px, py: py, ...
ambethia/LuckyPrincessNitro
lib/components/animated_component.rb
class AnimatedComponent < EntitySystem::Component provides :animation, :is_looped end
ambethia/LuckyPrincessNitro
lib/entity_system/factory.rb
class EntitySystem::Factory def initialize(manager) @manager = manager end def build_entity(type, &block) factory = @@factories[type].new factory.manager = @manager yield factory if block_given? factory.construct end def self.factories @@factories ||= {} end class Base att...
ambethia/LuckyPrincessNitro
lib/components/player_component.rb
<reponame>ambethia/LuckyPrincessNitro<filename>lib/components/player_component.rb<gh_stars>1-10 class PlayerComponent < EntitySystem::Component provides :shields, :is_turning_left, :is_turning_right, :is_firing end
ambethia/LuckyPrincessNitro
lib/entity_system/component.rb
class EntitySystem::Component attr_accessor :entity def self.provides(*attribute_list) attribute_list.each do |key| attr_accessor key end end def initialize(attributes = {}) attributes.each do |key, value| instance_variable_set("@#{key}", value) end end end
ambethia/LuckyPrincessNitro
lib/systems/test_system.rb
<reponame>ambethia/LuckyPrincessNitro class TestSystem < EntitySystem::System def setup @effect = ParticleEffect.new @effect.load(load_asset("explosion.particle"), load_asset("")) end def update(delta) if !@has_run @has_run = true @effect.emitters.each(&:start) end if Gdx.input....
ambethia/LuckyPrincessNitro
lib/systems/background_system.rb
class BackgroundSystem < EntitySystem::System STARFIELD_WIDTH = 320 STARFIELD_HEIGHT = 200 STARFIELD_DENSITY = 100 def setup # dark grey fill @pixmap = Pixmap.new($game.width, $game.height, Pixmap::Format::RGB888) @pixmap.set_color(0.1,0.1,0.1,1) @pixmap.fill @background = Texture.new(@pixm...
ambethia/LuckyPrincessNitro
test/entity_system_test.rb
require_relative 'test_helper' require 'game_helpers' require 'entity_system' class Position < EntitySystem::Component provides :x, :y end class Locator < EntitySystem::System def process(delta) each(Position) do |entity, component| component.x += (1 * delta) component.y += (1 * delta) end ...
ambethia/LuckyPrincessNitro
lib/entity_system/system.rb
class EntitySystem::System include GameHelpers attr_reader :manager def initialize(manager) @manager = manager setup end def each(component_class) manager.entities(component_class).each do |entity| yield(entity, manager.component(component_class, entity)) end end # Optionally over...
ambethia/LuckyPrincessNitro
lib/factories/player_factory.rb
class PlayerFactory < EntitySystem::Factory::Base INITIAL_SHIELDS = 6 build :player using :px, :py, :animations def construct entity = manager.create(:player) manager.attach(entity, PlayerComponent.new({ shields: INITIAL_SHIELDS })) manager.attach(entity, MotionComponent.new) manager...
ambethia/LuckyPrincessNitro
lib/systems/game_over_system.rb
class GameOverSystem < EntitySystem::System def setup @image = Texture.new(Gdx.files.internal(RELATIVE_ROOT + "assets/game_over.png")) end def render(delta) if $game.screen.is_a? GameOverScreen $game.screen.batch.draw(@image, 0, 0) end end end
ambethia/LuckyPrincessNitro
lib/components/spatial_component.rb
class SpatialComponent < EntitySystem::Component provides :px, :py, :bearing, :speed end
ambethia/LuckyPrincessNitro
lib/systems/rotation_system.rb
class RotationSystem < EntitySystem::System def update(delta) each(RotatedComponent) do |entity, component| spatial = manager.component(SpatialComponent, entity) render = manager.component(RenderableComponent, entity) angle = nearest_increment(spatial.bearing) if component.is_animated ...
ambethia/LuckyPrincessNitro
lib/systems/music_system.rb
class MusicSystem < EntitySystem::System def setup @music = Gdx.audio.new_music(load_asset("theme_01.ogg")) @music.looping = true end def update(delta) @elapsed ||= 0 if @elapsed > 3 && !@music.is_playing @music.play end @elapsed += delta end def dispose @music.dispose e...
ambethia/LuckyPrincessNitro
lib/systems/motion_system.rb
class MotionSystem < EntitySystem::System def update(delta) each(MotionComponent) do |entity, component| spatial = manager.component(SpatialComponent, entity) x_vel = Math.cos(spatial.bearing * Math::PI/180) * spatial.speed y_vel = Math.sin(spatial.bearing * Math::PI/180) * spatial.speed ...