code
stringlengths
1
1.73M
language
stringclasses
1 value
class SimplifySignup < ActiveRecord::Migration def self.up ActiveRecord::Base.establish_connection :users rename_column "people", "home_phone", "phone" remove_column "people", "work_phone" remove_column "people", "address" end def self.down ActiveRecord::Base.establish_connection :users r...
Ruby
class CreateEmailAddresses < ActiveRecord::Migration def self.up ActiveRecord::Base.establish_connection :users create_table :email_addresses do |t| t.column :address, :string, :null => false t.column :primary, :boolean t.column :account_id, :integer, :null => false t.column :created_a...
Ruby
class RefactorPeople < ActiveRecord::Migration def self.up ActiveRecord::Base.establish_connection :users create_table :procon_profiles do |t| t.column :person_id, :integer, :null => false t.column :nickname, :string t.column :phone, :string t.column :best_call_time, :string end ...
Ruby
class CreateAccounts < ActiveRecord::Migration def self.up ActiveRecord::Base.establish_connection :users create_table :accounts do |t| t.column :password, :string, :null => false t.column :active, :boolean t.column :activation_key, :string t.column :created_at, :datetime t.colum...
Ruby
class CreatePeople < ActiveRecord::Migration def self.up ActiveRecord::Base.establish_connection :users create_table :people do |t| t.column :firstname, :string t.column :lastname, :string t.column :gender, :string t.column :nickname, :string t.column :address, :string t.co...
Ruby
class CreateRoles < ActiveRecord::Migration def self.up ActiveRecord::Base.establish_connection :users create_table :roles do |t| t.column :name, :string, :null => false end create_table :people_roles, :id => false do |t| t.column :person_id, :integer, :null => false t.column :role_i...
Ruby
class CreatePermissions < ActiveRecord::Migration def self.up ActiveRecord::Base.establish_connection :users create_table :permissions do |t| t.column :role_id, :integer, :null => false t.column :permission, :string t.column :permissioned_id, :integer t.column :permissioned_type, :stri...
Ruby
# Install hook code here
Ruby
require 'rake' require 'rake/testtask' require 'rake/rdoctask' desc 'Default: run unit tests.' task :default => :test desc 'Test the ae_users plugin.' Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.pattern = 'test/**/*_test.rb' t.verbose = true end desc 'Generate documentation for the ae_users plugin.' Rak...
Ruby
# desc "Explaining what the task does" #task :ae_users do # # Task goes here # end
Ruby
class EmailAddress < ActiveRecord::Base establish_connection :users belongs_to :account belongs_to :person validates_uniqueness_of :address def account Account.find(:first, :conditions => ["id = ?", read_attribute(:account_id)]) || Person.find(:first, :conditions => ["id = ?", read_attribute(:per...
Ruby
class Person < ActiveRecord::Base establish_connection :users has_and_belongs_to_many :roles has_many :permissions, :dependent => :destroy def account Account.find(:first, :conditions => ["id = ?", read_attribute(:account_id)]) || Account.find(:first, :conditions => ["person_id = ?", read_attribute...
Ruby
class AuthNotifier < ActionMailer::Base def account_activation(account, address=nil) if address.nil? address = account.primary_email_address elsif address.kind_of? EmailAddress address = address.address end @recipients = address @from = "accounts@#{default_url_options[:host]}" ...
Ruby
class Role < ActiveRecord::Base acts_as_permissioned :permission_names => ['edit'] establish_connection :users has_and_belongs_to_many :people has_many :permissions, :dependent => :destroy end
Ruby
class Permission < ActiveRecord::Base belongs_to :role belongs_to :person belongs_to :permissioned, :polymorphic => true def object return permissioned end def grantee if not role.nil? return role else return person end end end
Ruby
require 'digest/md5' class Account < ActiveRecord::Base establish_connection :users def person Person.find(:first, :conditions => ["id = ?", read_attribute(:person_id)]) || Person.find(:first, :conditions => ["account_id = ?", read_attribute(:id)]) end def email_addresses addrs = [] beg...
Ruby
class Login attr_accessor :email, :password, :remember, :return_to def initialize(args) if not args.nil? if args[:email] self.email = args[:email] end if args[:password] self.password = args[:password] end if args[:remember] self.remember = args[:remember...
Ruby
module PermissionHelper end
Ruby
module AccountHelper end
Ruby
module AuthHelper end
Ruby
class AuthController < ApplicationController filter_parameter_logging :password def login @login = Login.new(params[:login]) @login.email ||= cookies['email'] if @login.return_to.nil? or @login.return_to == "" if params[:return_to] @login.return_to = params[:return_to] else ...
Ruby
class AccountController < ApplicationController before_filter :check_logged_in, :only => [:edit_profile, :edit_email_addresses, :change_password] before_filter :check_signup_allowed, :only => [:signup, :signup_success] filter_parameter_logging :password def activate if logged_in? redirect_to :co...
Ruby
class PermissionController < ApplicationController require_login def admin @pclasses = logged_in_person.administrator_classes @roles = Role.find :all end require_class_permission "change_permissions", :class_param => "klass", :only => [:edit] def edit pclass = nil AeUsers.permissioned_cl...
Ruby
# Include hook code here require 'ae_users' ActiveRecord::Base.send(:include, AeUsers::Acts::Permissioned) ActionController::Base.send(:include, AeUsers::ControllerExtensions::RequirePermission) ActionView::Base.send(:include, AeUsers::HelperFunctions)
Ruby
# AeUsers require 'active_record' module AeUsers begin @@db_name = Rails::Configuration.new.database_configuration["users"]["database"] def self.db_name @@db_name end rescue end @@signup_allowed = true def self.signup_allowed? @@signup_allowed end def self.disallow_signup @@...
Ruby
# Uninstall hook code here
Ruby
class JipeGenerator < Rails::Generator::Base def manifest record do |m| m.directory "public/images/jipe" m.file 'edit-field.png', 'public/images/jipe/edit-field.png' end end end
Ruby
# Install hook code here
Ruby
require 'rake' require 'rake/testtask' require 'rake/rdoctask' desc 'Default: run unit tests.' task :default => :test desc 'Test the jipe plugin.' Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.pattern = 'test/**/*_test.rb' t.verbose = true end desc 'Generate documentation for the jipe plugin.' Rake::RDocT...
Ruby
# desc "Explaining what the task does" # task :jipe do # # Task goes here # end
Ruby
class JipeController < ApplicationController layout nil def jester respond_to do |format| format.js {} end end def jipe respond_to do |format| format.js {} end end end
Ruby
require 'jipe' ActionView::Base.send :include, Jipe
Ruby
# Jipe module Jipe def jipe_id_for(record, field, options = {}) options = { :class => record.class.to_s, :id => nil }.update(options || {}) rclass = options[:class] if options[:id] return options[:id] else return "#{rclass.downcase}_#{record.id}_#{field}" end end def ...
Ruby
#!/usr/bin/env ruby # Simple Ruby XML Socket Server # # This is a a simple socket server implementation in ruby # to communicate with flash clients via Flash XML Sockets. # # The socket code is based on the tutorial # "Sockets programming in Ruby" # by M. Tim Jones (mtj@mtjones.com). # # Date:: Tue, 05 M...
Ruby
#!/usr/bin/env ruby # Simple Ruby XML Socket Server # # This is a a simple socket server implementation in ruby # to communicate with flash clients via Flash XML Sockets. # # The socket code is based on the tutorial # "Sockets programming in Ruby" # by M. Tim Jones (mtj@mtjones.com). # # Date:: Tue, 05 M...
Ruby
#! /usr/bin/ruby #author newdongyuwei@gmail.com if GC.respond_to?(:copy_on_write_friendly=) GC.copy_on_write_friendly = true end $KCODE = 'UTF-8'#解决中文乱码问题 %w(rubygems fileutils sinatra sinatra/base net/http net/https json erubis).each{|lib|require lib} require 'ruby-growl'if RUBY_PLATFORM.downcase.include?("darwin")...
Ruby
$:.unshift '.' ENV['RACK_ENV'] = "production" require 'rubygems' require 'fetion_robot' run Sinatra::Application
Ruby
#! /usr/bin/ruby #author newdongyuwei@gmail.com require 'rubygems' require "sinatra" require 'oauth' require 'oauth/consumer' require 'yaml' require 'logger' class SinaWeiboClient def initialize() @loger = Logger.new(STDOUT) @loger.level = Logger::DEBUG auth = YAML.load(File...
Ruby
#! /usr/bin/ruby #author newdongyuwei@gmail.com if GC.respond_to?(:copy_on_write_friendly=) GC.copy_on_write_friendly = true end $KCODE = 'UTF-8'#解决中文乱码问题 %w(rubygems fileutils sinatra sinatra/base net/http net/https json).each{|lib|require lib} require 'ruby-growl'if RUBY_PLATFORM.downcase.include?("darwin") class...
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' }]) # Mayor.create(:name =>...
Ruby
class CreateTechniqueTemplateFields < ActiveRecord::Migration def self.up create_table :technique_template_fields do |t| t.integer :technique_template_id t.integer :template_field_id t.timestamps end end def self.down drop_table :technique_template_fields end end
Ruby
class CreateFieldCategories < ActiveRecord::Migration def self.up create_table :field_categories do |t| t.string :name t.timestamps end end def self.down drop_table :field_categories end end
Ruby
class CreateTechniqueTemplates < ActiveRecord::Migration def self.up create_table :technique_templates do |t| t.integer :technique_id t.string :name t.timestamps end end def self.down drop_table :technique_templates end end
Ruby
class ChangeColumnTypeToTechniques < ActiveRecord::Migration def self.up change_column :techniques, :technique_type_id, :integer, :default => 1 end def self.down end end
Ruby
class CreateTechniques < ActiveRecord::Migration def self.up create_table :techniques do |t| t.string :filename t.string :location t.integer :technique_type_id t.integer :plugin_id t.boolean :recursively t.string :hash_type t.string :hash_value t.string :content ...
Ruby
class CreatePlugins < ActiveRecord::Migration def self.up create_table :plugins do |t| t.string :name t.string :os t.integer :category_id t.string :author t.timestamps end end def self.down drop_table :plugins end end
Ruby
class RemoveValueFromTemplateFields < ActiveRecord::Migration def self.up remove_column :template_fields, :value end def self.down add_column :template_fields, :value, :string end end
Ruby
class ChangeColumnsToTechniques < ActiveRecord::Migration def self.up change_column :techniques, :recursively, :boolean, :default => false end def self.down end end
Ruby
class CreatePluginTags < ActiveRecord::Migration def self.up create_table :plugin_tags do |t| t.integer :plugin_id t.integer :tag_id t.timestamps end add_index :plugin_tags, [:plugin_id, :tag_id], :unique => true end def self.down remove_index :plugin_tags, :column => [:plugin_...
Ruby
class CreateTechniqueTypes < ActiveRecord::Migration def self.up create_table :technique_types do |t| t.string :name t.timestamps end end def self.down drop_table :technique_types end end
Ruby
class CreateCategories < ActiveRecord::Migration def self.up create_table :categories do |t| t.string :name t.timestamps end end def self.down drop_table :categories end end
Ruby
class CreateTemplateFields < ActiveRecord::Migration def self.up create_table :template_fields do |t| t.string :name t.string :tech_col_name t.string :value t.integer :field_category_id t.timestamps end end def self.down drop_table :template_fields end end
Ruby
class AddColumnFieldValueIdToTechniqueTemplateField < ActiveRecord::Migration def self.up add_column :technique_template_fields, :field_value_id, :integer end def self.down remove_column :technique_template_fields, :field_value_id end end
Ruby
class CreateFieldValues < ActiveRecord::Migration def self.up create_table :field_values do |t| t.string :value t.integer :template_field_id t.timestamps end end def self.down drop_table :field_values end end
Ruby
class CreateTags < ActiveRecord::Migration def self.up create_table :tags do |t| t.string :name t.timestamps end end def self.down drop_table :tags end end
Ruby
class AddDescriptionToPlugins < ActiveRecord::Migration def self.up add_column :plugins, :description, :text end def self.down remove_column :plugins, :description end end
Ruby
class AddMimetypeToTechniques < ActiveRecord::Migration def self.up add_column :techniques, :mimetype, :string end def self.down remove_column :techniques, :mimetype end end
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integrati...
Ruby
source 'http://rubygems.org' gem 'rails', '3.0.5' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3' gem 'jquery-rails', '>= 0.2.6' gem 'mongrel' gem 'mongrel_cluster' # Use unicorn as the web server # gem 'unicorn' # Deploy with Capistrano # gem 'capistrano' # To...
Ruby
xml.instruct! xml.plugins do @plugins.each do |plugin| xml.plugin do xml.name(plugin.name) xml.category(plugin.category.name) xml.location(url_for(plugin)+".xml") xml.last_updated(plugin.updated_at.to_i.to_s + "000") end end end
Ruby
xml.instruct! xml.declare! :DOCTYPE, :plugin, :SYSTEM, '../Plugin.dtd' xml.plugin do xml.metadata do xml.name(@plugin.name) xml.os(@plugin.os) xml.category(@plugin.category.name) xml.author(@plugin.author) xml.description(@plugin.description) #add 000 to make timemiliseconds compatible xm...
Ruby
module TechniquesHelper end
Ruby
module TemplateFieldsHelper end
Ruby
module ApplicationHelper def selected_class(path) (request.path[path])? "selected" : "" end def sortable(column, model) title = column.titleize css_class = column == sort_column(model) ? "current #{sort_direction}" : nil direction = column == sort_column(model) && sort_direction == "asc" ? "desc...
Ruby
module FieldCategoriesHelper end
Ruby
module TechniqueTypesHelper end
Ruby
module PluginsHelper end
Ruby
module CategoriesHelper end
Ruby
module TechniqueTemplatesHelper end
Ruby
module TagsHelper end
Ruby
module HomeHelper end
Ruby
class TemplateField < ActiveRecord::Base belongs_to :field_category validates :field_category_id, :name, :tech_col_name, :presence => true validates :name, :uniqueness => {:case_sensitive => false} has_many :technique_template_fields has_many :technique_templates, :through => :technique_template_fields h...
Ruby
class FieldCategory < ActiveRecord::Base has_many :template_fields validates :name, :uniqueness => true end
Ruby
class Technique < ActiveRecord::Base belongs_to :plugin belongs_to :technique_type validates :technique_type_id, :presence => true end
Ruby
class TechniqueType < ActiveRecord::Base validates :name, :presence => true, :uniqueness => true validates_format_of :name, :with => /\A[a-zA-Z_\-0-9]*\Z/, :message => " format is not correct. Only letters, numbers, '_' and '-'." end
Ruby
class PluginTag < ActiveRecord::Base belongs_to :plugin belongs_to :tag validates :tag_id, :uniqueness => {:scope => :plugin_id} end
Ruby
class TechniqueTemplateField < ActiveRecord::Base belongs_to :technique_template belongs_to :template_field validates :technique_template_id, :uniqueness => {:scope => :template_field_id} end
Ruby
class Tag < ActiveRecord::Base has_many :plugin_tags has_many :plugins, :through => :plugin_tags validates :name, :presence => true, :uniqueness => true validates_format_of :name, :with => /\A[a-zA-Z_\-0-9]*\Z/, :message => " format is not correct. Only letters, numbers, '_' and '-'." end
Ruby
class Category < ActiveRecord::Base has_many :plugins validates :name, :uniqueness => true, :presence => true validates_format_of :name, :with => /\A[a-zA-Z_\-0-9]*\Z/, :message => " format is not correct. Only letters, numbers, '_' and '-'." end
Ruby
class TechniqueTemplate < ActiveRecord::Base belongs_to :technique validates :name, :presence => true has_many :technique_template_fields has_many :template_fields, :through => :technique_template_fields def tech_attr_value(attr) fields = self.template_fields return true if fields.count == 0 f...
Ruby
class FieldValue < ActiveRecord::Base belongs_to :template_field validates :value, :presence => true validates :template_field_id, :presence => true validates :template_field_id, :uniqueness => {:scope => :value} end
Ruby
class Plugin < ActiveRecord::Base has_many :techniques, :dependent => :destroy belongs_to :category has_many :plugin_tags, :dependent => :destroy has_many :tags, :through => :plugin_tags validates :category_id, :presence => true validates :name, :uniqueness => {:scope => :category_id}, :presence => true ...
Ruby
class TemplateFieldsController < ApplicationController # GET /template_fields # GET /template_fields.xml def index @template_fields = TemplateField.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @template_fields } end end # GET /template_fields...
Ruby
class FieldCategoriesController < ApplicationController # GET /field_categories # GET /field_categories.xml def index @field_categories = FieldCategory.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @field_categories } end end # GET /field_catego...
Ruby
class ApplicationController < ActionController::Base protect_from_forgery helper_method :sort_column, :sort_direction, :tech_col_names def sort_column(model) model.column_names.include?(params[:sort]) ? params[:sort] : "id" end def sort_direction %w[asc desc].include?(params[:direction]) ? params[:...
Ruby
class PluginsController < ApplicationController # GET /plugins # GET /plugins.xml def index @plugins = Plugin.order(sort_column(Plugin) + " " + sort_direction) respond_to do |format| format.html # index.html.erb format.xml { render :layaout => false } end end # GET /plugins/1 # ...
Ruby
class CategoriesController < ApplicationController # GET /categories # GET /categories.xml def index @categories = Category.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @categories } end end # GET /categories/1 # GET /categories/1.xml de...
Ruby
class HomeController < ApplicationController def index respond_to do |format| format.html end end def about respond_to do |format| format.html end end end
Ruby
class TechniqueTypesController < ApplicationController # GET /technique_types # GET /technique_types.xml def index @technique_types = TechniqueType.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @technique_types } end end # GET /technique_types/1...
Ruby
class TechniquesController < ApplicationController before_filter(:get_plugin) # GET /techniques # GET /techniques.xml def index @techniques = @plugin.techniques.order(sort_column(Technique) + " " + sort_direction) respond_to do |format| format.html # index.html.erb format.xml { render :...
Ruby
class TagsController < ApplicationController # GET /tags # GET /tags.xml def index @tags = Tag.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @tags } end end # GET /tags/1 # GET /tags/1.xml def show @tag = Tag.find(params[:id]) respo...
Ruby
class TechniqueTemplatesController < ApplicationController # GET /technique_templates # GET /technique_templates.xml def index @technique_templates = TechniqueTemplate.all respond_to do |format| format.html # index.html.erb format.xml { render :xml => @technique_templates } end end ...
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. # 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 to debug a probl...
Ruby
# Be sure to restart your server when you modify this file. # Your secret key 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 dictionary attac...
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. AfaWeb::Application.config.session_store :cookie_store, :key => '_afa_web_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information # (create the session table with "rails...
Ruby
AfaWeb::Application.routes.draw do resources :template_fields resources :field_categories match 'plugins/news' => 'plugins#news' resources :plugins do resources :techniques end resources :technique_templates resources :tags match 'plugins/:plugin_id/techniques/new' => 'techniques#new', :via...
Ruby
require 'rubygems' # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
Ruby
require File.expand_path('../boot', __FILE__) require 'rails/all' # If you have a Gemfile, require the gems listed there, including any gems # you've limited to :test, :development, or :production. Bundler.require(:default, Rails.env) if defined?(Bundler) module AfaWeb class Application < Rails::Application # ...
Ruby