code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
class RemoveNameFromAccounts < ActiveRecord::Migration
def up
Account.all.each do |a|
person = Person.find_by_email(a.email)
if person
person.name = "#{a.name} #{a.surname}"
person.save!(:validate => false)
else
a.person =
Person.create({:email => a.email,
... | Ruby |
class AddRequiredToOptions < ActiveRecord::Migration
def change
add_column :options, :required, :boolean
end
end
| Ruby |
class CreateTransactions < ActiveRecord::Migration
def change
create_table :transactions do |t|
t.string :title, :null => false
t.text :description
t.references :system
t.references :modified_by
t.timestamps
end
end
end
| Ruby |
class AddPersonCompany < ActiveRecord::Migration
def up
add_column :people, :company, :string
end
def down
remove_column :people, :company
end
end
| Ruby |
class AddResponseDueAtToRequest < ActiveRecord::Migration
def change
add_column :requests, :response_due_at, :date
end
end
| Ruby |
class AddProgramForEachDirective < ActiveRecord::Migration
def up
transaction do
Directive.all.each do |directive|
if directive.programs.count == 0
program = Program.create!(
:title => directive.title
)
program_directive = ProgramDirective.create!(
... | Ruby |
class AddDefaultOptionsAndCategories < ActiveRecord::Migration
def up
Option.reset_column_information
Category.reset_column_information
Categorization.reset_column_information
options = {
:control_type => [],
:control_kind => ["Reactive", "Directive", "Detective", "Preventative"],
:... | Ruby |
class CreateRelationshipTypes < ActiveRecord::Migration
def change
create_table :relationship_types, :id => false do |t|
t.string :relationship_type
t.string :description
t.string :forward_short_description
t.string :backward_short_description
t.timestamps
end
add_index... | Ruby |
class FixRiskyAttributeRelationships < ActiveRecord::Migration
RELATIONSHIP_TYPE_NAME_CHANGES = [
[ :risky_attribute_is_an_attribute_of_org_group, :org_group_has_risky_attribute ],
[ :risky_attribute_is_an_attribute_of_product, :product_has_risky_attribute ],
[ :risky_attribute_is_an_attribute_of_loca... | Ruby |
class CreateRequests < ActiveRecord::Migration
def change
create_table :requests do |t|
t.references :pbc_list
t.references :type
t.references :control
t.string :pbc_control_code
t.text :pbc_control_desc
t.text :request
t.text :test
t.text :notes
t.string :com... | Ruby |
class AddRelationshipTypeSymmetric < ActiveRecord::Migration
def change
add_column :relationship_types, :symmetric, :boolean, :default => false
end
end
| Ruby |
class ChangeHelpsContentType < ActiveRecord::Migration
def up
change_column :helps, :content, :text, :limit => nil
end
def down
change_column :helps, :content, :string
end
end
| Ruby |
class RemoveInvalidRiskyAttributes < ActiveRecord::Migration
def up
RiskyAttribute.where(:type_string => nil).each do |ra|
ra.destroy
end
RiskyAttribute.where(:type_string => "").each do |ra|
ra.destroy
end
RiskyAttribute.where(:type_string => "Org Group").each do |ra|
ra.updat... | Ruby |
class RemoveParentheticalsFromStatusValues < ActiveRecord::Migration
REQUEST_STATUS_MIGRATIONS = [
["Responded (by Compliance)", "Responded"],
["Amended/Updated Request (by Auditor)", "Amended/Updated Request"],
["Accepted (by Auditor)", "Accepted"]
]
def up
REQUEST_STATUS_MIGRATIONS.each do |old... | Ruby |
class RenameProgramsToDirectives < ActiveRecord::Migration
def up
rename_table :programs, :directives
rename_column :controls, :program_id, :directive_id
rename_column :sections, :program_id, :directive_id
rename_column :cycles, :program_id, :directive_id
end
def down
rename_table :directive... | Ruby |
class UpdateRelationshipTypeIds < ActiveRecord::Migration
RELATIONSHIP_TYPE_NAME_CHANGES = [
[:program_is_relevant_to_org_group, :program_applies_to_org_group],
[:program_is_relevant_to_product, :program_applies_to_product],
[:program_is_relevant_to_facility, :program_applies_to_facility],
... | Ruby |
class CreateVersions < ActiveRecord::Migration
def self.up
create_table :versions do |t|
t.string :item_type, :null => false
t.integer :item_id, :null => false
t.string :event, :null => false
t.string :whodunnit
t.text :object
t.datetime :created_at
end
... | Ruby |
class CreateObjectPeople < ActiveRecord::Migration
class BizProcessPerson < ActiveRecord::Base
end
class SystemPerson < ActiveRecord::Base
end
def change
create_table :object_people do |t|
t.string :role
t.text :notes
t.references :person, :null => false
t.references :personable, ... | Ruby |
class CreateOptions < ActiveRecord::Migration
def change
create_table :options do |t|
t.string :role, :null => false
t.string :title, :null => false
t.text :description
t.references :modified_by
t.timestamps
end
end
end
| Ruby |
class FixRiskyAttributeSlugs < ActiveRecord::Migration
def up
RiskyAttribute.all.each do |ra|
if ra.slug.match(/^RISKYATTRIBUTE/)
ra.slug = ra.slug.sub(/^RISKYATTRIBUTE/, 'RA')
ra.save!
end
end
end
def down
end
end
| Ruby |
class AddToProgram < ActiveRecord::Migration
def up
change_table :programs do |t|
t.integer :frequency_type, :default => 1
t.integer :frequency, :default => 1
end
end
def down
change_table :programs do |t|
t.remove :frequency, :frequency_type
end
end
end
| Ruby |
class DeprecateUnusedAccountRoles < ActiveRecord::Migration
class Account < ActiveRecord::Base
end
def up
Account.where(:role => :admin).each do |account|
account.role = :superuser
account.save
end
Account.where(:role => :admin).each do |account|
account.role = :superuser
acc... | Ruby |
class CreatePopulationSamples < ActiveRecord::Migration
def change
create_table :population_samples do |t|
t.references :response
t.references :population_document
t.integer :population
t.references :sample_worksheet_document
t.integer :samples
t.references :sample_evidence_doc... | Ruby |
class CreatePbcLists < ActiveRecord::Migration
def change
create_table :pbc_lists do |t|
t.references :audit_cycle
t.string :title
t.string :audit_firm
t.string :audit_lead
t.text :description
t.datetime :list_import_date
t.string :status
t.text :notes
t.refer... | Ruby |
class UpdateBaseRelationshipTypes < ActiveRecord::Migration
def up
RelationshipType.reset_column_information
new_relationship_types = [
# Relationship types are in alphabetical order!
{
:relationship_type => 'location_is_dependent_on_location',
:description => "Locations can be de... | Ruby |
class CreateProducts < ActiveRecord::Migration
def up
create_table :products do |t|
t.string :slug
t.string :title
t.text :description
t.string :url
t.string :version
t.references :type
t.references :modified_by
t.timestamps
end
end
def down
end
end
| Ruby |
class AddEndAtToCycles < ActiveRecord::Migration
def change
add_column :cycles, :end_at, :date
end
end
| Ruby |
class CreateLocations < ActiveRecord::Migration
def change
create_table :locations do |t|
t.string :slug
t.string :title
t.text :description
t.string :url
t.references :modified_by
t.datetime :start_date
t.datetime :stop_date
t.timestamps
end
end
end
| Ruby |
class AddBaseMarketRelationships < ActiveRecord::Migration
def up
new_relationship_types = [
# Relationship types are in alphabetical order!
{
:relationship_type => 'market_contains_a_market',
:description => "Markets can have submarkets.",
:forward_phrase =>"containing",
... | Ruby |
class AddTitleToHelps < ActiveRecord::Migration
def change
add_column :helps, :title, :string
end
end
| Ruby |
class CreateRiskyAttributes < ActiveRecord::Migration
def change
create_table :risky_attributes do |t|
t.string :slug
t.string :title
t.text :description
t.string :url
t.references :modified_by
t.datetime :start_date
t.datetime :stop_date
t.timestamps
end
... | Ruby |
class AddKindToDirectives < ActiveRecord::Migration
def change
add_column :directives, :kind, :string
end
end
| Ruby |
class CreateProgramDirectives < ActiveRecord::Migration
def change
create_table :program_directives do |t|
t.references :program, :null => false
t.references :directive, :null => false
t.references :modified_by
t.timestamps
end
end
end
| Ruby |
class ChangeDirectiveKindToString < ActiveRecord::Migration
def up
transaction do
Directive.all.each do |directive|
option = Option.where(:role => 'directive_kind', :id => directive.kind_id).first
kind = option ? option.title : "Regulation"
kind = "Org Group Policy" if kind == "Opera... | Ruby |
class CreateMarkets < ActiveRecord::Migration
def change
create_table :markets do |t|
t.string :slug
t.string :title
t.text :description
t.string :url
t.references :modified_by
t.datetime :start_date
t.datetime :stop_date
t.timestamps
end
end
end
| Ruby |
class MoveProgramHelps < ActiveRecord::Migration
HELP_SLUG_CHANGES = {
:program_cycles => :directive_cycles,
:program_info => :directive_info,
:programs_list => :directives_list,
:program_controls => :directive_controls,
:program_more_info => :directive_more_info,
:program => :directive
}
... | Ruby |
class ReorgControls < ActiveRecord::Migration
class Program < ActiveRecord::Base
end
class Section < ActiveRecord::Base
belongs_to :parent, :class_name => "Section"
end
def up
raise "do not know how to migrate ControlControls" unless ControlControl.count == 0
rename_table :control_control_object... | Ruby |
class CreateOrgGroups < ActiveRecord::Migration
def change
create_table :org_groups do |t|
t.string :slug
t.string :title
t.text :description
t.string :url
t.references :modified_by
t.datetime :start_date
t.datetime :stop_date
t.timestamps
end
end
end
| Ruby |
class CreateRisks < ActiveRecord::Migration
def change
create_table :risks do |t|
t.string :slug
t.string :title
t.text :description
t.string :url
t.references :modified_by
t.datetime :start_date
t.datetime :stop_date
t.timestamps
end
end
end
| Ruby |
class AddControlColumns < ActiveRecord::Migration
def up
change_table :controls do |t|
t.string :version
t.datetime :start_date
t.datetime :stop_date
t.string :url
t.text :documentation_description
t.references :verify_frequency
t.remove :frequency
t.remove :frequen... | Ruby |
class AddOptionReferences < ActiveRecord::Migration
def up
change_table :controls do |t|
t.references :type
t.references :kind
t.references :means
end
change_table :systems do |t|
t.references :type
end
end
def down
change_table :controls do |t|
t.remove :type_i... | Ruby |
class CreateDataAssets < ActiveRecord::Migration
def change
create_table :data_assets do |t|
t.string :slug
t.string :title
t.text :description
t.string :url
t.references :modified_by
t.datetime :start_date
t.datetime :stop_date
t.timestamps
end
end
end
| Ruby |
class ChangeCompanyControlsToPolicy < ActiveRecord::Migration
def up
transaction do
Directive.where(:kind => "Company Controls").each do |directive|
directive.kind = "Company Controls Policy"
directive.save!
end
end
end
def down
end
end
| Ruby |
class ChangeRelationshipsFromLocationToFacility < ActiveRecord::Migration
def up
Relationship.where(:source_type => 'Location').all.each do |rel|
rel.update_attribute(:source_type, 'Facility')
end
Relationship.where(:destination_type => 'Location').all.each do |rel|
rel.update_attribute(:desti... | Ruby |
class ChangePolymorphicTypesFromLocationToFacility < ActiveRecord::Migration
def up
ObjectPerson.where(:personable_type => 'Location').all.each do |o|
o.update_attribute(:personable_type, 'Facility')
end
ObjectDocument.where(:documentable_type => 'Location').all.each do |o|
o.update_attribute(... | Ruby |
class AddRequiredToCategories < ActiveRecord::Migration
def change
add_column :categories, :required, :boolean
end
end
| Ruby |
class RemoveDeprecatedDatabaseObjects < ActiveRecord::Migration
def up
# BizProcess is now a subset/type of System
# - data migration happened in 20120723223448_copy_biz_processes_to_systems.rb
drop_table :biz_process_controls
drop_table :biz_process_documents
drop_table :biz_process_people
dr... | Ruby |
class CreateHelps < ActiveRecord::Migration
def change
create_table :helps do |t|
t.string :slug
t.string :content
t.timestamps
end
end
end
| Ruby |
class RegulationToProgram < ActiveRecord::Migration
def up
rename_table :regulations, :programs
rename_table :control_objectives, :sections
change_table :sections do |t|
t.integer :parent_id
t.index :parent_id
end
end
end
| Ruby |
class AddControlAssessmentIdToRequests < ActiveRecord::Migration
def change
add_column :requests, :control_assessment_id, :integer
add_index :requests, :control_assessment_id
end
end
| Ruby |
class CreateObjectDocuments < ActiveRecord::Migration
class BizProcessDocument < ActiveRecord::Base
end
class DocumentSystem < ActiveRecord::Base
end
class DocumentSystemControl < ActiveRecord::Base
end
def change
create_table :object_documents do |t|
t.string :role
t.text :notes
t.... | Ruby |
class AddSystemsIsBizProcess < ActiveRecord::Migration
def up
change_table :systems do |t|
t.boolean :is_biz_process, :default => false
end
end
def down
change_table :systems do |t|
t.remove :is_biz_process
end
end
end
| Ruby |
SIZE=20
ACCOUNTS = {
:root => :superuser,
:user => :user,
:owner1 => :user,
:owner2 => :user
}
ActiveRecord::Base.transaction do
# Accounts
ACCOUNTS.each do |name, role|
Account.
where(:email => "#{name}@t.com").
first_or_create!(
{:password => name, :password_confirmation => name... | 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 |
# Uncomment or put the following in Gemfile.local
# source 'http://rubygems.org'
if File.exist? 'Gemfile.local'
instance_eval(Bundler.read_file('Gemfile.local'), 'Gemfile.local', 1)
end
RAILS_VERSION = '= 3.2.13'
# Fulltext search
gem 'thinking-sphinx', '~> 2.0.14'
gem 'remotipart'
#gem 'gdata-ruby-util', '1.1.2... | Ruby |
#!/usr/bin/env ruby
# 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 |
# Test some of the authorization basics for resource controllers.
#
# Usage:
#
# require 'authorized_controller'
#
# before :each do
# @model = <model> # The model that you're testing authorization for, e.g. Account
# @object = <obj> # An instance you want to test read and update actions against
# @index_objs = ... | Ruby |
module UserSpecHelper
# Set the rspec environment so that we can call stub_model
def set_rspec(rspec)
@_rspec = rspec
end
def current_user(stubs = {})
return @current_user if @current_user
role = (stubs.delete(:role) || :user).to_s
if respond_to?(:stub_model)
@current_user = stub_model(... | Ruby |
require 'spork'
require 'simplecov'
require 'capybara/rspec'
if ENV['COVERAGE']
SimpleCov.start do
add_group 'Models', 'app/models'
add_group 'Helpers', 'app/helpers'
add_group 'Controllers', 'app/controllers'
add_group 'Admin C', 'app/controllers/admin'
add_filter 'config'
add_fil... | Ruby |
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do
factory :control_assessment do
pbc_list { |c| c.association(:pbc_list) }
control { |c| c.association(:control) }
control_version "MyString"
internal_tod false
internal_toe false
external_tod false
e... | Ruby |
FactoryGirl.define do
sequence(:slug) do |n|
# FIXME: Do I need to generate slugs according to a convention, or
# do they only need to be unique?
# FIXME: Slugs will become invalid if parenting is ever changed
# anywhere in the ancestor heirarchy.
# FIXME: Slug validation makes factories for secti... | Ruby |
module BaseObjects
def create_base_objects
@prog = FactoryGirl.create(:program, :title => 'Program')
@opt_reg = FactoryGirl.create(:option, :title => 'Regulation', :role => 'directive_kind')
@opt_com = FactoryGirl.create(:option, :title => 'Company Policy', :role => 'directive_kind')
@creg = FactoryGi... | Ruby |
module DatedModel
include ActiveSupport::Concern
def self.included(model)
model.validate :stop_date_later_than_start_date
end
def stop_date_later_than_start_date
if self.has_attribute? :stop_date
if self.start_date.present? && self.stop_date.present?
errors.add(:stop_date, 'Must be l... | Ruby |
module DefaultRelationshipTypes
RELATIONSHIP_TYPES = {
:data_asset_has_process => {
:source_type => "DataAsset",
:target_type => "Process",
:forward_phrase => "has",
:reverse_phrase => "is a process for",
:forward_description => "This data asset relies upon the following processes."... | Ruby |
# A lot of this is cribbed from how declarative_authorization handles
# model-based authorization.
module Authorization
# Controller-independent method for retrieving the current user.
# Needed for model security where the current controller is not available.
# Primarily for use by the console and tests, where w... | Ruby |
module CommonModel
def self.included(model)
model.send(:include, AuthoredModel)
model.has_many :object_people, :as => :personable, :dependent => :destroy
model.has_many :people, :through => :object_people
model.has_many :object_documents, :as => :documentable, :dependent => :destroy
model.has_many... | Ruby |
module BusinessObjectModel
@business_object_models = nil
def self.included(model)
model.class_eval do
end
model.extend(ClassMethods)
if model.ancestors.include?(ActiveRecord::Base)
@business_object_models = [] if @business_object_models.nil?
@business_object_models.push(model)
end
... | Ruby |
module AuthoredModel
# Typecast form parameters into the right primitive to work around a DataMapper dirty-detection bug.
#
# If we don't do this, the persistence layer thinks all non-strings params are modifications
# where in fact we might just have changed false => 0, which is a no-op. This is important
#... | Ruby |
module ControlState
VALUES = [ :green, :yellow, :red, :unknown ]
STATE_WEIGHT = { :green => 10, :unknown => 15, :yellow => 20, :red => 30 }
STATE_IS_GOOD = { :green => true, :unknown => true }
end
| Ruby |
# Sanitize attributes before validation.
#
# Usage in model:
#
# sanitize_attributes :description, :documentation_description
#
module SanitizableAttributes
# based on defaults from ActionView::Base.sanitized_allowed_tags with table tags added
SANITIZED_ALLOWED_TAGS = %w(strong em b i p code pre tt samp kbd var s... | Ruby |
module StateModel
def state
index = read_attribute(:state) || self.class.columns_hash['state'].default
ControlState::VALUES[index]
end
def state=(value)
write_attribute(:state, ControlState::VALUES.index(value))
end
def good_state?
ControlState::STATE_IS_GOOD[state]
end
def self.include... | Ruby |
module RoleModel
ROLES = [:tech, :business]
def role
index = read_attribute(:role) || self.class.columns_hash['role'].default
ROLES[index]
end
def role=(value)
write_attribute(:role, ROLES.index(value))
end
def self.included(model)
model.validates :role, :presence => true
end
end
| Ruby |
# Provides utility functions for doing authorization on CRUD and other operations
# to the model, given a standard way of getting the current user and
# a list of users and roles for an object.
# Note: requires the model to implement the authorizing_objects method
# FIXME: Properly deal with anonymous users - or are w... | Ruby |
module SearchableModel
def self.included(model)
model.extend(ClassMethods)
end
def self.sphinx_servers
@@sphinx_servers ||= begin
servers = CMS_CONFIG['FULLTEXT']
(servers or '').split(',').map do |host_port|
{ :host => host_port.split(':')[0],
:port => host_port.split(':')[... | Ruby |
# RelatedModel mixin
#
# Many mixins that exist for managing relationships, and especially the relationship
# traversal functions that are used in the context of authorization.
#
# Also creates some useful scoping functions that allow you to
# create scopes for relationships with very little code. Example usage:
#
# In... | Ruby |
module SluggedModel
def compact_slug
return slug unless parent
cslug = slug
cslug[parent.slug] = '' if cslug[parent.slug] # Substring replacement of parent.slug with ''
return cslug
end
def self.included(model)
model.extend(ClassMethods)
model.class_eval do
validates :slug, :presen... | Ruby |
module BusinessObjectsHelper
def related_objects(instance)
if instance.is_a?(System) && instance.is_biz_process?
instance.class.related_models("Process")
else
instance.class.related_models
end
end
def arranged_related_objects(instance)
end
end
| Ruby |
module WelcomeHelper
end
| Ruby |
module ApplicationHelper
# Shorthand humanized text for admin pages
def pat(sym)
sym.to_s.humanize
end
# Default time display (localize at some point)
def display_time(time)
time.strftime("%Y-%m-%d %H:%M") rescue "-"
end
#:nocov:
# FIXME: No obvious way to sanely test this.
# Use instead of ... | Ruby |
module FormHelper
# Simple helper for repetitive form error spans
def error_messages_inline(f, field_name)
capture_haml do
haml_tag :span, :class => 'help-inline' do
f.object.errors[field_name].each do |error|
haml_tag :span do
haml_concat "#{error}"
end
en... | Ruby |
module CyclesHelper
def generate_default_title_for_cycle(program=nil)
default_title = (program.nil? ? "" : program.title + " ") + "Audit"
count = Cycle.where(Cycle.arel_table[:title].matches("%#{default_title}%")).count
default_title += count > 0 ? " " + (count + 1).to_s : ""
return "#{Date.today.ye... | Ruby |
module ImportHelper
def trim_array(a)
while !a.empty? && a.last.blank?
a.pop
end
a
end
def validate_import_slug(object, object_name, expected_slug)
raise ImportException.new("#{object_name} Code column does not exist") unless object["slug"]
raise ImportException.new("#{object_name} Code... | Ruby |
module ManyHelper
# Many to many AJAX page - show form.
#
# Example:
# if request.put?
# post_many2many(:left_class => Control,
# :right_class => DocumentDescriptor,
# :right_relation => :evidence_descriptors,
# :right_ids => :evid... | Ruby |
require 'prawn_monkeypatch'
module EvidenceHelper
include ApplicationHelper
# Capture evidence on Google Docs
#
# Convert the evidence document to PDF and watermark it with:
#
# * Acceptance date
# * Who accepted the evidence
# * Which system was the evidence attached to
#
# The PDF is then upload... | Ruby |
module AuthorizationHelper
# Roles
def access_control_roles
[:user, :admin, :risk, :admin_risk, :no_access]
end
def allowed_objs(objects, ability)
objects
#Authorization::allowed_objects(ability, @current_user, objects)
end
def check_model_risk_authorization(models)
if current_user.can_man... | Ruby |
# Helper methods defined here can be accessed in any controller or view in the application
module GdataHelper
# Transform a list of docs to a map by title
def gdocs_by_title(docs)
by_title = {}
docs.values.each do |doc|
by_title[doc.full_title] = doc
end
by_title
end
# Check if this is a... | Ruby |
module SlugfilterHelper
def walk_slug_tree(tree, options=nil, &block)
options ||= {}
depth = options[:depth]
capture_haml do
walk_slug_tree_children_helper(tree, nil, true, depth, options, &block)
end
end
def walk_slug_tree_children_helper(tree, step=nil, odd=true, depth=nil, options=nil, ... | Ruby |
module MappingHelper
end
| Ruby |
module DashboardHelper
def init_quick_find
@quick_find ||= {}
@quick_find[:controls] ||= Control.all
@quick_find[:systems] ||= System.where(:is_biz_process => false).all
@quick_find[:biz_processes] ||= System.where(:is_biz_process => true).all
end
end
| Ruby |
module DirectivesHelper
# Set up a directive and relevant stats for display
def directive_stats(directive)
stats = {}
stats[:sections_count] = Section.where(:directive_id => directive.id).count()
stats[:sections_done_count] = Section.joins(:controls).where(:directive_id => directive.id).count(:distinct ... | Ruby |
# Helper methods defined here can be accessed in any controller or view in the application
module DocumentHelper
# Transform a document URL for display purposes.
#
# Currently just transforms a Google Docs url to the editable document
# version.
def transform_document_url(url)
gdoc_url = Gdoc.edit_url_fr... | Ruby |
module ProgramsDashHelper
end
| Ruby |
module ControlsHelper
def control_params
control_params = params[:control] || {}
if control_params[:directive_id]
# TODO: Validate the user has access to add controls to the directive
control_params[:directive] = Directive.where(:id => control_params.delete(:directive_id)).first
end
%w(typ... | Ruby |
class UrlValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
valid = begin
URI.parse(value).kind_of?(URI::HTTP)
rescue URI::InvalidURIError
false
end
unless valid
record.errors[attribute] << (options[:message] || "is an invalid URL")
end
end
e... | Ruby |
class EmailValidator < ActiveModel::EachValidator
EMAIL_RE = /([^@\s]+)(?:@((?:[-a-z0-9]+\.)+[a-z]{2,}))/i
EMAILS_RE = /\A\s*#{EMAIL_RE}(?:\s*[, ]\s*#{EMAIL_RE})*\Z/i
def validate_each(record, attribute, value)
unless value =~ /^#{EMAIL_RE}$/
record.errors[attribute] << (options[:message] || "must be a... | Ruby |
class MultiEmailValidator < ActiveModel::EachValidator
EMAIL_RE = /([^@\s]+)(?:@((?:[-a-z0-9]+\.)+[a-z]{2,}))/i
EMAILS_RE = /\A\s*#{EMAIL_RE}(?:\s*[, ]\s*#{EMAIL_RE})*\Z/i
def validate_each(record, attribute, value)
unless value =~ EMAILS_RE #/\A([^@\s]+)(?:@((?:[-a-z0-9]+\.)+[a-z]{2,}))?\z/i
record.er... | Ruby |
require 'authorization'
# class to manage user accounts on CMS. Note that this class is different
# than the Person class, because not all people responsible for compliance will
# have an account.
class Account < ActiveRecord::Base
include AuthoredModel
attr_accessor :password, :password_confirmation
attr_acc... | Ruby |
# System to Control many to many
class SystemControl < ActiveRecord::Base
include CommonModel
include StateModel
attr_accessible :control, :system, :cycle
belongs_to :control
belongs_to :system
belongs_to :cycle
is_versioned_ext
def self.by_system_control(system_id, control_id, cycle)
sc = Syste... | Ruby |
require 'slugged_model'
# A company / regulation control
#
class Control < ActiveRecord::Base
include CommonModel
include SluggedModel
include SearchableModel
include AuthorizedModel
include RelatedModel
include SanitizableAttributes
include DatedModel
CATEGORY_TYPE_ID = 100
CATEGORY_ASSERTION_TYPE_... | Ruby |
class SectionSweeper < ActionController::Caching::Sweeper
observe Section, ControlSection
# TODO: monitor implementing_controls
def after_create(section)
expire_cache_for(section)
end
def after_update(section)
expire_cache_for(section)
end
def after_destroy(section)
expire_cache_for(sectio... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.