code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
#!/usr/bin/env ruby
#
# You may specify the path to the FastCGI crash log (a log of unhandled
# exceptions which forced the FastCGI instance to exit, great for debugging)
# and the number of requests to process before running garbage collection.
#
# By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log
... | Ruby |
#!/bin/env ruby
require File.dirname(__FILE__) + '/../test_helper'
class LocalizationSettingsTest < Test::Unit::TestCase
include LocalizationSettings
# TODO: shouldn't use production data for tests
# require File.dirname(__FILE__) + '/../test_helper'
TRANSLATION_TABLE = LOCALIZED_STRINGS['localization_s... | Ruby |
class Test::Unit::TestCase
include AuthenticatedUserTestHelper
end
| Ruby |
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
class Test::Unit::TestCase
# Transactional fixtures accelerate your tests by wrapping each test method
# in a transaction that's rolled back on completion. This ensures that the
# test datab... | Ruby |
require 'rubygems'
gem 'Mxx_ru', '>= 1.5.2'
require 'mxx_ru/cpp'
MxxRu::Cpp::composite_target( MxxRu::BUILD_ROOT ) {
global_include_path( "." )
default_runtime_mode( MxxRu::Cpp::RUNTIME_RELEASE )
MxxRu::enable_show_brief
required_prj "const_generator/prj.rb"
} | Ruby |
require 'mxx_ru/cpp'
MxxRu::Cpp::exe_target {
target( "const_generator" )
cpp_source( "cmd_parser.cpp" )
cpp_source( "cfg.cpp" )
cpp_source( "generator.cpp" )
cpp_source( "main.cpp" )
}
| Ruby |
require 'rubygems'
gem 'Mxx_ru', '>= 1.5.2'
require 'mxx_ru/cpp'
MxxRu::Cpp::composite_target( MxxRu::BUILD_ROOT ) {
global_include_path( "." )
default_runtime_mode( MxxRu::Cpp::RUNTIME_RELEASE )
MxxRu::enable_show_brief
required_prj "const_generator/prj.rb"
} | Ruby |
require 'mxx_ru/cpp'
MxxRu::Cpp::exe_target {
target( "const_generator" )
cpp_source( "cmd_parser.cpp" )
cpp_source( "cfg.cpp" )
cpp_source( "generator.cpp" )
cpp_source( "main.cpp" )
}
| Ruby |
#!/usr/local/bin/ruby
Dir.entries(Dir.pwd).select{|f| f =~ /md$/}.each do |file|
file =~ /(.*).md$/
system "pandoc -f markdown -t html \"#{$1}.md\" > \"#{$1}.html\""
end
| Ruby |
#!/usr/local/bin/ruby
system 'pandoc -f markdown -t html '+"\"#{ARGV[0]}.md\" > \"#{ARGV[0]}.html\""
| 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 |
class Random
LETTERS = %w{a b c d e f g h i j k l m n o p q r s t u v w x y z}
def self.words(size = 1)
Random.paragraphs.split(" ")[0,size].join(" ").gsub(/[,;?\.'"\-\n]/, "").downcase
end
def self.phrase(size = 3)
words(size).capitalize
end
def self.question(size = 8)
words(size).capi... | 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 |
module ApplicationHelper
# 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 automatically generated form error messages
# called from la... | 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_en
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 => "Ar... | 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"),
link_to_if_auth("SMS Test Console", new_sms_test_path, "sms_tests#create")]
end
def forms_index_fields
%w[type version name questions published? smsable? last_modified downloads respons... | 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_en
when "published... | Ruby |
require 'seedable'
class QuestionType < ActiveRecord::Base
include Seedable
SMSABLE = %w(integer decimal select_one select_multiple datetime date time tiny_text)
has_many(:questions, :inverse_of => :type)
default_scope(order("long_name"))
def self.generate
seed(:name, :name => "text", :long_na... | Ruby |
class ConditionOrderingError < StandardError
end | Ruby |
class Translation < ActiveRecord::Base
def self.lookup(class_name, id, field, language)
language ||= :en
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'
require 'form_versionable'
class OptionSet < ActiveRecord::Base
include MissionBased
include FormVersionable
has_many(:option_settings, :dependent => :destroy, :autosave => true, :inverse_of => :option_set)
has_many(:options, :through => :option_settings)
has_many(:questions, :inverse... | 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)
# first ensure we have a valid adapter
ensure_adapter
# 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).... | 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'
require 'form_versionable'
class Option < ActiveRecord::Base
include MissionBased
include Translatable
include FormVersionable
has_many(:option_sets, :through => :option_settings)
has_many(:option_settings, :inverse_of => :option, :dependent => :destroy, :auto... | 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 |
require 'form_versionable'
class OptionSetting < ActiveRecord::Base
include FormVersionable
belongs_to(:option, :inverse_of => :option_settings)
belongs_to(:option_set, :inverse_of => :option_settings)
before_destroy(:no_answers_or_choices)
after_create(:notify_form_versioning_policy_of_create)
after_de... | 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 |
# Implements the policy about when a form's version should be upgraded.
# Any form component objects (Option, OptionSet, OptionSetting, Question, Questioning) should call this class before updating.
# This class tells them which, if any, forms will require a version update as a result.
# If the update proceeds, this cl... | 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 |
# models a version number for a Form object. allows forms to have multiple uniquely identifiable versions.
# provides 3 letter code for use with sms encoded forms.
class FormVersion < ActiveRecord::Base
attr_accessible :code, :form_id, :is_current, :sequence
belongs_to :form
after_initialize :generate_code
b... | 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)
has_many(:versions, :class_name... | Ruby |
require 'mission_based'
class Setting < ActiveRecord::Base
include MissionBased
KEYS_TO_COPY = %w(timezone languages intellisms_username intellisms_password isms_hostname isms_username isms_password
outgoing_sms_language incoming_sms_number)
DEFAULTS = {:timezone => "UTC", :languages => "en"}
scope(:by_m... | 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 a string or an array of strings holding phone numbers in ITU E.123... | Ruby |
# decodes a coded sms containing an elmo responses
class Sms::Decoder
# sets up a decoder
# sms - an Sms::Message object
def initialize(msg)
@msg = msg
end
# main method called to do the decoding
# returns an unsaved Response object on success
# raises an Sms::DecodingError on error
def decode
... | Ruby |
module Sms::Adapters
def self.table_name_prefix
'adapters_'
end
end
| Ruby |
# models a generic sms adapter. should be subclassed.
require 'net/http'
class Sms::Adapters::Adapter
# checks if this adapter recognizes an incoming http receive request
def self.recognize_receive_request?(request)
false
end
# delivers a message to one or more recipients
# raises an error if no recip... | Ruby |
class Sms::Adapters::Factory
VALID_ADAPTERS = ["IntelliSms", "Isms"]
def self.name_is_valid?(name)
VALID_ADAPTERS.include?(name)
end
# returns an array of known adapter classes
def self.products
VALID_ADAPTERS.map{|n| adapter = "Sms::Adapters::#{n}Adapter".constantize}
end
# creates an in... | Ruby |
require 'uri'
require 'net/http'
require 'xml'
class Sms::Adapters::IsmsAdapter < Sms::Adapters::Adapter
# checks if this adapter recognizes an incoming http receive request
def self.recognize_receive_request?(request)
# just check the user agent
request.headers["User-Agent"] =~ /MultiModem iSMS/
end
... | Ruby |
require 'open-uri'
require 'uri'
class Sms::Adapters::IntelliSmsAdapter < Sms::Adapters::Adapter
def service_name
@service_name ||= "IntelliSMS"
end
def deliver(message)
# let the superclass do the sanity checks
super
# build the URI the request
uri = build_uri(:deliver, :to => mess... | Ruby |
# a test request to the sms decoder
class Sms::Test
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :from, :body
def initialize(attribs = {})
attribs.each{|k,v| instance_variable_set("@#{k}", v)}
end
def persisted?
false
end
def self.human_attribute_name(a)
... | Ruby |
require 'mission_based'
require 'xml'
class Response < ActiveRecord::Base
include MissionBased
belongs_to(:form, :inverse_of => :responses, :counter_cache => true)
has_many(:answers, :include => :questioning, :order => "questionings.rank",
:autosave => true, :validate => false, :dependent => :destroy, :inve... | Ruby |
class BroadcastAddressing < ActiveRecord::Base
belongs_to(:broadcast, :inverse_of => :broadcast_addressings)
belongs_to(:user, :inverse_of => :broadcast_addressings)
end
| Ruby |
require 'mission_based'
require 'translatable'
require 'form_versionable'
class Question < ActiveRecord::Base
include MissionBased
include Translatable
include FormVersionable
belongs_to(:type, :class_name => "QuestionType", :foreign_key => :question_type_id, :inverse_of => :questions)
belongs_to(:option_s... | Ruby |
# A calculation that just returns the referenced argument with no modification
class Report::IdentityCalculation < Report::Calculation
def name_expr
arg1.name_expr(:tbl_pfx => table_prefix)
end
def value_expr
arg1.value_expr(:tbl_pfx => table_prefix)
end
def sort_expr
arg1.sort_expr(:tbl_pfx =... | Ruby |
class Report::Formatter
extend ActionView::Helpers::TextHelper
def self.format(value, type, context)
case type
when "date"
# cast mysql date to nice string
value.to_s.gsub(" 00:00:00", "")
when "decimal"
"%.2f" % value
when "long_text"
context == :header ? truncate(value, :le... | Ruby |
# models response attributes that are not answers to questions (user, date, etc.)
class Report::AttribField < Report::Field
attr_accessor :name, :name_expr_params, :value_expr_params, :data_type, :groupable
# builds one of each type of AttribField
def self.all
@@ATTRIBS.values.collect{|a| new(a[:name])}... | Ruby |
# models a row/column of headers
class Report::Header
attr_accessor :cells, :title
def initialize(params)
@cells = params[:cells].collect{|c| Report::HeaderCell.new(c)}
@title = params[:title]
end
# looks for a header cell with a matching key and returns its index; returns nil if not found
def f... | Ruby |
require 'mission_based'
class Report::Report < ActiveRecord::Base
include MissionBased
attr_accessible :type, :name, :option_set_id, :display_type, :bar_style, :unreviewed,
:question_labels, :show_question_labels, :percent_type, :unique_rows, :calculations_attributes, :calculations,
:option_set, :filte... | Ruby |
# models the result rows returned by the db from the query
class Report::DbResult
attr_reader :rows
def initialize(rows)
@rows = rows
# debug print rows
#rows.each{|row| pp row.attributes}
end
def has_col?(col)
return !@rows.empty? && @rows.first.attributes.keys.include?(col)
end
#... | Ruby |
class Report::ListReport < Report::Report
has_many(:calculations, :class_name => "Report::Calculation", :foreign_key => "report_report_id", :order => "rank", :dependent => :destroy, :autosave => true)
accepts_nested_attributes_for(:calculations, :allow_destroy => true)
def as_json(options = {})
h = supe... | Ruby |
# models a single cell in a header
class Report::HeaderCell
attr_accessor :name, :sort_value, :key
def initialize(params)
@name = params[:name]
@sort_value = params[:sort_value] || @name
@key = params[:key] || @name
end
def as_json(options = {})
{:name => name, :sort_value => sort_value, :ke... | Ruby |
module Report::Groupable
module ClassMethods
end
def self.included(base)
# ruby idiom to activate class methods
base.extend(ClassMethods)
# add scope
base.class_eval do
attr_accessible :calculations_attributes
has_many(:calculations, :class_name => "Report::Calculation", :foreign... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.