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 | benignware/schedulable | https://github.com/benignware/schedulable | test/dummy/app/models/event_occurrence.rb | Ruby | mit | 93 | master | 248 | class EventOccurrence < ActiveRecord::Base
belongs_to :schedulable, polymorphic: true
default_scope lambda{order('date ASC')}
scope :remaining, lambda{where(["date >= ?",Time.now])}
scope :previous, lambda{where(["date < ?",Time.now])}
end |
github | benignware/schedulable | https://github.com/benignware/schedulable | test/dummy/app/controllers/events_controller.rb | Ruby | mit | 93 | master | 1,173 | class EventsController < ApplicationController
before_action :set_event, only: [:show, :edit, :update, :destroy]
# GET /events
def index
@events = Event.all
end
# GET /events/1
def show
end
# GET /events/new
def new
@event = Event.new
end
# GET /events/1/edit
def edit
end
# POST... |
github | benignware/schedulable | https://github.com/benignware/schedulable | test/dummy/app/inputs/schedule_input.rb | Ruby | mit | 93 | master | 6,413 | class ScheduleInput < SimpleForm::Inputs::Base
def input(wrapper_options)
# Init options
input_options||= {}
# I18n
weekdays = Date::DAYNAMES.map(&:downcase)
weekdays = weekdays.slice(1..7) << weekdays.slice(0)
day_names = I18n.t('date.day_names', default: "")
day_names =... |
github | benignware/schedulable | https://github.com/benignware/schedulable | test/dummy/app/inputs/date_time_input.rb | Ruby | mit | 93 | master | 740 | class DateTimeInput < SimpleForm::Inputs::Base
def input(wrapper_options)
# Determine control type
if input_type == :date || input_type == :datetime || input_type == :time
type = input_type
else
column = @builder.object.class.columns.select{ |c| c.name == attribute_name.to_s }.first
... |
github | benignware/schedulable | https://github.com/benignware/schedulable | test/dummy/config/routes.rb | Ruby | mit | 93 | master | 1,622 | Dummy::Application.routes.draw do
resources :events
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
# You can have the root of your site routed with "root"
# root 'welcome#index'
# Example of regular route:
# get ... |
github | benignware/schedulable | https://github.com/benignware/schedulable | test/dummy/config/application.rb | Ruby | mit | 93 | master | 1,113 | require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(*Rails.groups)
require "schedulable"
module Dummy
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in confi... |
github | benignware/schedulable | https://github.com/benignware/schedulable | test/dummy/config/initializers/schedulable.rb | Ruby | mit | 93 | master | 402 | Schedulable.configure do |config|
config.max_build_count = 0
config.max_build_period = 1.year
config.simple_form = {
input_types: {
#date: :date_picker,
#time: :date_picker,
#datetime: :date_picker
}
}
config.form_helper = {
style: :bootstrap,
input_types: {
date: :dat... |
github | benignware/schedulable | https://github.com/benignware/schedulable | test/dummy/config/initializers/simple_form_bootstrap.rb | Ruby | mit | 93 | master | 5,181 | # Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
config.error_notification_class = 'alert alert-danger'
config.button_class = 'btn btn-default'
config.boolean_label_class = nil
config.wrappers :vertical_form, tag: 'div', class: 'form-group', error_class: '... |
github | benignware/schedulable | https://github.com/benignware/schedulable | test/dummy/config/initializers/secret_token.rb | Ruby | mit | 93 | master | 659 | # Be sure to restart your server when you modify this file.
# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to diction... |
github | benignware/schedulable | https://github.com/benignware/schedulable | test/dummy/config/environments/test.rb | Ruby | mit | 93 | master | 1,609 | Dummy::Application.configure do
# Settings specified here will take precedence over those in config/application.rb.
# The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test sui... |
github | benignware/schedulable | https://github.com/benignware/schedulable | lib/schedulable.rb | Ruby | mit | 93 | master | 521 | require 'schedulable/engine' if defined? ::Rails::Engine
require 'schedulable/railtie' if defined? ::Rails::Railtie
require 'schedulable/acts_as_schedulable'
require 'schedulable/schedule'
require 'schedulable/schedule_support'
require 'schedulable/form_helper'
require 'i18n'
module Schedulable
class Config
att... |
github | benignware/schedulable | https://github.com/benignware/schedulable | lib/generators/schedulable/simple_form_generator.rb | Ruby | mit | 93 | master | 397 | module Schedulable
module Generators
class SimpleFormGenerator < ::Rails::Generators::Base
include Rails::Generators::Migration
source_root File.expand_path('../templates', __FILE__)
def create_config
puts 'Install simple_form custom input'
template 'inputs/schedule... |
github | benignware/schedulable | https://github.com/benignware/schedulable | lib/generators/schedulable/config_generator.rb | Ruby | mit | 93 | master | 390 | module Schedulable
module Generators
class ConfigGenerator < ::Rails::Generators::Base
include Rails::Generators::Migration
source_root File.expand_path('../templates', __FILE__)
def create_config
puts 'install schedulable config'
template 'config/schedulable.rb', "... |
github | benignware/schedulable | https://github.com/benignware/schedulable | lib/generators/schedulable/locale_generator.rb | Ruby | mit | 93 | master | 428 | module Schedulable
module Generators
class LocaleGenerator < ::Rails::Generators::Base
argument :locale, :type => :string, :default => "en"
source_root File.expand_path('../templates', __FILE__)
def create_locale
puts 'install locale'
template "../../../../... |
github | benignware/schedulable | https://github.com/benignware/schedulable | lib/generators/schedulable/install_generator.rb | Ruby | mit | 93 | master | 762 | module Schedulable
module Generators
class InstallGenerator < ::Rails::Generators::Base
# TODO: skip-migration
include Rails::Generators::Migration
source_root File.expand_path('../templates', __FILE__)
def self.next_migration_number(path)
unless @prev_migratio... |
github | benignware/schedulable | https://github.com/benignware/schedulable | lib/generators/schedulable/occurrence_generator.rb | Ruby | mit | 93 | master | 982 | require 'active_support/core_ext/module/introspection'
require 'rails/generators/base'
require 'rails/generators/generated_attribute'
module Schedulable
module Generators
class OccurrenceGenerator < ::Rails::Generators::NamedBase
argument :attributes, type: :array, default: [], banner: "field[:type]... |
github | benignware/schedulable | https://github.com/benignware/schedulable | lib/generators/schedulable/templates/inputs/schedule_input.rb | Ruby | mit | 93 | master | 6,458 | class ScheduleInput < SimpleForm::Inputs::Base
def input(wrapper_options)
# Init options
input_options||= {}
# I18n
weekdays = Date::DAYNAMES.map(&:downcase)
weekdays = weekdays.slice(1..7) << weekdays.slice(0)
day_names = I18n.t('date.day_names', default: "")
day_names =... |
github | benignware/schedulable | https://github.com/benignware/schedulable | lib/schedulable/railtie.rb | Ruby | mit | 93 | master | 1,333 | require 'rails'
require 'i18n'
module Schedulable
class Railtie < ::Rails::Railtie
railtie_name :schedulable
# requires all dependencies
Gem.loaded_specs['schedulable'].dependencies.each do |d|
require d.name
end
# application configuration initializer
config.schedulable = ... |
github | benignware/schedulable | https://github.com/benignware/schedulable | lib/schedulable/schedule_support.rb | Ruby | mit | 93 | master | 275 | module Schedulable
module ScheduleSupport
def self.param_names
[:id, :date, :time, :rule, :until, :count, :interval, day: [], day_of_week: [monday: [], tuesday: [], wednesday: [], thursday: [], friday: [], saturday: [], sunday: []]]
end
end
end |
github | benignware/schedulable | https://github.com/benignware/schedulable | lib/schedulable/form_helper.rb | Ruby | mit | 93 | master | 12,228 | module Schedulable
module FormHelper
STYLES = {
default: {
field_html: {class: 'field'},
input_wrapper: {tag: 'div'}
},
bootstrap: {
field_html: {class: 'field form-group'},
num_field_html: {class: 'form-control'},
date_select_html: {class: 'form-cont... |
github | benignware/schedulable | https://github.com/benignware/schedulable | lib/schedulable/acts_as_schedulable.rb | Ruby | mit | 93 | master | 7,986 | module Schedulable
module ActsAsSchedulable
extend ActiveSupport::Concern
included do
end
module ClassMethods
def acts_as_schedulable(name, options = {})
name||= :schedule
attribute = :date
has_one name, as: :schedulable, dependent: :d... |
github | benignware/schedulable | https://github.com/benignware/schedulable | lib/schedulable/schedule.rb | Ruby | mit | 93 | master | 3,460 | module Schedulable
module Model
class Schedule < ActiveRecord::Base
serialize :day
serialize :day_of_week, Hash
belongs_to :schedulable, polymorphic: true
after_initialize :update_schedule
before_save :update_schedule
validates_presence_of :rule
validates_presence_of... |
github | benignware/schedulable | https://github.com/benignware/schedulable | lib/tasks/schedulable_tasks.rake | Ruby | mit | 93 | master | 476 | require 'rake'
desc 'Builds occurrences for schedulable models'
namespace :schedulable do
task :build_occurrences => :environment do
Schedule.uniq.pluck(:schedulable_type).each do |schedulable_type|
clazz = schedulable_type.constantize
occurrences_associations = Schedulable::ActsAsSchedulable.occurren... |
github | k2nr/ulid-rails | https://github.com/k2nr/ulid-rails | ulid-rails.gemspec | Ruby | mit | 93 | master | 1,775 | lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "ulid/rails/version"
Gem::Specification.new do |spec|
spec.name = "ulid-rails"
spec.version = ULID::Rails::VERSION
spec.required_ruby_version = ">= 3.2.0"
spec.authors = ["Kazunori Kajihiro", "Zendesk"]
... |
github | k2nr/ulid-rails | https://github.com/k2nr/ulid-rails | lib/ulid/rails.rb | Ruby | mit | 93 | master | 1,608 | require "active_record"
require "active_support/concern"
require "active_model/type"
require "ulid"
require "base32/crockford"
require "ulid/rails/version"
require "ulid/rails/type"
require "ulid/rails/postgresql_type"
require "ulid/rails/sqlite_type"
require "ulid/rails/patch"
module ULID
module Rails
extend Ac... |
github | k2nr/ulid-rails | https://github.com/k2nr/ulid-rails | lib/ulid/rails/type.rb | Ruby | mit | 93 | master | 2,003 | require "active_model/type"
require "base32/crockford"
require "ulid/rails/errors"
module ULID
module Rails
class Type < ActiveModel::Type::Binary
def assert_valid_value(value)
raise ArgumentError, "`#{value}` is not a ULID format" unless Data.valid_ulid?(value)
end
def cast(value)
... |
github | k2nr/ulid-rails | https://github.com/k2nr/ulid-rails | lib/ulid/rails/patch.rb | Ruby | mit | 93 | master | 341 | module ULID
module Rails
module Patch
module Migrations
def virtual_ulid_timestamp(timestamp_column_name, ulid_column_name)
virtual timestamp_column_name,
type: :datetime,
as: "FROM_UNIXTIME(CONV(HEX(#{ulid_column_name} >> 80), 16, 10) / 1000.0)"
end
e... |
github | k2nr/ulid-rails | https://github.com/k2nr/ulid-rails | lib/ulid/rails/postgresql_type.rb | Ruby | mit | 93 | master | 884 | require_relative "type"
module ULID
module Rails
class PostgresqlType < Type
class Data < ULID::Rails::Type::Data
def hex
hexed = super
return nil if hexed.nil?
[hexed].pack("H*")
end
alias_method :to_s, :hex
end
# Inspired by active_recor... |
github | k2nr/ulid-rails | https://github.com/k2nr/ulid-rails | lib/ulid/rails/sqlite_type.rb | Ruby | mit | 93 | master | 416 | require_relative "type"
module ULID
module Rails
class SqliteType < Type
class Data < ULID::Rails::Type::Data
alias_method :to_s, :hex
end
private
def cast_string_to_ulid(value)
if value.is_a?(String) && value.length == 32
Data.from_serialized(value)
el... |
github | k2nr/ulid-rails | https://github.com/k2nr/ulid-rails | test/test_helper.rb | Ruby | mit | 93 | master | 3,266 | $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
require "irb"
require "pry-byebug"
require "logger"
require "ulid/rails"
require "minitest/autorun"
db_sets = {
"sqlite3" => {
adapter: "sqlite3",
database: ":memory:"
},
"mysql56" => {
host: "mysql56",
adapter: "mysql2",
username: "... |
github | k2nr/ulid-rails | https://github.com/k2nr/ulid-rails | test/ulid/rails_test.rb | Ruby | mit | 93 | master | 6,880 | require "test_helper"
class ULID::Rails::TypeTest < Minitest::Test
def setup
@ulid = "01ARZ3NDEKTSV4RRFFQ69G5FAV"
end
def type
case database_adapter
when "mysql2", "trilogy"
ULID::Rails::Type.new
when "sqlite3"
ULID::Rails::SqliteType.new
when "postgresql"
ULID::Rails::Post... |
github | k2nr/ulid-rails | https://github.com/k2nr/ulid-rails | test/ulid/rails/type_test.rb | Ruby | mit | 93 | master | 1,356 | require "test_helper"
class ULID::Rails::Type::DataTest < Minitest::Test
def test_has_26_valid_characters
id = "01BX5ZZKBKACTAV9WEVGEMMVRZ"
assert ULID::Rails::Type::Data.valid_ulid?(id)
end
def test_length_less_than_26
id = "A" * 25
refute ULID::Rails::Type::Data.valid_ulid?(id)
end
def ... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | panda.gemspec | Ruby | mit | 93 | master | 1,015 | # -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "panda/version"
Gem::Specification.new do |s|
s.name = "panda"
s.version = Panda::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Pandastream"]
s.email = ["info@pandastream.com"]
s.homepage = "h... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | spec/spec_helper.rb | Ruby | mit | 93 | master | 453 | $LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'panda'
require 'rspec'
require 'webmock/rspec'
include WebMock::API
def hputs(*args)
puts ERB::Util.html_escape(args.join("\n")).gsub(/\r?\n/, '<br/>') + '<br/>'
end
RSpec.configure do |config|
... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | spec/cloud_spec.rb | Ruby | mit | 93 | master | 4,549 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe Panda::Cloud do
describe "region" do
it "should tell the region" do
Panda.configure do
access_key "my_access_key"
secret_key "my_secret_key"
api_host "api.pandastream.com"
cloud_id 'my_cloud_id'
... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | spec/heroku_spec.rb | Ruby | mit | 93 | master | 943 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe Panda::Video do
before(:each) do
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\"}"
stub_http_request(:get, /api.example.com:443\/v2\/clouds\/my_cloud_id.json/).
to_return(:body => cloud_json)
my_her... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | spec/profile_spec.rb | Ruby | mit | 93 | master | 3,976 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe Panda::Profile do
before(:each) do
cloud_json = "{\"s3_videos_bucket\":\"my_bucket\",\"id\":\"my_cloud_id\"}"
stub_http_request(:get, /api.example.com:85\/v2\/clouds\/my_cloud_id.json/).
to_return(:body => cloud_json)
Pand... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | spec/encoding_spec.rb | Ruby | mit | 93 | master | 10,731 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe Panda::Encoding do
before(:each) do
Panda.configure do
access_key "my_access_key"
secret_key "my_secret_key"
api_host "api.example.com"
cloud_id 'my_cloud_id'
api_port 85
end
end
it "should f... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | spec/video_spec.rb | Ruby | mit | 93 | master | 14,631 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
describe Panda::Video do
before(:each) do
Panda.configure do
access_key "my_access_key"
secret_key "my_secret_key"
api_host "api.example.com"
cloud_id 'my_cloud_id'
api_port 85
end
end
it "should ... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | spec/panda_spec.rb | Ruby | mit | 93 | master | 7,617 | require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'timecop'
describe Panda do
before(:each) do
new_time = Time.utc(2010, 1, 12, 1, 0, 0)
Timecop.freeze(new_time)
end
describe "when not connected" do
["get", "post", "put", "delete"].each do |method|
it "should rai... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda.rb | Ruby | mit | 93 | master | 851 | require 'panda/version'
require 'panda/api_authentication'
require 'panda/connection'
require 'panda/config'
require 'panda/modules/router'
require 'panda/modules/finders'
require 'panda/modules/builders'
require 'panda/modules/destroyers'
require 'panda/modules/associations'
require 'panda/modules/updatable'
require '... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/api_authentication.rb | Ruby | mit | 93 | master | 1,952 | require 'rubygems'
require 'cgi'
require 'time'
require 'hmac'
require 'hmac-sha2'
require 'base64'
module Panda
class ApiAuthentication
def self.generate_signature(verb, request_uri, host, secret_key, params_given={})
# Ensure all param keys are strings
params = {}; params_given.each {|k,v| params[k... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/base.rb | Ruby | mit | 93 | master | 2,278 | require 'forwardable'
module Panda
class Base
attr_accessor :attributes, :errors
extend Forwardable
include Panda::Router
include Panda::Builders
include Panda::Finders
def initialize(attributes = {})
clear_attributes
load(attributes)
end
class << self
def sti_... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/connection.rb | Ruby | mit | 93 | master | 2,917 | module Panda
API_PORT=443
US_API_HOST="api.pandastream.com"
EU_API_HOST="api-eu.pandastream.com"
class Connection
attr_accessor :api_host, :api_port, :access_key, :secret_key, :api_version, :cloud_id
def initialize(auth_params={})
params = { :api_host => US_API_HOST, :api_port => API_PORT ... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/config.rb | Ruby | mit | 93 | master | 1,814 | require 'uri'
module Panda
class Config
def self.from_panda_url(panda_url)
panda_uri = URI.parse(panda_url)
config = new
config.access_key = panda_uri.user
config.secret_key = panda_uri.password
config.cloud_id = panda_uri.path[1..-1]
config.api_host = panda_uri.host
... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/panda.rb | Ruby | mit | 93 | master | 1,326 | module Panda
extend self
extend Forwardable
attr_reader :cloud, :clouds
attr_reader :connection
def_delegators :connection, :get, :post, :put, :delete, :api_url, :setup_bucket, :signed_params
def configure(auth_params=nil, &block)
raise ArgumentError, "missing auth params or block" unless auth_param... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/upload_session.rb | Ruby | mit | 93 | master | 2,919 | CHUNK_SIZE = 100 * 1024 # 5 * 1024 * 1024
class File
def each_chunk_with_index()
i = 0
until eof?
yield(read(CHUNK_SIZE), i)
i = i+1
end
end
end
module Panda
class UploadSession
attr_reader :location, :status, :video, :error_message, :file_name, :file_size
def initialize(file_na... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/errors.rb | Ruby | mit | 93 | master | 290 | module Panda
class Error < StandardError; end
class APIError < Panda::Error
def initialize(options)
super("#{options['error']}: #{options['message']}")
end
end
class ServiceNotAvailable < Panda::Error
end
class ConfigurationError < Panda::Error
end
end |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/faraday.rb | Ruby | mit | 93 | master | 2,325 | require 'faraday'
require 'multi_json'
module Panda
module HttpClient
class Faraday
def initialize(api_url)
@api_url = api_url
end
def get(request_uri, params)
rescue_json_parsing do
connection.get do |req|
req.url File.join(connection.path_prefix, request... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/resources/encoding.rb | Ruby | mit | 93 | master | 1,135 | module Panda
class Encoding < Resource
include VideoState
belongs_to :video
has_one :profile
class << self
def first
EncodingScope.new(self).per_page(1).first
end
end
def url(options={})
default_options = {:https => false}
options = default_options.merge(opti... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/resources/cloud.rb | Ruby | mit | 93 | master | 1,187 | module Panda
class Cloud < Base
include Panda::Updatable
attr_reader :connection
def initialize(attributes={})
super(attributes)
connection_params = Panda.connection.to_hash.merge!(:cloud_id => id)
@connection = Connection.new(connection_params)
Panda.clouds[id] = self
en... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/resources/profile.rb | Ruby | mit | 93 | master | 380 | module Panda
class Profile < Resource
include Panda::Updatable
has_many :encodings
def preset?
!preset_name
end
# override attributes command and preset_name
# to ovoid <method undefined> when profile is a preset or not
def command
@attributes['command']
end
def pre... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/resources/video.rb | Ruby | mit | 93 | master | 847 | module Panda
class Video < Resource
include VideoState
has_many :encodings
class << self
def first
VideoScope.new(self).per_page(1).first
end
end
def metadata
connection.get("/videos/#{id}/metadata.json")
end
def delete_source
connection.delete("/videos/#... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/resources/resource.rb | Ruby | mit | 93 | master | 972 | module Panda
class Resource < Base
include Panda::Destroyers
include Panda::Associations
include Panda::CloudConnection
def initialize(attributes={})
super(attributes)
@attributes['cloud_id'] ||= Panda.cloud.id
end
class << self
include Panda::CloudConnection
def clo... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/modules/finders.rb | Ruby | mit | 93 | master | 1,523 | module Panda
module Finders
def self.included(base)
base.extend(FindOne)
base.extend(FindMany)
end
module FindOne
def find(id)
raise 'find method requires a correct value' if id.nil? || id == ''
find_by_path(one_path, {:id => id})
end
def find_object_b... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/modules/router.rb | Ruby | mit | 93 | master | 1,375 | module Panda
module Router
VAR_PATTERN = /:\w+/
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def resource_path
@url || "/#{sti_name.downcase}s"
end
def match(url)
@url = url
end
def many_path
resource_path
... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/modules/associations.rb | Ruby | mit | 93 | master | 1,457 | module Panda
module Associations
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def has_one(relation_name)
# for example creates : @video ||= VideoScope.new(self)
define_method relation_name do
param_id = "#{relation_name}_id"
i... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/modules/updatable.rb | Ruby | mit | 93 | master | 607 | module Panda
module Updatable
def save
new? ? create : update
end
def save!
save || raise(errors.last)
end
def update_attribute(name, value)
send("#{name}=".to_sym, value) && save
end
def update_attributes(attributes)
load(attributes) && save
end
def up... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/modules/destroyers.rb | Ruby | mit | 93 | master | 468 | module Panda
module Destroyers
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def delete(id)
uri = create_rest_url(one_path,{:id =>id})
response = connection.delete(uri)
!!response['deleted']
end
end
def delete
u... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/modules/video_state.rb | Ruby | mit | 93 | master | 243 | module Panda
module VideoState
def success?
@attributes['status'] == 'success'
end
def processing?
@attributes['status'] == 'processing'
end
def fail?
@attributes['status'] == 'fail'
end
end
end |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/modules/builders.rb | Ruby | mit | 93 | master | 968 | module Panda
module Builders
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def create(attributes={})
resource = build_resource(attributes)
yield resource if block_given?
resource.create
resource
end
def create!(attributes... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/proxies/encoding_scope.rb | Ruby | mit | 93 | master | 1,167 | module Panda
class EncodingScope < Scope
def initialize(parent)
super(parent, Encoding)
end
def non_delegate_methods
super + [:status, :profile_id, :profile_name, :video, :page, :per_page, :[]]
end
def page(this_page)
@scoped_attributes[:page] = this_page
self
end
... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/proxies/proxy.rb | Ruby | mit | 93 | master | 479 | module Panda
class Proxy
include Panda::Router::ClassMethods
include Panda::Builders::ClassMethods
include Panda::Finders::FindMany
include Panda::Finders::FindOne
include Panda::CloudConnection
attr_accessor :parent, :klass
def initialize(parent, klass)
@parent = parent
... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/proxies/video_scope.rb | Ruby | mit | 93 | master | 481 | module Panda
class VideoScope < Scope
def initialize(parent)
super(parent, Video)
end
def non_delegate_methods
super + [:status, :page, :per_page]
end
def page(this_page)
@scoped_attributes[:page] = this_page
self
end
def per_page(this_per_page)
@scoped_at... |
github | pandastream/panda_gem | https://github.com/pandastream/panda_gem | lib/panda/proxies/scope.rb | Ruby | mit | 93 | master | 2,210 | require 'forwardable'
module Panda
class Scope < Proxy
extend Forwardable
def respond_to?(method)
scoped_methods = [].methods.map{|i| i.to_sym} - non_delegate_methods + [:reload, :non_delegate_methods]
!(scoped_methods).include?(method.to_sym)
end
def non_delegate_methods
[:nil?,... |
github | shenoudab/active_device | https://github.com/shenoudab/active_device | active_device.gemspec | Ruby | mit | 93 | master | 745 | # -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "active_device/version"
Gem::Specification.new do |s|
s.name = "active_device"
s.version = ActiveDevice::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ["Shenouda Bertel"]
s.email = ["sbertel@mobithou... |
github | shenoudab/active_device | https://github.com/shenoudab/active_device | lib/active_device.rb | Ruby | mit | 93 | master | 4,534 | #--
# Copyright (c) 2009 Shenouda Bertel <sbertel@mobithought.com>, MobiThought.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the righ... |
github | shenoudab/active_device | https://github.com/shenoudab/active_device | lib/active_device/brand.rb | Ruby | mit | 93 | master | 9,448 | class Brand
##
# User agent string.
attr_reader :user_agent
##
# Initialize with user agent _string_.
def initialize user_agent
@user_agent = user_agent.strip
end
##
# Return the brand for user agent _string_.
def self.mobile_brand user_agent
case user_agent
when /SonyEricsson/i ... |
github | shenoudab/active_device | https://github.com/shenoudab/active_device | lib/active_device/bot.rb | Ruby | mit | 93 | master | 1,448 | class Bot
##
# User agent string.
attr_reader :user_agent
##
# Initialize with user agent _string_.
def initialize user_agent
@user_agent = user_agent.strip
end
##
# Check UserAgent is Bot.
def self.is_bot? user_agent
case user_agent
when /bot/i ; true
when /S... |
github | shenoudab/active_device | https://github.com/shenoudab/active_device | lib/active_device/os.rb | Ruby | mit | 93 | master | 2,804 | class Os
##
# User agent string.
attr_reader :user_agent
##
# Initialize with user agent _string_.
def initialize user_agent
@user_agent = user_agent.strip
end
##
# Return the os for user agent _user_agent_.
def self.os user_agent
case user_agent
when /Android/i ; :Andr... |
github | shenoudab/active_device | https://github.com/shenoudab/active_device | lib/active_device/model.rb | Ruby | mit | 93 | master | 3,328 | class Model
##
# User agent user_agent.
attr_reader :user_agent
##
# Initialize with user agent _user_agent_.
def initialize user_agent
@user_agent = user_agent.strip
end
def self.brand_model user_agent
case user_agent
when /iPad/i ; :iPad
when /iPhone/i ... |
github | shenoudab/active_device | https://github.com/shenoudab/active_device | lib/active_device/handset.rb | Ruby | mit | 93 | master | 1,113 | require 'active_device/brand'
require 'active_device/model'
class Handset
##
# User agent string.
attr_reader :user_agent
##
# Initialize with user agent _string_.
def initialize user_agent
@user_agent = user_agent.strip
end
##
# Is _string_. Mobile Device
def self.is_mobile? user_agent... |
github | shenoudab/active_device | https://github.com/shenoudab/active_device | lib/active_device/engine.rb | Ruby | mit | 93 | master | 1,730 | class Engine
##
# User agent string.
attr_reader :user_agent
##
# Initialize with user agent _string_.
def initialize user_agent
@user_agent = user_agent.strip
end
##
# Return engine symbol for user agent _user_agent_.
def self.engine user_agent
case user_agent
when /AppleWebKit... |
github | shenoudab/active_device | https://github.com/shenoudab/active_device | lib/active_device/user_agent.rb | Ruby | mit | 93 | master | 672 | class UserAgent
##
# User agent user_agent.
attr_reader :user_agent
##
# Initialize with user agent _user_agent_.
def initialize user_agent
@user_agent = user_agent.strip
end
##
# User agent user_agent.
def to_s
user_agent
end
##
# Inspect.
def inspect
"#<Agent:#{name} v... |
github | shenoudab/active_device | https://github.com/shenoudab/active_device | lib/active_device/browser.rb | Ruby | mit | 93 | master | 9,382 | class Browser
##
# User agent string.
attr_reader :user_agent
##
# Initialize with user agent _user_agent_.
def initialize user_agent
@user_agent = user_agent.strip
end
##
# Return name for user agent _user_agent_.
def self.name user_agent
case user_agent
when /ABrowse/i ... |
github | shenoudab/active_device | https://github.com/shenoudab/active_device | lib/active_device/helper.rb | Ruby | mit | 93 | master | 2,360 | #--
# Copyright (c) 2009 Shenouda Bertel <sbertel@mobithought.com>, MobiThought.
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the righ... |
github | fl00r/pickup | https://github.com/fl00r/pickup | pickup.gemspec | Ruby | mit | 93 | master | 747 | # -*- encoding: utf-8 -*-
require File.expand_path('../lib/pickup/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ["fl00r"]
gem.email = ["fl00r@yandex.ru"]
gem.description = %q{Pickup helps you to pick item from collection by it's weight/probability}
gem.summary = %q{Pic... |
github | fl00r/pickup | https://github.com/fl00r/pickup | Rakefile | Ruby | mit | 93 | master | 219 | #!/usr/bin/env rake
require "bundler/gem_tasks"
require 'rake/testtask'
task :default => :spec
desc 'Tests'
Rake::TestTask.new(:spec) do |t|
t.libs << 'spec'
t.pattern = 'spec/**/*_spec.rb'
t.verbose = false
end |
github | fl00r/pickup | https://github.com/fl00r/pickup | lib/pickup.rb | Ruby | mit | 93 | master | 942 | require 'pickup/version'
class Pickup
require 'pickup/circle_iterator'
require 'pickup/mapped_list'
attr_reader :list, :uniq
attr_writer :pick_func, :key_func, :weight_func
def initialize(list, opts = {}, &block)
@list = list
@uniq = opts[:uniq] || false
@pick_func = block if block_given?
@... |
github | fl00r/pickup | https://github.com/fl00r/pickup | lib/pickup/mapped_list.rb | Ruby | mit | 93 | master | 1,800 | class Pickup
class MappedList
attr_reader :list, :func, :uniq
BOOLEAN_DEPRECATION ||= '[DEPRECATED] Passing uniq as a boolean to ' \
"MappedList's initialize method is deprecated. Please use the opts hash " \
'instead.'.freeze
def initialize(list, func, opts = nil)
if opts.is_a?(Hash)
... |
github | fl00r/pickup | https://github.com/fl00r/pickup | lib/pickup/circle_iterator.rb | Ruby | mit | 93 | master | 827 | class Pickup
class CircleIterator
attr_reader :func, :obj, :max
def initialize(obj, func, max, opts = {})
@obj = obj.dup
@func = func
@max = max
@key_func = Pickup.func_opt(opts[:key_func]) || key_func
@weight_func = Pickup.func_opt(opts[:weight_func]) || weight_func
end
... |
github | fl00r/pickup | https://github.com/fl00r/pickup | spec/pickup/pickup_spec.rb | Ruby | mit | 93 | master | 4,206 | # encoding: utf-8
require 'spec_helper'
require 'ostruct'
require 'stringio'
describe Pickup do
before do
@list = {
"selmon" => 1, # 1
"carp" => 4, # 5
"crucian" => 3, # 8
"herring" => 6, # 14
"sturgeon" => 8, # 22
"gudgeon" => 10, # 32
"minnow... |
github | fl00r/pickup | https://github.com/fl00r/pickup | benchmarks/pickup.rb | Ruby | mit | 93 | master | 1,176 | require 'benchmark'
require './lib/pickup'
def simple_hash
@simple ||= begin
hash = {}
(1..30).to_a.each do |i|
hash["item_#{i}"] = rand(30)
end
hash
end
end
def big_hash
@big ||= begin
hash = {}
(1..5000).to_a.each do |i|
hash["item_#{i}"] = rand(1000)
end
hash
end... |
github | talison/rack-mobile-detect | https://github.com/talison/rack-mobile-detect | Rakefile | Ruby | mit | 93 | master | 1,725 | require 'rubygems'
require 'rake'
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "rack-mobile-detect"
gem.summary = %Q{Rack middleware for ruby webapps to detect mobile devices.}
gem.description = %Q{Rack::MobileDetect detects mobile devices and adds an
X_MOBILE_DEVICE header to the... |
github | talison/rack-mobile-detect | https://github.com/talison/rack-mobile-detect | rack-mobile-detect.gemspec | Ruby | mit | 93 | master | 1,879 | # Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{rack-mobile-detect}
s.version = "0.4.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :requ... |
github | talison/rack-mobile-detect | https://github.com/talison/rack-mobile-detect | util/echo_env.rb | Ruby | mit | 93 | master | 549 | require 'rubygems'
require 'sinatra'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'rack/mobile-detect'
use Rack::MobileDetect
# Very simple sinatra app that allows debugging of the headers with
# Rack::MobileDetect. Also useful for looking at various mobile phone
# headers.
get '/' do
... |
github | talison/rack-mobile-detect | https://github.com/talison/rack-mobile-detect | test/helper.rb | Ruby | mit | 93 | master | 229 | require 'rubygems'
require 'test/unit'
require 'shoulda'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rack/mobile-detect'
class Test::Unit::TestCase
end |
github | talison/rack-mobile-detect | https://github.com/talison/rack-mobile-detect | test/test_rack-mobile-detect.rb | Ruby | mit | 93 | master | 9,754 | require 'helper'
class TestRackMobileDetect < Test::Unit::TestCase
context "An app with mobile-device defaults" do
setup do
@app = test_app
@rack = Rack::MobileDetect.new(@app)
end
should "not detect a non-mobile device" do
env = test_env
@rack.call(env)
assert !env.key?(x... |
github | talison/rack-mobile-detect | https://github.com/talison/rack-mobile-detect | lib/rack/mobile-detect.rb | Ruby | mit | 93 | master | 7,269 | # The MIT License
#
# Copyright (c) 2009 Tom Alison
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merg... |
github | raileurope/lolsoap | https://github.com/raileurope/lolsoap | Rakefile | Ruby | mit | 93 | master | 269 | # encoding: utf-8
require 'rubygems'
require 'bundler/setup'
require 'bundler/gem_tasks'
require 'rake'
require 'rake/testtask'
Rake::TestTask.new do |t|
t.libs = ["test"]
t.pattern = "test/**/test_*.rb"
t.ruby_opts = ['-w']
end
task :default => :test |
github | raileurope/lolsoap | https://github.com/raileurope/lolsoap | lolsoap.gemspec | Ruby | mit | 93 | master | 1,065 | # coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'lolsoap/version'
Gem::Specification.new do |spec|
spec.name = "lolsoap"
spec.version = LolSoap::VERSION
spec.authors = ["Jon Leighton"]
spec.summary = %q{A libr... |
github | raileurope/lolsoap | https://github.com/raileurope/lolsoap | lib/lolsoap.rb | Ruby | mit | 93 | master | 271 | module LolSoap
require 'lolsoap/builder'
require 'lolsoap/client'
require 'lolsoap/envelope'
require 'lolsoap/fault'
require 'lolsoap/request'
require 'lolsoap/response'
require 'lolsoap/wsdl'
require 'lolsoap/wsdl_parser'
require 'lolsoap/version'
end |
github | raileurope/lolsoap | https://github.com/raileurope/lolsoap | lib/lolsoap/builder.rb | Ruby | mit | 93 | master | 3,487 | # frozen_string_literal: true
require 'lolsoap/wsdl'
module LolSoap
# Used to build XML, with namespaces automatically added.
#
# @example General
# builder = Builder.new(node, type)
# builder.someTag do |t|
# t.foo 'bar'
# end
# # => <ns1:someTag><ns1:foo>bar</ns1:foo></ns1:someTag>
#
... |
github | raileurope/lolsoap | https://github.com/raileurope/lolsoap | lib/lolsoap/client.rb | Ruby | mit | 93 | master | 689 | require 'lolsoap/wsdl'
require 'lolsoap/request'
require 'lolsoap/envelope'
require 'lolsoap/response'
module LolSoap
class Client
attr_reader :wsdl
# @param wsdl a WSDL object, or a string that will be parsed into one
def initialize(wsdl)
@wsdl = wsdl.respond_to?(:to_str) ? WSDL.parse(wsdl.to_str... |
github | raileurope/lolsoap | https://github.com/raileurope/lolsoap | lib/lolsoap/wsdl_parser.rb | Ruby | mit | 93 | master | 11,540 | # frozen_string_literal: true
require 'nokogiri'
require 'cgi'
module LolSoap
# @private
class WSDLParser
class ParseError < StandardError; end
class Schema < Struct.new(:target_namespace, :element_form_default)
UNQUALIFIED = 'unqualified'
def self.from_node(node)
new(
node... |
github | raileurope/lolsoap | https://github.com/raileurope/lolsoap | lib/lolsoap/response.rb | Ruby | mit | 93 | master | 1,364 | require 'lolsoap/fault'
require 'lolsoap/hash_builder'
require 'nokogiri'
module LolSoap
class Response
attr_reader :request, :doc
# Create a new instance from a raw XML string
def self.parse(request, raw)
new(
request,
Nokogiri::XML::Document.parse(
raw, nil, nil,
... |
github | raileurope/lolsoap | https://github.com/raileurope/lolsoap | lib/lolsoap/wsdl.rb | Ruby | mit | 93 | master | 4,939 | # frozen_string_literal: true
require 'lolsoap/wsdl_parser'
module LolSoap
class WSDL
require 'lolsoap/wsdl/operation'
require 'lolsoap/wsdl/operation_io'
require 'lolsoap/wsdl/type'
require 'lolsoap/wsdl/named_type_reference'
require 'lolsoap/wsdl/immediate_type_reference'
require 'lolsoap/... |
github | raileurope/lolsoap | https://github.com/raileurope/lolsoap | lib/lolsoap/hash_builder.rb | Ruby | mit | 93 | master | 1,249 | module LolSoap
# Turns an XML node into a hash data structure. Works out which elements
# are supposed to be collections based on the type information.
class HashBuilder
attr_reader :node, :type
def initialize(node, type)
@node = node
@type = type
end
def output
if node.first_e... |
github | raileurope/lolsoap | https://github.com/raileurope/lolsoap | lib/lolsoap/request.rb | Ruby | mit | 93 | master | 1,941 | module LolSoap
# Represents a HTTP request containing a SOAP Envelope
class Request
attr_reader :envelope
attr_accessor :xml_options
def initialize(envelope)
@envelope = envelope
@xml_options = default_xml_options
end
# @see Envelope#body
def body(&block)
envelope.bo... |
github | raileurope/lolsoap | https://github.com/raileurope/lolsoap | lib/lolsoap/fault.rb | Ruby | mit | 93 | master | 779 | module LolSoap
class Fault
attr_reader :request, :node
def initialize(request, node)
@request = request
@node = node
end
def soap_namespace
request.soap_namespace
end
def soap_version
request.soap_version
end
def code
node.at_xpath(
soap_ver... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.