code
stringlengths
1
1.73M
language
stringclasses
1 value
class App < ActiveRecord::Base # People has_many :stakeholders has_many :operators, :through => :stakeholders, :class_name => 'User' has_many :release_packs has_many :softwares # Machine has_many :machines has_many :operation_templates has_many :operations def to_s ...
Ruby
class ReleasePack < ActiveRecord::Base belongs_to :app def vnumber version =~ /(\d+)(\.\d+)?$/ $1 end state_machine :state, :initial => :init do event :use do transition :init => :using end event :off do transition :using => :used end event :reuse do transition :used => :using e...
Ruby
class Software < ActiveRecord::Base belongs_to :app end
Ruby
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, :validatable # Setup a...
Ruby
class Role < ActiveRecord::Base has_many :stakeholders Admin = "Admin" PE = "PE" APPOPS = "APPOPS" end
Ruby
class Room < ActiveRecord::Base has_many :machines, :dependent => :nullify def to_s send :name end end
Ruby
class Stakeholder < ActiveRecord::Base belongs_to :user belongs_to :app belongs_to :role validates_uniqueness_of :app_id, :scope => [:user_id, :role_id], :message => "您已经将当前应用分配给了指定的用户与角色" end
Ruby
class DirectiveTemplate < ActiveRecord::Base GLOBAL_ID = 0 belongs_to :directive_group end
Ruby
class AppsController < BaseController def index respond_with current_user.apps.uniq end def show respond_with current_user.apps.find(params[:id]) end def rooms respond_with(current_user.apps.find(params[:id]).machines.select([:room_id]).uniq.collect do |machine| Room.find(mach...
Ruby
class HomeController < BaseController def index render :layout => 'application' end def welcome respond_with current_user end end
Ruby
class ApiController < ApplicationController def commands room = Room.where(:name => params[:room_name]).first if room.nil? render :text => "" else # 查询参数包括机房的 name 和 id,是考虑到 room 表的name字段发生变动, # 此时应该谨慎处理,不下发相应的命令 if params[:reload] oper_query = Directive.with_state(...
Ruby
class MachinesController < BaseController def index machines = current_app.machines.paginate(:per_page => params[:limit].to_i, :page => params[:page].to_i) total = current_app.machines.count respond_with :totalCount => total, :machines => machines end def command_state directives = cu...
Ruby
class DirectiveGroupsController < ApplicationController def index render :text => DirectiveGroup.all.to_json(:include => [:directive_templates]) end end
Ruby
class RoomsController < ApplicationController end
Ruby
class BaseController < ApplicationController before_filter :authenticate_user! respond_to :json def current_app current_user.apps.where(:id => params[:app_id]).first||App.new end end
Ruby
class Admin::AppsController < Admin::BaseController def update_resource(object, attributes) attributes[:machines] = Machine.where(:id => attributes[:machines]) attributes[:directive_groups] = DirectiveGroup.where(:id => attributes[:directive_groups]) object.update_attributes(attributes) end ...
Ruby
class Admin::HomeController < Admin::BaseController def index if !current_user.is_admin? redirect_to root_path end end end
Ruby
class Admin::DirectiveTemplatesController < Admin::BaseController def index directive_templates = DirectiveTemplate.paginate(:per_page => params[:limit].to_i, :page => params[:page].to_i) total = directive_templates.count respond_with :totalCount => total, :directive_templates => directive_templates ...
Ruby
class Admin::RolesController < Admin::BaseController def index() roles = Role.paginate(:per_page => params[:limit].to_i, :page => params[:page].to_i) total = roles.count respond_with :totalCount => total, :roles => roles end def model Role end def group :role end def destroy room ...
Ruby
class Admin::MachinesController < Admin::BaseController def index machines = Machine.paginate(:per_page => params[:limit].to_i, :page => params[:page].to_i) total = Machine.all.count machines = machines.collect do |m| m.serializable_hash.delete_if {|k,v| k == 'password'} end respond_w...
Ruby
class Admin::DirectiveGroupsController < Admin::BaseController def index() directive_groups = DirectiveGroup.paginate(:per_page => params[:limit].to_i, :page => params[:page].to_i) total = directive_groups.count respond_with :totalCount => total, :directive_groups => directive_groups end def...
Ruby
class Admin::RoomsController < Admin::BaseController def index() rooms = Room.paginate(:per_page => params[:limit].to_i, :page => params[:page].to_i) total = rooms.count respond_with :totalCount => total, :rooms => rooms end def model() Room end def group() :room end ...
Ruby
class Admin::BaseController < ApplicationController before_filter :authenticate_user! respond_to :json layout 'admin' def index respond_with model.all end def show respond_with model.find(params[:id]) end def create respond_with model.create(params[group]) end def ...
Ruby
class Admin::UsersController < Admin::BaseController def index users = User.paginate(:per_page => params[:per_page], :page => params[:page]) users = users.inject([]) do |user_infos, u| user_infos << u.attributes end total = users.count respond_with :totalCount => total, :users => user...
Ruby
class OperationsController < BaseController def index respond_with current_app.operations.without_state(:done).collect { |cs| cs.attributes.update( "state" => cs.human_state_name, "children" => cs.machines.uniq.collect { |m| m.attributes.update( "id" =>...
Ruby
class DirectivesController < BaseController def ack render :text => Directive.find(params[:id]).ack end end
Ruby
class ApplicationController < ActionController::Base protect_from_forgery layout false end
Ruby
class OperationTemplatesController < BaseController def index app_id = params[:app_id] roles = Stakeholder.where(:app_id => app_id, :user_id => current_user.id).inject([]) do |roles, stakeholder| roles << Role.find(stakeholder.role_id).name end role = roles.index(Role::Admin) ? Role::Admin...
Ruby
class SoftwaresController < BaseController def index respond_with current_app.softwares end def create software = current_app.softwares.create(params[:software]) render :text => software.to_json end def destroy respond_with current_app.softwares.find(params[:id]).delete end ...
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.expand_path('../config/application', __FILE__) require 'rake' include Rake::DSL if defined?(Rake::DSL) Apposs::Application.load_tasks
Ruby
#!/usr/bin/env jruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. APP_PATH = File.expand_path('../../config/application', __FILE__) require File.expand_path('../../config/boot', __FILE__) require 'rails/commands'
Ruby
#!/usr/bin/env ruby vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first if vendored_cucumber_bin load File.expand_path(vendored_cucumber_bin) else require 'rubygems' unless ENV['NO_RUBYGEMS'] require 'cucumber' load Cucumber::BINARY end
Ruby
#!/usr/bin/env ruby vendored_cucumber_bin = Dir["#{File.dirname(__FILE__)}/../vendor/{gems,plugins}/cucumber*/bin/cucumber"].first if vendored_cucumber_bin load File.expand_path(vendored_cucumber_bin) else require 'rubygems' unless ENV['NO_RUBYGEMS'] require 'cucumber' load Cucumber::BINARY end
Ruby
#!/usr/bin/env jruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. APP_PATH = File.expand_path('../../config/application', __FILE__) require File.expand_path('../../config/boot', __FILE__) require 'rails/commands'
Ruby
source 'http://rubygems.org' gem 'rails', '3.0.6' gem 'rake' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' # Use unicorn as the web server # gem 'unicorn' # Deploy with Capistrano # gem 'capistrano' # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9...
Ruby
class CreateDirectiveTemplates < ActiveRecord::Migration def self.up create_table :directive_templates do |t| t.string :name t.string :alias t.string :arg1 t.string :arg2 t.string :arg3 t.string :arg4 t.string :arg5 t.integer :directive_group_id t...
Ruby
class CreateRooms < ActiveRecord::Migration def self.up create_table :rooms do |t| t.string :name t.timestamps end end def self.down drop_table :rooms end end
Ruby
class CreateOperations < ActiveRecord::Migration def self.up create_table :operations do |t| t.integer :operation_template_id t.integer :operator_id t.integer :app_id t.string :name t.string :state t.timestamps end end def self.down drop_table :opera...
Ruby
class CreateOperationTemplates < ActiveRecord::Migration def self.up create_table :operation_templates do |t| t.string :name t.integer :app_id t.string :expression t.timestamps end end def self.down drop_table :operation_templates end end
Ruby
class CreateDirectives < ActiveRecord::Migration def self.up create_table :directives do |t| t.integer :operation_id t.integer :machine_id t.integer :directive_template_id t.boolean :next_when_fail t.string :state t.boolean :isok, :default => false t.text :respon...
Ruby
class CreateRoles < ActiveRecord::Migration def self.up create_table :roles do |t| t.string :name t.timestamps end end def self.down drop_table :roles end end
Ruby
class CreateStakeholders < ActiveRecord::Migration def self.up create_table :stakeholders do |t| t.integer :role_id t.integer :user_id t.integer :app_id t.timestamps end end def self.down drop_table :stakeholders end end
Ruby
class CreateReleasePacks < ActiveRecord::Migration def self.up create_table :release_packs do |t| t.string :version t.string :branch t.integer :app_id t.string :state t.timestamps end end def self.down drop_table :release_packs end end
Ruby
class CreateDirectiveGroups < ActiveRecord::Migration def self.up create_table :directive_groups do |t| t.string :name t.timestamps end end def self.down drop_table :directive_groups end end
Ruby
class AddMachineState < ActiveRecord::Migration def self.up add_column :machines, :state, :string end def self.down remove_column :machines, :state end end
Ruby
class DeviseCreateUsers < ActiveRecord::Migration def self.up create_table(:users) do |t| t.database_authenticatable :null => false t.recoverable t.rememberable t.trackable # t.encryptable # t.confirmable # t.lockable :lock_strategy => :failed_attempts, :unlock...
Ruby
class CreateMachines < ActiveRecord::Migration def self.up create_table :machines do |t| t.string :name t.string :host t.integer :room_id t.integer :app_id t.integer :port t.string :adapter, :default => :ssh t.string :user t.string :password ...
Ruby
class CreateSoftwares < ActiveRecord::Migration def self.up create_table :softwares do |t| t.string :name t.integer :app_id t.timestamps end end def self.down drop_table :softwares end end
Ruby
class CreateApps < ActiveRecord::Migration def self.up create_table :apps do |t| t.string :name t.timestamps end end def self.down drop_table :apps 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' }]) # Mayor.create(:name ...
Ruby
# This file is copied to spec/ when you run 'rails generate rspec:install' ENV["RAILS_ENV"] ||= 'test' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' # Requires supporting ruby files with custom matchers and macros, etc, # in spec/support/ and its subdirectories. Dir[Rails....
Ruby
RSpec.configure do |config| config.include Devise::TestHelpers, :type => :controller end
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Apposs::Application
Ruby
# include the utils rb file which has extra functionality for the ext theme dir = File.dirname(__FILE__) require File.join(dir, 'lib', 'utils.rb') # register ext4 as a compass framework Compass::Frameworks.register 'ext4', dir
Ruby
# $ext_path: This should be the path of where the ExtJS SDK is installed # Generally this will be in a lib/extjs folder in your applications root # <root>/lib/extjs $ext_path = "../../lib/extjs" # sass_path: the directory your Sass files are in. THIS file should also be in the Sass folder # Generally this will b...
Ruby
module ExtJS4 module SassExtensions module Functions module Utils def parsebox(list, n) assert_type n, :Number if !n.int? raise ArgumentError.new("List index #{n} must be an integer") elsif n.to_i < 1 raise ArgumentError.new("List index ...
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 in...
Ruby
# $ext_path: This should be the path of where the ExtJS SDK is installed # Generally this will be in a lib/extjs folder in your applications root # <root>/lib/extjs $ext_path = "../../" # sass_path: the directory your Sass files are in. THIS file should also be in the Sass folder # Generally this will be in a resource...
Ruby
# include the utils rb file which has extra functionality for the ext theme dir = File.dirname(__FILE__) require File.join(dir, 'lib', 'utils.rb') # register ext4 as a compass framework Compass::Frameworks.register 'ext4', dir
Ruby
# $ext_path: This should be the path of the Ext JS SDK relative to this file $ext_path = "../../extjs" # sass_path: the directory your Sass files are in. THIS file should also be in the Sass folder # Generally this will be in a resources/sass folder # <root>/resources/sass sass_path = File.dirname(__FILE__) # css_pat...
Ruby
# Compass configurations sass_path = File.dirname(__FILE__) css_path = File.join(sass_path, "..", "css") # Require any additional compass plugins here. images_dir = File.join(sass_path, "..", "img") output_style = :expanded environment = :production
Ruby
module ExtJS4 module SassExtensions module Functions module Utils def parsebox(list, n) assert_type n, :Number if !n.int? raise ArgumentError.new("List index #{n} must be an integer") elsif n.to_i < 1 raise ArgumentError.new("List index #{n} must...
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
source :gemcutter gem 'sinatra', :require => 'sinatra/base' gem 'thin', '~> 1.3' gem 'pg' gem 'data_mapper', '~> 1.2' gem 'dm-postgres-adapter' gem 'google-api-client', '>= 0.4.3' group :development do gem 'dm-sqlite-adapter', '~> 1.2' gem 'do_sqlite3', '~> 0.10' end
Ruby
require 'formula' # Documentation: https://github.com/mxcl/homebrew/wiki/Formula-Cookbook # PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST! class Apporo < Formula homepage 'http://code.google.com/p/apporo/' url 'http://apporo.googlecode.com/svn/trunk' sha1 '' version '0.0.1-01' hea...
Ruby
require 'formula' # Documentation: https://github.com/mxcl/homebrew/wiki/Formula-Cookbook # PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST! class Apporo < Formula homepage 'http://code.google.com/p/apporo/' url 'http://apporo.googlecode.com/svn/trunk' sha1 '' version '0.0.1-01' hea...
Ruby
pod 'JSONModel' platform :ios, '7.0' pod "AFNetworking", "~> 2.0"
Ruby
before 'index.html.erb.erb' do @name = 'World' end
Ruby
source :rubygems gem 'stasis' gem 'ponyhost'
Ruby
source :rubygems gem 'stasis' gem 'ponyhost'
Ruby
# Require any additional compass plugins here. # Set this to the root of your project when deployed: http_path = "/" css_dir = "theme/css" sass_dir = "theme/scss" images_dir = "images" javascripts_dir = "js" # You can select your preferred output style here (can be overridden via the command line): output_style = :co...
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
# Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. Devise.setup do |config| # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use yo...
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 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. # # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do wrap_parameters ...
Ruby
# Be sure to restart your server when you modify this file. BudgetGroup::Application.config.session_store :cookie_store, key: '_budget_group_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...
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
BudgetGroup::Application.configure do # Settings specified here will take precedence over those in config/application.rb # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.ac...
Ruby
BudgetGroup::Application.configure do # Settings specified here will take precedence over those in config/application.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 w...
Ruby
BudgetGroup::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 t...
Ruby
# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application BudgetGroup::Application.initialize!
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 defined?(Bundler) # If you precompile assets before deploying to production, use this line Bundler.require(*Rails.groups(:assets => %w(development test))) # If you want your assets lazily compiled in production, use this line # Bundler.requi...
Ruby
BudgetGroup::Application.routes.draw do resources :notifications get "stubpayments/index" devise_for :users resources :account_budget_rules resources :budgets resources :payments resources :budget_exceptions resources :categories resources :stubpayments do collection do post 'payment...
Ruby
module ApplicationHelper end
Ruby
module BudgetExceptionsHelper end
Ruby
module CategoriesHelper end
Ruby
module AccountBudgetRulesHelper end
Ruby
module AccountBudgetRuleHelper end
Ruby
module PaymentsHelper end
Ruby
module BudgetsHelper end
Ruby
class Category < ActiveRecord::Base end
Ruby
class AccountBudgetRule < ActiveRecord::Base end
Ruby
class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :confirmable, # :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable # Setup accessible (or pr...
Ruby
class Payment < ActiveRecord::Base belongs_to :category end
Ruby
class BudgetException < ActiveRecord::Base belongs_to :category end
Ruby
class Budget < ActiveRecord::Base belongs_to :category end
Ruby
class BudgetsController < ApplicationController # GET /budgets # GET /budgets.json def index @budgets = Budget.all respond_to do |format| format.html # index.html.erb format.json { render json: @budgets } end end # GET /budgets/1 # GET /budgets/1.json def show @budget = Budge...
Ruby
class PaymentsController < ApplicationController # GET /payments # GET /payments.json def index if params.has_key? ("account_id") and params.has_key? ("category_id") @payments = Payment.find_all_by_account_id_and_category_id(params[:account_id], params[:category_id] ) render json: @payments else...
Ruby