code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
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 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 ConsolidateRiskFields < ActiveRecord::Migration
def up
transaction do
Risk.all.each do |risk|
impact = [risk.financial_impact, risk.reputational_impact, risk.operational_impact]
impact = impact.map(&:presence).compact.join("<br />")
risk.update_attribute(:impact, impact)
... | 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 |
# 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).
ActiveRecord::Base.transaction do
# Categories
# Control categories
control_categories = [
["Access Contr... | 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 |
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 |
# 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 |
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 |
# 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 |
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 |
require 'gdata'
module Gdoc
DOCLIST_SCOPE = 'https://docs.google.com/feeds/'
DOCLIST_DOWNLOD_SCOPE = 'https://docs.googleusercontent.com/'
CONTACTS_SCOPE = 'https://www.google.com/m8/feeds/'
SPREADSHEETS_SCOPE = 'https://spreadsheets.google.com/feeds/'
DEFAULT_FEED = DOCLIST_SCOPE + 'default/private/full'
... | Ruby |
namespace :demo do
desc "Load demo seed data"
task :seed => :environment do |t, args|
demo_seed_file = File.join(Rails.root, 'db', 'demo_seeds', 'demo_seeds.rb')
load(demo_seed_file)
end
task :setup => [:environment, :"db:seed", :"demo:seed"]
task :reset, [ :subdir ] => [:environment, :"db:reset", :s... | Ruby |
namespace :import do
desc "Import various documents into CMS"
task :consolidated, [:filename] => [:environment] do |t, args|
puts "Import consolidated format from #{args[:filename]}"
require 'importer/consolidated'
ActiveRecord::Base.transaction do
importer = Importer::Consolidated.new
imp... | Ruby |
namespace :export do
desc "Export help data to YAML file"
task :help, [:filename] => [:environment] do |t, args|
puts "Exporting help data to #{args[:filename]}"
File.open(args[:filename], 'w') do |file|
YAML::dump(Help.all, file)
end
end
end | Ruby |
# Importer contains classes and methods to import data from various formats
# into the system.
module Importer
class ImportError < StandardError
end
end
| Ruby |
require 'open-uri'
require 'csv'
module Importer
# Importer for specialized CSV document format
#
# Expected columns are:
# 0-4: Company control index, unused, title, description-part-1, description-part-2
# 5-6: Directive 1: description, slug(s)
# 7-8: Directive 2: description, slug(s)
# 9-10... | Ruby |
require 'open-uri'
require 'csv'
module Importer
class Regulation
def initialize
end
def run_file(filename)
open(filename, 'r:utf-8') do |file|
run_csv(file.read)
end
end
def run_csv(csv_string)
directive = nil
headers_seen = false
CSV.parse(csv_string) ... | Ruby |
# Copyright (C) 2009 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 |
# Monkey patch Prawn to fix 'incompatible character encodings' error in JRuby:
# https://github.com/prawnpdf/prawn/issues/283
require 'prawn'
module Prawn
module Core
def self.utf8_to_utf16(str)
str
end
end
end
| Ruby |
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run CmsRails::Application
| 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 |
#!/usr/bin/ruby
require File.expand_path('../../rules/mosync_exe.rb')
work = PipeExeWork.new
work.instance_eval do
@SOURCES = ["."]
@LIBRARIES = ["mautil"]
@NAME = "HelloNativeUI"
end
work.invoke
| Ruby |
#!/usr/bin/ruby
require File.expand_path('../../rules/mosync_exe.rb')
work = PipeExeWork.new
work.instance_eval do
@SOURCES = ["."]
@LIBRARIES = ["mautil"]
@NAME = "HelloNativeUI"
end
work.invoke
| 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 |
class String
def is_number?
true if Float(self) rescue false
end
def normalize
mb_chars.normalize(:kd).gsub(/[^\x00-\x7F]/n,'')
end
def ucwords
self.split(" ").map{|w| w.capitalize}.join(" ")
end
end | Ruby |
module ActionView
module Helpers
class FormBuilder
include ActionView::Helpers::TagHelper
attr_accessor :mode
alias :old_text_field :text_field
alias :old_text_area :text_area
alias :old_select :select
alias :old_datetime_select :datetime_select
alias :old_date_sel... | Ruby |
module ActiveSupport
class TimeZone
def mysql_name
self.class::MAPPING[name]
end
end
end | Ruby |
class ActionView::Base
def json_escape(s)
result = s.to_s.gsub('/', '\/')
s.html_safe? ? result.html_safe : result
end
alias j json_escape
end | Ruby |
class Niller; def method_missing(*m); nil; end; end
def nn(x); x.nil? ? Niller.new : x; end | Ruby |
module ActiveSupport #:nodoc:
class SafeBuffer < String
def to_param
to_str
end
end
end | Ruby |
class Array
# Matches elements of a to elements of b and passes each pair to a block.
# If an element of a has no match in b or vice versa, nil is passed.
# Assumes no duplicates in either array.
def compare_by_element(arr, hashfunc = nil, &block)
hashfunc ||= Proc.new{|x| x}
# create hashes from a... | 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
Mime::Type.register 'text/x-vcard', :vcf | 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.
#ELMO::Application.config.session_store :cookie_store, :key => '_command_center_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 |
ELMO::Application.configure do
# Settings specified here will take precedence over those in config/application.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
... | Ruby |
ELMO::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 webserve... | Ruby |
ELMO::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... | Ruby |
# Load the rails application
require File.expand_path('../application', __FILE__)
# Initialize the rails application
ELMO::Application.initialize!
# Standard date-time format
Time::DATE_FORMATS[:std_datetime] = "%Y-%m-%d %H:%M"
Time::DATE_FORMATS[:std_date] = "%Y-%m-%d"
Time::DATE_FORMATS[:std_time] = "%H:%M"
Time::D... | 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)
if defined?(Bundler)
# If you precompile assets before depl... | Ruby |
ELMO::Application.routes.draw do
# redirects for ODK
match("/missions/:mission_compact_name/formList" => 'forms#index', :format => :xml)
match("/m/:mission_compact_name/formList" => 'forms#index', :format => :xml)
match("/missions/:mission_compact_name/submission" => 'responses#create', :format => :xml)
matc... | Ruby |
require 'language_list'
module ApplicationHelper
include LanguageList
# renders the flash message and any form errors for the given activerecord object
def flash_and_form_errors(object = nil)
render("layouts/flash", :flash => flash, :object => object)
end
# applies any customizations to automatical... | Ruby |
module PermissionsHelper
end
| Ruby |
module ResponsesHelper
def responses_index_fields
%w[form_name submitter submission_time age reviewed? actions]
end
def format_responses_field(resp, field)
case field
when "submission_time" then resp.created_at && resp.created_at.to_s(:std_datetime) || ""
when "age" then resp.created_at && time... | Ruby |
module SearchesHelper
def search_examples(search)
content_tag("div", :id => "search_examples") do
("Examples: " + search.examples.join(" ")).html_safe
end
end
end | Ruby |
module UsersHelper
def users_index_fields
%w[name login email main_phone alternate_phone latest_mission actions]
end
def format_users_field(user, field)
case field
when "email" then mail_to(user.email)
when "main_phone" then user.phone
when "alternate_phone" then user.phone2
when "latest_m... | Ruby |
module FormTypesHelper
def form_types_index_links(form_types)
[link_to_if_auth("Add new Form Type", new_form_type_path, "form_types#create")]
end
def form_types_index_fields
%w[name actions]
end
def format_form_types_field(form_type, field)
case field
when "actions"
action_links(form_typ... | Ruby |
module OptionSetsHelper
def option_sets_index_links(option_sets)
[link_to_if_auth("Add new option set", new_option_set_path, "option_sets#create")]
end
def option_sets_index_fields
%w[name options questions published? actions]
end
def format_option_sets_field(option_set, field)
case field
when... | Ruby |
module QuestioningsHelper
def format_questionings_field(qing, field)
case field
when "rank" then controller.action_name == "show" ? qing.rank : text_field_tag("rank[#{qing.id}]", qing.rank, :class => "rank_box")
when "code", "title", "type" then format_questions_field(qing.question, field)
when "condi... | Ruby |
module SessionsHelper
end
| Ruby |
module UserBatchesHelper
end
| Ruby |
module QuestionsHelper
def format_questions_field(q, field)
case field
when "title" then q.name_eng
when "type" then q.type.long_name
when "published?" then q.published? ? "Yes" : "No"
when "actions"
exclude = q.published? ? [:edit, :destroy] : []
action_links(q, :destroy_warning => "A... | Ruby |
module MissionsHelper
def missions_index_links(missions)
[link_to_if_auth("Add new Mission", new_mission_path, "missions#create")]
end
def missions_index_fields
%w[name created actions]
end
def format_missions_field(mission, field)
case field
when "created"
mission.created_at.to_s(:std_d... | Ruby |
module FormsHelper
def forms_index_links(forms)
[link_to_if_auth("Create Form", new_form_path, "forms#create")]
end
def forms_index_fields
%w[type name questions published? last_modified downloads responses actions]
end
def format_forms_field(form, field)
case field
when "type" then fo... | Ruby |
module BroadcastsHelper
def broadcasts_index_links(broadcasts)
[link_to_if_auth("Send Broadcast", new_broadcast_path, "broadcasts#create")]
end
def broadcasts_index_fields
%w[to medium sent_at errors? message actions]
end
def format_broadcasts_field(broadcast, field)
case field
when "t... | Ruby |
module Report::ReportsHelper
require 'csv'
def report_reports_index_links(reports)
links = [link_to_if_auth("Create new report", new_report_report_path, "report_reports#create")]
end
def report_reports_index_fields
%w[title last_viewed views actions]
end
def format_report_reports_field(repo... | Ruby |
module OptionsHelper
def options_index_links(options)
[link_to_if_auth("Add new option", new_option_path, "options#create")]
end
def options_index_fields
%w[name value published? actions]
end
def format_options_field(option, field)
case field
when "name" then option.name_eng
when "publishe... | Ruby |
require 'seedable'
class QuestionType < ActiveRecord::Base
include Seedable
has_many(:questions, :inverse_of => :type)
default_scope(order("long_name"))
def self.generate
seed(:name, :name => "text", :long_name => "Short Text", :odk_name => "string", :odk_tag => "input")
seed(:name, :name => "l... | Ruby |
class ConditionOrderingError < StandardError
end | Ruby |
class Translation < ActiveRecord::Base
def self.lookup(class_name, id, field, language)
language ||= :eng
t = find_by_class_name_and_obj_id_and_fld_and_language(class_name, id, field, language)
t ? t.str : nil
end
end
| Ruby |
module Sms
def self.table_name_prefix
'sms_'
end
end
| Ruby |
require 'mission_based'
class OptionSet < ActiveRecord::Base
include MissionBased
has_many(:option_settings, :dependent => :destroy, :autosave => true, :inverse_of => :option_set)
has_many(:options, :through => :option_settings)
has_many(:questions, :inverse_of => :option_set)
has_many(:questionings, :throug... | Ruby |
class Marker < ActiveRecord::Base
def self.generate(color)
# ensure there is a map-markers directory inside tmp
tmp_path = File.join(Rails.root, "tmp/markers")
Dir.mkdir(tmp_path) unless File.exists?(tmp_path)
# build path to image we're going to generate
file_path = File.join(tmp_path, "#... | Ruby |
class InvalidAssociationDeletionError < StandardError
end | Ruby |
class Smser
def self.deliver(recips, which_phone, msg)
# get numbers
numbers = []
numbers += recips.collect{|u| u.phone} if %w(main_only both).include?(which_phone)
numbers += recips.collect{|u| u.phone2} if %w(alternate_only both).include?(which_phone)
numbers.compact!
# build th... | Ruby |
# TOM need more comments in this class. especially on load_sms_code function. explain what this class is modelling.
class SmsCode < ActiveRecord::Base
attr_accessible :code, :option_id, :form_id, :question_number, :questioning_id
belongs_to :questioning
belongs_to :option
validates(:questioning_id, :pres... | Ruby |
require 'mission_based'
class Broadcast < ActiveRecord::Base
include MissionBased
has_many(:broadcast_addressings, :inverse_of => :broadcast)
has_many(:recipients, :through => :broadcast_addressings, :source => :user)
validates(:recipients, :presence => true)
validates(:medium, :presence => true)
valida... | Ruby |
class Permission
GENERAL = {
"missions#*" => {:group => :admin},
"users#create" => {:min_level => 3},
"user_batches#*" => {:min_level => 3},
"users#*" => {:min_level => 3},
"forms#create" => {:min_level => 3},
"forms#update" => {:min_level => 3},
"forms#destroy" => {:min_level => 3},
... | Ruby |
module Report
def self.table_name_prefix
'report_'
end
end
| Ruby |
require 'mission_based'
require 'translatable'
class Option < ActiveRecord::Base
include MissionBased
include Translatable
has_many(:option_sets, :through => :option_settings)
has_many(:option_settings, :inverse_of => :option)
has_many(:translations, :class_name => "Translation", :foreign_key => :obj_id,
... | Ruby |
class Mission < ActiveRecord::Base
has_many(:responses, :inverse_of => :mission)
has_many(:forms, :inverse_of => :mission)
has_many(:report_reports, :class_name => "Report::Report", :inverse_of => :mission)
has_many(:broadcasts, :inverse_of => :mission)
has_many(:assignments, :inverse_of => :mission)
has_ma... | Ruby |
class Assignment < ActiveRecord::Base
belongs_to(:mission)
belongs_to(:role, :inverse_of => :assignments)
belongs_to(:user, :inverse_of => :assignments)
validates(:mission, :presence => true)
validates(:role, :presence => true)
default_scope(includes(:mission, :role))
scope(:sorted_recent_first, order("... | Ruby |
class OptionSetting < ActiveRecord::Base
belongs_to(:option, :inverse_of => :option_settings)
belongs_to(:option_set, :inverse_of => :option_settings)
before_destroy(:no_answers_or_choices)
# temp var used in the option_set form
attr_writer :included
def included
# default to true
defined?(... | Ruby |
# TOM this and all other sms-related model classes should be in the sms namespace. please read up on Rails/Ruby namespaces.
class SmsResponse < ActiveRecord::Base
attr_accessible :message, :response_id
belongs_to :response
validates(:message, :presence => true)
validates(:response_id, :presence => true)
... | Ruby |
class PermissionError < StandardError
end | Ruby |
require 'seedable'
require 'mission_based'
class FormType < ActiveRecord::Base
include MissionBased
has_many(:forms, :inverse_of => :type)
before_destroy(:check_assoc)
validates(:name, :presence => :true, :length => {:maximum => 16})
default_scope(order("name"))
# creates and returns a defaul... | Ruby |
require 'seedable'
class User < ActiveRecord::Base
include Seedable
attr_writer(:reset_password_method)
has_many(:responses, :inverse_of => :user)
has_many(:broadcast_addressings, :inverse_of => :user)
has_many(:assignments, :autosave => true, :dependent => :destroy, :validate => true, :inverse_of => :use... | Ruby |
module Search
def self.table_name_prefix
'search_'
end
end
| Ruby |
class Choice < ActiveRecord::Base
belongs_to(:answer, :inverse_of => :choices)
belongs_to(:option, :inverse_of => :choices)
def option_name; option.name; end
def checked; @checked; end
def checked=(v); @checked = v; end
end
| Ruby |
class Search::ParseError < StandardError
end | Ruby |
class Search::Lexer
attr_reader :tokens
def initialize(str)
@str = str.strip
@tokens = []
end
# performs a lexical analysis on @str
def lex
# while there are characters left
while @str.size > 0
token = nil
match = nil
chop = nil
# try each token type
Search:... | Ruby |
class Search::Parser
# GRAMMAR
# query ::= "(" query ")" | term bin-bool-op query | term query | term
# term ::= qual-term | unqual-term
# unqual-term ::= target
# qual-term ::= CHUNK comp-op target-set
# bin-bool-op ::= "and" | "or"
# comp-op ::= "=" | ":" | "<" | ">" | "<=" | ">=" | "!=" | "<>"
# t... | Ruby |
class Search::Search < ActiveRecord::Base
# finds or creates a search based on the given class_name and str
def self.find_or_create(params)
find_or_create_by_class_name_and_str(params[:class_name], params[:str])
end
# parses the search string
def parse
@parser = Search::Parser.new(self)
@parser.p... | Ruby |
class Search::LexToken
attr_reader(:kind, :content, :fragment)
# array of lex token kinds, in the order by which they should be searched
EQUAL = {:name => :equal, :pattern => "="}
KINDS = [
{:name => :colon, :pattern => ":", :sql => "="},
EQUAL,
{:name => :gt, :pattern => ">"},
{:name => :lt,... | Ruby |
class Search::Qualifier
# required params - :label, :col
def initialize(params)
@params = params
# by default, qualifier is not default-searched
@params[:default] ||= false
# by default, the associations are nil
@params[:assoc] ||= nil
# by default, search has to match exac... | Ruby |
class Search::Token
EQUAL_TOKEN = Search::LexToken.new(Search::LexToken::EQUAL, "=")
def initialize(search, kind, children)
@search = search
@kind = kind
@children = children.is_a?(Array) ? children : [children]
end
def to_s_indented(level = 0)
(" " * level) + "#{@kind}\n" + @children.colle... | Ruby |
class UserSession < Authlogic::Session::Base
# only session related configuration goes here, see documentation for sub modules of Authlogic::Session
# other config goes in acts_as block
logout_on_timeout(true)
def to_key
new_record? ? nil : [ self.send(self.class.primary_key) ]
end
end | Ruby |
require 'mission_based'
class Form < ActiveRecord::Base
include MissionBased
has_many(:questions, :through => :questionings)
has_many(:questionings, :order => "rank", :autosave => true, :dependent => :destroy, :inverse_of => :form)
has_many(:responses, :inverse_of => :form)
belongs_to(:type, :class_name => "... | Ruby |
require 'mission_based'
require 'language_list'
class Setting < ActiveRecord::Base
include MissionBased
include LanguageList
KEYS = %w(timezone languages outgoing_sms_username outgoing_sms_password outgoing_sms_extra outgoing_sms_language)
DEFAULTS = {:timezone => "UTC", :languages => "eng"}
scope(:by_missi... | Ruby |
require 'seedable'
class Role < ActiveRecord::Base
include Seedable
has_many(:assignments, :inverse_of => :role)
default_scope(order("level DESC"))
def self.generate
seed(:level, :name => "Coordinator", :level => "3")
seed(:level, :name => "Staffer", :level => "2")
seed(:level, :name => "Obse... | Ruby |
class Answer < ActiveRecord::Base
include ActionView::Helpers::NumberHelper
# a flag set by javascript on the client side indicating whether the answer is relevant based on any conditions
attr_writer(:relevant)
belongs_to(:questioning, :inverse_of => :answers)
belongs_to(:option, :inverse_of => :answers)
... | Ruby |
# models an sms message, either incoming or outgoing
# gets created by adapters when messages are incoming
# and gets created by controllers and sent to adapters for sending when messages are outgoing
#
# direction :incoming or :outgoing
# to an array of strings holding phone numbers in ITU E.123 format (e.g... | Ruby |
module Sms::Adapters
def self.table_name_prefix
'adapters_'
end
end
| Ruby |
# models a generic sms adapter. should be subclassed.
class Sms::Adapters::Adapter
# delivers a message to one or more recipients
# raises an error if no recipients, wrong direction, or message empty
# should also raise an error if the provider returns an error code
# returns true if all goes well
#
# m... | Ruby |
class Sms::Adapters::Factory
VALID_ADAPTERS = ["IntelliSms", "ISMS"]
def self.name_is_valid?(name)
VALID_ADAPTERS.include?(name)
end
# creates an instance of the specified adapter
def create(name)
raise ArgumentError.new("Invalid adapter name") unless self.class.name_is_valid?(name)
Sms::Ada... | Ruby |
class Sms::Adapters::ISMSAdapter < Sms::Adapters::Adapter
require 'open-uri'
require 'uri'
def initialize
# TOM don't think you need these. an adapter doesn't model a send/receive session. it is just a conduit for messages to flow through.
@incoming_messages = []
@outgoing_messages = []
end
... | Ruby |
class Sms::Adapters::IntelliSmsAdapter < Sms::Adapters::Adapter
require 'open-uri'
require 'uri'
def service_name
@service_name ||= "IntelliSMS"
end
def deliver(message, options = {})
super
# build the URI the request
uri = build_uri("sendmsg", "to=#{message.to.join(',')}&text=#{URI... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.