code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
module Translatable
def translation_obj_for(field, lang)
lang ||= :eng
trans = translation_hash["#{field.to_s}__#{lang}"]
end
def translation_for(field, lang)
trans = translation_obj_for(field, lang)
trans ? trans.str : nil
end
def set_translation_for(field, lang, str)
trans = translation_... | Ruby |
# ISO 639-2 languages and codes
module LanguageList
LANGS = {
:aar => 'Afar',
:abk => 'Abkhazian',
:ave => 'Avestan',
:afr => 'Afrikaans',
:aka => 'Akan',
:amh => 'Amharic',
:arg => 'Aragonese',
:ara => 'Arabic',
:asm => 'Assamese',
:ava => 'Avaric',
:aym => 'Aymara',
:... | Ruby |
module MissionBased
module ClassMethods
def mission_based?
return true
end
end
def self.included(base)
# ruby idiom to activate class methods
base.extend(ClassMethods)
# add scope
base.class_eval do
belongs_to(:mission, :inverse_of => base.model_name.plural.to_sym)
... | Ruby |
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run ELMO::Application
| Ruby |
ENV["RAILS_ENV"] = "test"
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
class ActiveSupport::TestCase
#####################################################
# REPORT TEST HELPERS
def prep_objects
Role.generate
# clear out tables
[Question, Question... | Ruby |
require 'sinatra/activerecord/rake'
require './main' | Ruby |
source :gemcutter
gem 'sinatra', :require => 'sinatra/base'
gem 'thin', '~> 1.3'
gem 'pg'
gem 'sinatra-activerecord'
gem 'google-api-client', '>= 0.4.4', :require => 'google/api_client'
group :development do
gem 'rake'
gem 'sqlite3-ruby'
end
| Ruby |
class CreateUsers < ActiveRecord::Migration
def up
create_table :users do |t|
t.string :profile_id
t.string :email
t.string :refresh_token
end
add_index :users, :profile_id
end
def down
drop_table :users
end
end
| Ruby |
# Copyright (C) 2012 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | Ruby |
require 'sinatra.rb'
# Sinatra defines #set at the top level as a way to set application configuration
set :run, false
set :env, (ENV['RACK_ENV'] ? ENV['RACK_ENV'].to_sym : :development)
require './main'
run Sinatra::Application | Ruby |
require 'mongowiki'
def test_output_file(filename, infolist)
File.open(filename, 'w') do |io|
infolist.each do |info|
io.puts "Title: #{info[:title]}"
io.puts "URL: #{info[:url]}"
io.puts "Keywords: #{info[:keywords].join(',')},"
io.puts "Links:"
info[:links].each { |l| io.puts l }
... | Ruby |
require 'mongowiki/wikiparser'
require 'mongowiki/wikipage' | Ruby |
module Mongowiki
class Wikipage
attr_accessor :title, :url, :keywords, :links, :citations
attr_reader :dbname, :host, :port
DEFAULT_DBNAME = 'specdb'
DEFAULT_HOST = 'localhost'
DEFAULT_PORT = 27017
def self.import(pagelist, *conn)
connect(*conn) do |pages|
pagelist.... | Ruby |
module Mongowiki
class Wikiparser
def self.parse(filename)
pages = []
File.open(filename) do |file|
while(true)
page = parse_one(file)
break if page.nil?
pages << page
end
end
pages
end
private
def self.parse_one(file)
... | Ruby |
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person',... | Ruby |
# Be sure to restart your server when you modify this file.
# These settings change the behavior of Rails 2 apps and will be defaults
# for Rails 3. You can remove this initializer when Rails 3 is released.
if defined?(ActiveRecord)
# Include Active Record class name as root for JSON serialized output.
ActiveReco... | Ruby |
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
| Ruby |
# Be sure to restart your server when you modify this file.
# Your secret key for verifying cookie session data integrity.
# If you change this key, all old sessions will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
Act... | Ruby |
# Be sure to restart your server when you modify this file.
# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.
# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }
# You can also remove all the silencers if you're trying do debug a probl... | Ruby |
# Settings specified here will take precedence over those in config/environment.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Full error reports are disabled and caching is turned on
config.action_controller.consider_all_reque... | Ruby |
# Settings specified here will take precedence over those in config/environment.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.ca... | Ruby |
# Settings specified here will take precedence over those in config/environment.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 suite and is wiped
# and recreated between... | Ruby |
# Be sure to restart your server when you modify this file
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.4' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
... | Ruby |
# Don't change this file!
# Configure your app in config/environment.rb and config/environments/*.rb
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
module Rails
class << self
def boot!
unless booted?
preinitialize
pick_boot.run
end
end
def booted?
... | Ruby |
ActionController::Routing::Routes.draw do |map|
# The priority is based upon order of creation: first created -> highest priority.
# Sample of regular route:
# map.connect 'products/:id', :controller => 'catalog', :action => 'view'
# Keep in mind you can assign values other than :controller and :action
# ... | Ruby |
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
end
| Ruby |
module WelcomeHelper
end
| Ruby |
module ProfileHelper
end
| Ruby |
module LoginHelper
end
| Ruby |
class User < ActiveRecord::Base
end
| Ruby |
class WelcomeController < ApplicationController
def index
end
end
| Ruby |
class ProfileController < ApplicationController
def index
@user = session[:authentication]
end
def save
@user = session[:authentication]
if params[:new_password] != params[:confirm_new_password]
flash[:profile_error] = "Passwords do not match !"
render :action => "index"
end
if... | Ruby |
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryPr... | Ruby |
class LoginController < ApplicationController
def login
@username = params[:username]
@password = params[:password]
valid_user = User.find(:first,:conditions => ["username = ? and password = ?",@username, @password])
if valid_user
flash[:notice] = "Welcome" + " " + @username
session[:auth... | Ruby |
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/dbconsole'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/console'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/runner'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/benchmarker'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/benchmarker'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/profiler'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/profiler'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/plugin'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/destroy'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
$LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
require 'commands/about'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/dbconsole'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/runner'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/server'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/generate'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/console'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/destroy'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/generate'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/server'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
$LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info"
require 'commands/about'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/plugin'
| Ruby |
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :username
t.string :password
t.string :email
t.string :phone
t.string :fax
t.timestamps
end
end
def self.down
drop_table :users
end
end
| Ruby |
# This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }])
# Major.create(:name... | Ruby |
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
class ActiveSupport::TestCase
# Transactional fixtures accelerate your tests by wrapping each test method
# in a transaction that's rolled back on completion. This ensures that the
# test da... | Ruby |
require 'open-uri'
require 'rexml/document'
GET_CATEGORY_URI = 'http://localhost:3000/categories/show/'
LIST_CATEGORIES_URI = 'http://localhost:3000/categories'
def get_category(categoryID)
response = open("#{GET_CATEGORY_URI}#{categoryID}.xml").read
#document = REXML::Document.new(response)
#REXML::XP... | Ruby |
#!/usr/bin/env ruby
require 'rubygems'
require 'activeresource'
class User < ActiveResource::Base
self.site = "http://localhost:3000"
end
#list all users
def list_users
puts "listing all users.."
users = User.find(:all)
users.each do |user|
puts "#{user.id}, #{user.username}, #{user.email}"
end
end
#cr... | Ruby |
#!/usr/bin/env ruby
require 'rubygems'
require 'activeresource'
class User < ActiveResource::Base
self.site = "http://localhost:3000"
end
#list all users
def list_users
puts "listing all users.."
users = User.find(:all)
users.each do |user|
puts "#{user.id}, #{user.username}, #{user.email}"
end
end
#cr... | Ruby |
require 'rubygems'
require 'json'
require 'net/http'
require 'yaml'
def get_users
base_url = "http://localhost:3000"
url = "#{base_url}/users.json"
resp = Net::HTTP.get_response(URI.parse(url))
data = resp.body
# convert JSON to Ruby
result = JSON.parse(data)
return result
end
# listing users
u... | Ruby |
require 'net/https'
require "rexml/document"
def list_users
resp = "";
http = Net::HTTP.new("localhost", 3000)
http.start do |http|
req = Net::HTTP::Get.new("/users.xml")
response = http.request(req)
resp = response.body
end
doc = REXML::Document.new(resp)
REXML::XPath.each(doc, '//users/user') do |use... | Ruby |
# Be sure to restart your server when you modify this file.
# Add new inflection rules using the following format
# (all these examples are active by default):
# ActiveSupport::Inflector.inflections do |inflect|
# inflect.plural /^(ox)$/i, '\1en'
# inflect.singular /^(ox)en/i, '\1'
# inflect.irregular 'person',... | Ruby |
# These settings change the behavior of Rails 2 apps and will be defaults
# for Rails 3. You can remove this initializer when Rails 3 is released.
if defined?(ActiveRecord)
# Include Active Record class name as root for JSON serialized output.
ActiveRecord::Base.include_root_in_json = true
# Store the full clas... | Ruby |
# Be sure to restart your server when you modify this file.
# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
# Mime::Type.register_alias "text/html", :iphone
| Ruby |
# Settings specified here will take precedence over those in config/environment.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Enable threaded mode
# config.threadsafe!
# Use a different logger for distributed setups
# config.... | Ruby |
# Settings specified here will take precedence over those in config/environment.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.ca... | Ruby |
# Settings specified here will take precedence over those in config/environment.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 suite and is wiped
# and recreated between... | Ruby |
# Be sure to restart your server when you modify this file
# Uncomment below to force Rails into production mode when
# you don't control web/app server and can't set it the proper way
# ENV['RAILS_ENV'] ||= 'production'
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.2... | Ruby |
# Don't change this file!
# Configure your app in config/environment.rb and config/environments/*.rb
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
module Rails
class << self
def boot!
unless booted?
preinitialize
pick_boot.run
end
end
def booted?
... | Ruby |
ActionController::Routing::Routes.draw do |map|
map.resources :users do |user|
user.resources :accesses
end
# The priority is based upon order of creation: first created -> highest priority.
# Sample of regular route:
# map.connect 'products/:id', :controller => 'catalog', :action => 'view'
# Keep... | Ruby |
module RepliesHelper
end
| Ruby |
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
end
| Ruby |
module TopicsHelper
end
| Ruby |
require 'redcloth'
module MywikiHelper
# parse and return data as HTML
def to_html(rawtext)
return "" if rawtext.nil?
r = RedCloth.new rawtext
r.to_html
end
def use_tinymce
@content_for_tinymce = ""
content_for :tinymce do
javascript_include_tag "tiny_mce/tiny_mce"
end
... | Ruby |
module UsersHelper
end
| Ruby |
module AccessesHelper
end
| Ruby |
module CategoriesHelper
end
| Ruby |
module HomeHelper
end
| Ruby |
class Category < ActiveRecord::Base
has_many :topics
end
| Ruby |
class MywikiUser < ActiveRecord::Base
#default_value_for :create, false
end
| Ruby |
class Topic < ActiveRecord::Base
belongs_to :category
has_many :replies
end
| Ruby |
require 'acts_as_ferret'
class Mywiki < ActiveRecord::Base
acts_as_ferret :fields => ['tags', 'body', 'title', 'description']
end
| Ruby |
class User < ActiveRecord::Base
validates_uniqueness_of :username
validates_presence_of :password
validates_length_of :password, :username, :minimum => 5
has_many :accesses
end
| Ruby |
class Reply < ActiveRecord::Base
belongs_to :topic
end
| Ruby |
class Access < ActiveRecord::Base
belongs_to :user
end
| Ruby |
class HomeController < ApplicationController
def index
#login page
end
#def admin
#redirect_to :action => 'admin'
#end
def register
#new user registration details....
#redirect_to :action=> 'register'
end
def guest
#redirect to guest page
#redirec... | Ruby |
class RepliesController < ApplicationController
def editReply
@reply = Reply.find(params[:id])
end
def update
@reply = Reply.find(params[:id])
if @reply.update_attributes(params[:reply])
@reply.save
redirect_to :controller => :replies, :action => :updatePage
else render :action =>... | Ruby |
# This class defines the user action supported by the program
# Author:: Rashmi Motgi(mailto: rashmi.motgi@gmail.com)
# Copyright:: Copyright (c) SJSU 2008
class MywikiUserController < ApplicationController
# index page is redirected to user privileges management page
def index
redirect_to :action => :manage
end... | Ruby |
class TopicsController < ApplicationController
def editTopic
@topic = Topic.find(params[:id])
end
def update
@topic = Topic.find(params[:id])
if @topic.update_attributes(params[:topic])
@topic.save
redirect_to :controller => :topics, :action => :updatePage
else render :action => :e... | Ruby |
# MyWiki is a program based on Ruby on Rails developed as part of a class
# project for the Fall 2008 session on CmpE 275 at SJSU. This program
# sets up a Wiki system supporting creating, editing, and deleting rich text
# pages. It supports built in full text search on page titles, tags, description
# and body, using... | Ruby |
class AccessesController < ApplicationController
def index
@user = User.find(params[:user_id])
@accesses = @user.accesses
end
def show
@user = User.find(params[:user_id])
@access = @user.accesses.find(params[:id])
end
def new
@user = User.find(params[:user_id])
@acc... | Ruby |
class CategoriesController < ApplicationController
def deleteCategory
Category.find(params[:id]).destroy
redirect_to :action => 'categoryDeleted'
end
def categoryDeleted
end
def editCategories
@category = Category.find(params[:id])
end
def update
@category = Category.find(params[:id])
... | Ruby |
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
# See ActionController::RequestForgeryProtection for details... | Ruby |
class UsersController < ApplicationController
# GET /users
# GET /users.xml
def index
@users = User.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @users }
format.json { render :json => @users }
end
end
# GET /users/1
# GET /users/... | Ruby |
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require(File.join(File.dirname(__FILE__), 'config', 'boot'))
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'tasks/rails'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/dbconsole'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/console'
| Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/runner'
| Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.