_id
stringlengths 2
6
| title
stringlengths 9
130
| partition
stringclasses 3
values | text
stringlengths 30
4.3k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q25800
|
Ws2812.UnicornHAT.[]=
|
validation
|
def []=(x, y, color)
check_coords(x, y)
@pixels[x][y] = color
|
ruby
|
{
"resource": ""
}
|
q25801
|
Ws2812.UnicornHAT.set
|
validation
|
def set(x, y, r, g, b)
check_coords(x, y)
|
ruby
|
{
"resource": ""
}
|
q25802
|
Ws2812.UnicornHAT.rotation=
|
validation
|
def rotation=(val)
permissible = [0, 90, 180, 270]
fail ArgumentError, "invalid rotation, permissible: #{permissible.join(', ')}" unless
|
ruby
|
{
"resource": ""
}
|
q25803
|
Ws2812.UnicornHAT.check_coords
|
validation
|
def check_coords(x, y)
if 0 <= x && x < 8 && 0 <= y && y < 8
true
else
fail
|
ruby
|
{
"resource": ""
}
|
q25804
|
Pupa.Model.validate!
|
validation
|
def validate!
if self.class.json_schema
self.class.validator.instance_variable_set('@errors', [])
self.class.validator.instance_variable_set('@data',
|
ruby
|
{
"resource": ""
}
|
q25805
|
Pupa.Model.to_h
|
validation
|
def to_h(persist: false)
{}.tap do |hash|
(persist ? properties - foreign_objects : properties).each do |property|
value = self[property]
|
ruby
|
{
"resource": ""
}
|
q25806
|
Tmx.Map.export_to_file
|
validation
|
def export_to_file(filename, options={})
content_string = export_to_string(default_options(filename).merge(:filename
|
ruby
|
{
"resource": ""
}
|
q25807
|
Tmx.Map.export_to_string
|
validation
|
def export_to_string(options = {})
hash = self.to_h
# Need to add back all non-tilelayers to hash["layers"]
image_layers = hash.delete(:image_layers)
object_groups = hash.delete(:object_groups)
hash[:layers] += image_layers
hash[:layers] += object_groups
hash[:layers].sort_by! { |l| l[:name] }
hash.delete(:contents)
object_groups.each do |object_layer|
|
ruby
|
{
"resource": ""
}
|
q25808
|
Pupa.Processor.dump_scraped_objects
|
validation
|
def dump_scraped_objects(task_name)
counts = Hash.new(0)
@store.pipelined do
send(task_name).each do |object|
counts[object._type] += 1
|
ruby
|
{
"resource": ""
}
|
q25809
|
Pupa.Processor.import
|
validation
|
def import
@report[:import] = {}
objects = deduplicate(load_scraped_objects)
object_id_to_database_id = {}
if use_dependency_graph?(objects)
dependency_graph = build_dependency_graph(objects)
# Replace object IDs with database IDs in foreign keys and save objects.
dependency_graph.tsort.each do |id|
object = objects[id]
resolve_foreign_keys(object, object_id_to_database_id)
# The dependency graph strategy only works if there are no foreign objects.
database_id = import_object(object)
object_id_to_database_id[id] = database_id
object_id_to_database_id[database_id] = database_id
end
else
size = objects.size
# Should be O(n²). If there are foreign objects, we do not know all the
# edges in the graph, and therefore cannot build a dependency graph or
# derive any evaluation order.
#
# An exception is raised if a foreign object matches multiple documents
# in the database. However, if a matching object is not yet saved, this
|
ruby
|
{
"resource": ""
}
|
q25810
|
Pupa.Processor.dump_scraped_object
|
validation
|
def dump_scraped_object(object)
type = object.class.to_s.demodulize.underscore
name = "#{type}_#{object._id.gsub(File::SEPARATOR, '_')}.json"
if @store.write_unless_exists(name, object.to_h)
info {"save #{type} #{object.to_s} as
|
ruby
|
{
"resource": ""
}
|
q25811
|
Pupa.Processor.load_scraped_objects
|
validation
|
def load_scraped_objects
{}.tap do |objects|
@store.read_multi(@store.entries).each do |properties|
|
ruby
|
{
"resource": ""
}
|
q25812
|
Pupa.Processor.load_scraped_object
|
validation
|
def load_scraped_object(properties)
type = properties['_type'] || properties[:_type]
if type
type.camelize.constantize.new(properties)
else
|
ruby
|
{
"resource": ""
}
|
q25813
|
Pupa.Processor.deduplicate
|
validation
|
def deduplicate(objects)
losers_to_winners = build_losers_to_winners_map(objects)
# Remove all losers.
losers_to_winners.each_key do |key|
objects.delete(key)
end
# Swap the IDs of losers for the IDs of winners.
objects.each do |id,object|
object.foreign_keys.each do |property|
|
ruby
|
{
"resource": ""
}
|
q25814
|
Pupa.Processor.build_losers_to_winners_map
|
validation
|
def build_losers_to_winners_map(objects)
inverse = {}
objects.each do |id,object|
(inverse[object.to_h.except(:_id)] ||= []) << id
end
{}.tap do |map|
inverse.values.each do |ids|
|
ruby
|
{
"resource": ""
}
|
q25815
|
Pupa.Processor.use_dependency_graph?
|
validation
|
def use_dependency_graph?(objects)
objects.each do |id,object|
object.foreign_objects.each do |property|
if object[property].present?
|
ruby
|
{
"resource": ""
}
|
q25816
|
Pupa.Processor.build_dependency_graph
|
validation
|
def build_dependency_graph(objects)
DependencyGraph.new.tap do |graph|
objects.each do |id,object|
graph[id] = [] # no duplicate IDs
object.foreign_keys.each do |property|
value = object[property]
|
ruby
|
{
"resource": ""
}
|
q25817
|
Pupa.Processor.resolve_foreign_keys
|
validation
|
def resolve_foreign_keys(object, map)
object.foreign_keys.each do |property|
value = object[property]
if value
if map.key?(value)
object[property] = map[value]
else
|
ruby
|
{
"resource": ""
}
|
q25818
|
Pupa.Processor.resolve_foreign_objects
|
validation
|
def resolve_foreign_objects(object, map)
object.foreign_objects.each do |property|
value = object[property]
if value.present?
foreign_object = ForeignObject.new(value)
resolve_foreign_keys(foreign_object, map)
document = connection.find(foreign_object.to_h)
if document
|
ruby
|
{
"resource": ""
}
|
q25819
|
Pupa.Runner.run
|
validation
|
def run(args, overrides = {})
rest = opts.parse!(args)
@options = OpenStruct.new(options.to_h.merge(overrides))
if options.actions.empty?
options.actions = %w(scrape import)
end
if options.tasks.empty?
options.tasks = @processor_class.tasks
end
processor = @processor_class.new(options.output_dir,
pipelined: options.pipelined,
cache_dir: options.cache_dir,
expires_in: options.expires_in,
value_max_bytes: options.value_max_bytes,
memcached_username: options.memcached_username,
memcached_password: options.memcached_password,
database_url: options.database_url,
validate: options.validate,
level: options.level,
faraday_options: options.faraday_options,
options: Hash[*rest])
options.actions.each do |action|
unless action == 'scrape' || processor.respond_to?(action)
abort %(`#{action}` is not a #{opts.program_name} action. See `#{opts.program_name} --help` for a list of available actions.)
end
end
if %w(DEBUG INFO).include?(options.level)
puts "processor: #{@processor_class}"
puts "actions: #{options.actions.join(', ')}"
puts "tasks: #{options.tasks.join(', ')}"
end
if options.level == 'DEBUG'
%w(output_dir pipelined cache_dir expires_in value_max_bytes memcached_username memcached_password database_url validate level).each do |option|
puts "#{option}: #{options[option]}"
end
unless rest.empty?
|
ruby
|
{
"resource": ""
}
|
q25820
|
Pupa.VoteEvent.add_group_result
|
validation
|
def add_group_result(result, group: nil)
data = {result: result}
if group
data[:group] = group
|
ruby
|
{
"resource": ""
}
|
q25821
|
Pupa.VoteEvent.add_count
|
validation
|
def add_count(option, value, group: nil)
data = {option: option, value: value}
if group
data[:group] = group
|
ruby
|
{
"resource": ""
}
|
q25822
|
Danger.DangerJenkins.print_artifacts
|
validation
|
def print_artifacts
artifacts = build.artifacts
return if artifacts.empty?
content = "### Jenkins artifacts:\n\n"
|
ruby
|
{
"resource": ""
}
|
q25823
|
RPM.Transaction.delete
|
validation
|
def delete(pkg)
iterator = case pkg
when Package
pkg[:sigmd5] ? each_match(:sigmd5, pkg[:sigmd5]) : each_match(:label, pkg[:label])
when String
each_match(:label, pkg)
when Dependency
each_match(:label, pkg.name).set_iterator_version(pkg.version)
else
raise TypeError, 'illegal argument type'
|
ruby
|
{
"resource": ""
}
|
q25824
|
RPM.Transaction.commit
|
validation
|
def commit
flags = RPM::C::TransFlags[:none]
callback = proc do |hdr, type, amount, total, key_ptr, data_ignored|
key_id = key_ptr.address
key = @keys.include?(key_id) ? @keys[key_id] : nil
if block_given?
package = hdr.null? ? nil : Package.new(hdr)
data = CallbackData.new(type, key, package, amount, total)
yield(data)
else
RPM::C.rpmShowProgress(hdr, type, amount, total, key, data_ignored)
end
end
# We create a callback to pass to the C method and we
# call the user supplied callback from there
#
# The C callback expects you to return a file handle,
# We expect from the user to get a File, which we
# then convert to a file handle to return.
callback = proc do |hdr, type, amount, total, key_ptr, data_ignored|
key_id = key_ptr.address
key = @keys.include?(key_id) ? @keys[key_id] : nil
if block_given?
package = hdr.null? ? nil : Package.new(hdr)
data = CallbackData.new(type, key, package, amount, total)
ret = yield(data)
# For OPEN_FILE we need to do some type conversion
# for certain callback types we need to do some
case type
when :inst_open_file
# For :inst_open_file the user callback has to
# return the open file
unless ret.is_a?(::File)
raise TypeError, "illegal return value type #{ret.class}. Expected File."
end
fdt = RPM::C.fdDup(ret.to_i)
if fdt.null? || RPM::C.Ferror(fdt) != 0
raise "Can't use opened file #{data.key}: #{RPM::C.Fstrerror(fdt)}"
RPM::C.Fclose(fdt) unless fdt.nil?
else
fdt = RPM::C.fdLink(fdt)
@fdt = fdt
end
|
ruby
|
{
"resource": ""
}
|
q25825
|
Tmx.Objects.find
|
validation
|
def find(params)
params = { type: params } if params.is_a?(String)
found_objects = find_all do |object|
|
ruby
|
{
"resource": ""
}
|
q25826
|
Deacon.RandomGenerator.next_lfsr25
|
validation
|
def next_lfsr25(seed)
i = 1
i = (seed + 1) & MASK
raise ArgumentError, "Seed #{seed} out of bounds" if seed && i ==
|
ruby
|
{
"resource": ""
}
|
q25827
|
Shebang.Command.parse
|
validation
|
def parse(argv = [])
@option_parser.parse!(argv)
options.each do |option|
if option.required? and !option.has_value?
|
ruby
|
{
"resource": ""
}
|
q25828
|
Shebang.Command.option
|
validation
|
def option(opt)
opt = opt.to_sym
options.each do |op|
if op.short === opt or op.long === opt
|
ruby
|
{
"resource": ""
}
|
q25829
|
FCS.Client.method_missing
|
validation
|
def method_missing(method, *args, &block)
klass = class_for_api_command(method)
return klass.new(@socket).send(method,
|
ruby
|
{
"resource": ""
}
|
q25830
|
Linked.Listable.in_chain?
|
validation
|
def in_chain?(other)
return false unless
|
ruby
|
{
"resource": ""
}
|
q25831
|
Linked.Listable.before
|
validation
|
def before
return to_enum(__callee__) unless block_given?
return if chain_head?
item = prev
|
ruby
|
{
"resource": ""
}
|
q25832
|
Linked.Listable.after
|
validation
|
def after
return to_enum(__callee__) unless block_given?
return if chain_tail?
item = self.next
|
ruby
|
{
"resource": ""
}
|
q25833
|
Bitkassa.PaymentResult.valid?
|
validation
|
def valid?
return false if raw_payload.nil? || raw_payload.empty?
return false if raw_authentication.nil? || raw_authentication.empty?
return
|
ruby
|
{
"resource": ""
}
|
q25834
|
IncrementalBackup.Task.run
|
validation
|
def run
# Validate - this will throw an exception if settings are not valid
validate_settings
# Run everything inside a lock, ensuring that only one instance of this
# task is running.
Lock.create(self) do
# Find the schedule to run
schedule = find_schedule
unless schedule
logger.info "No backup needed - exiting"
return
end
logger.info "Starting #{schedule} backup to #{settings.remote_server}"
# Paths and other options
timestamp = Time.now.strftime('backup_%Y-%m-%d-T%H-%M-%S')
current_path = File.join(settings.remote_path, 'current')
progress_path = File.join(settings.remote_path, 'incomplete')
complete_path =
|
ruby
|
{
"resource": ""
}
|
q25835
|
IncrementalBackup.Task.execute_ssh
|
validation
|
def execute_ssh(commands)
commands = [commands] unless commands.is_a? Array
result = ""
Net::SSH.start settings.remote_server, settings.remote_user do |ssh|
commands.each do |command|
was_error = false
logger.info "ssh: #{command}"
ssh.exec! command do |channel, stream, data|
case stream
when :stdout
logger.info data
result
|
ruby
|
{
"resource": ""
}
|
q25836
|
IncrementalBackup.Task.find_schedule
|
validation
|
def find_schedule
minutes = {
# If a cron job is run hourly it can be off by a couple of seconds
# from the last run. Set hourly to 58 minutes
hourly: 58,
daily: 24*60,
weekly: 7*24*60,
monthly: 30*24*60,
yearly: 365*24*60
}
now = DateTime.now
[:yearly, :monthly, :weekly, :daily, :hourly].each do |schedule|
|
ruby
|
{
"resource": ""
}
|
q25837
|
Bitkassa.Config.debug=
|
validation
|
def debug=(mode)
@debug = mode
if mode
HTTPI.log = true
HTTPI.log_level = :debug
|
ruby
|
{
"resource": ""
}
|
q25838
|
Shebang.Option.option_parser
|
validation
|
def option_parser
params = ["-#{@short}", "--#{@long}", nil, @options[:type]]
if [email protected]? and [email protected]?
params[2] = @description
|
ruby
|
{
"resource": ""
}
|
q25839
|
Linked.List.shift
|
validation
|
def shift
return nil if empty?
if list_head.last?
@_chain.tap { @_chain = nil }
else
|
ruby
|
{
"resource": ""
}
|
q25840
|
GoldenRose.ResultsFilterer.compact_results
|
validation
|
def compact_results(items)
items.map do |subtest|
subtests = subtest[:subtests]
if subtests.size >
|
ruby
|
{
"resource": ""
}
|
q25841
|
BnetApi.WoW.pet_stats
|
validation
|
def pet_stats(species_id, options = {})
level = options[:level] || 1
breedId = options[:breedId] || 3
qualityId = options[:qualityId] || 1
BnetApi.make_request_with_params("/wow/pet/stats/#{species_id}",
|
ruby
|
{
"resource": ""
}
|
q25842
|
BnetApi.WoW.realm_status
|
validation
|
def realm_status(*realms)
if realms.count > 0
BnetApi.make_request_with_params("/wow/realm/status", { realms: realms.join(',') })
|
ruby
|
{
"resource": ""
}
|
q25843
|
CloudMade.TilesService.get_tile
|
validation
|
def get_tile(lat, lon, zoom, style_id = nil, tile_size = nil)
|
ruby
|
{
"resource": ""
}
|
q25844
|
CloudMade.TilesService.get_xy_tile
|
validation
|
def get_xy_tile(xtile, ytile, zoom, style_id = nil, tile_size = nil)
style_id = self.default_style_id if
|
ruby
|
{
"resource": ""
}
|
q25845
|
Linked.ListEnumerable.each_item
|
validation
|
def each_item
return to_enum(__method__) { count } unless block_given?
return if empty?
item = list_head
|
ruby
|
{
"resource": ""
}
|
q25846
|
Linked.ListEnumerable.reverse_each_item
|
validation
|
def reverse_each_item
return to_enum(__method__) { count } unless block_given?
return if empty?
item =
|
ruby
|
{
"resource": ""
}
|
q25847
|
DuckPuncher.Registration.register
|
validation
|
def register(target, *mods, &block)
options = mods.last.is_a?(Hash) ? mods.pop : {}
mods << Module.new(&block) if block
target = DuckPuncher.lookup_constant target
|
ruby
|
{
"resource": ""
}
|
q25848
|
DuckPuncher.Registration.deregister
|
validation
|
def deregister(*targets)
targets.each &Ducks.list.method(:delete)
|
ruby
|
{
"resource": ""
}
|
q25849
|
LogstashAuditor.LogstashAuditor.audit
|
validation
|
def audit(audit_data)
request = create_request(audit_data)
|
ruby
|
{
"resource": ""
}
|
q25850
|
Sequel.MigrationBuilder.generate_migration
|
validation
|
def generate_migration(tables)
return if tables.empty? && @db_tables.empty?
result.clear
add_line "Sequel.migration do"
indent do
|
ruby
|
{
"resource": ""
}
|
q25851
|
Sequel.MigrationBuilder.generate_migration_body
|
validation
|
def generate_migration_body(tables)
current_tables, new_tables = table_names(tables).partition do |table_name|
@db_table_names.include?(table_name)
end
add_line "change do"
|
ruby
|
{
"resource": ""
}
|
q25852
|
Sequel.MigrationBuilder.create_new_tables
|
validation
|
def create_new_tables(new_table_names, tables)
each_table(new_table_names, tables) do |table_name, table, last_table|
|
ruby
|
{
"resource": ""
}
|
q25853
|
Sequel.MigrationBuilder.alter_tables
|
validation
|
def alter_tables(current_table_names, tables)
each_table(current_table_names, tables) do |table_name, table, last_table|
hsh = table.dup
hsh[:columns] = hsh[:columns].map {|c| Schema::DbColumn.build_from_hash(c) }
operations = Schema::AlterTableOperations.
build(@db_tables[table_name], hsh, :immutable_columns => @immutable_columns)
unless operations.empty?
all_operations = if @separate_alter_table_statements
operations.map {|o| [o] }
|
ruby
|
{
"resource": ""
}
|
q25854
|
Sequel.MigrationBuilder.alter_table_statement
|
validation
|
def alter_table_statement(table_name, operations)
add_line "alter_table #{table_name.inspect} do"
|
ruby
|
{
"resource": ""
}
|
q25855
|
Sequel.MigrationBuilder.create_table_statement
|
validation
|
def create_table_statement(table_name, table)
normalize_primary_key(table)
add_line "create_table #{table_name.inspect}#{pretty_hash(table[:table_options])} do"
indent do
output_columns(table[:columns],
|
ruby
|
{
"resource": ""
}
|
q25856
|
SauceLabs.SauceBrowserFactory.watir_browser
|
validation
|
def watir_browser(browser,browser_options)
target,options = browser_caps(browser,browser_options)
|
ruby
|
{
"resource": ""
}
|
q25857
|
SauceLabs.SauceBrowserFactory.selenium_driver
|
validation
|
def selenium_driver(browser,browser_options)
target,options
|
ruby
|
{
"resource": ""
}
|
q25858
|
SauceLabs.SauceBrowserFactory.browser_caps
|
validation
|
def browser_caps(browser,browser_options)
target = (browser.to_sym if ENV['BROWSER'].nil? or ENV['browser'].empty?) || (ENV['BROWSER'].to_sym)
browser,version,platform,device = extract_values_from(target)
options = {}
options.merge! browser_options
caps = capabilities(browser,version,platform,device)
options[:url] = url if url
if options.include? :url
|
ruby
|
{
"resource": ""
}
|
q25859
|
SauceLabs.ParsedValues.extract_values_from
|
validation
|
def extract_values_from(browser_string)
browser = extract_browser(browser_string).to_sym
version = extract_version(browser_string)
|
ruby
|
{
"resource": ""
}
|
q25860
|
SauceLabs.ParsedValues.extract_browser
|
validation
|
def extract_browser(value)
browser = value.to_s.split(/\d+/)[0]
browser = browser.to_s.split('|')[0]
|
ruby
|
{
"resource": ""
}
|
q25861
|
SauceLabs.ParsedValues.extract_version
|
validation
|
def extract_version(value)
value = value.to_s.split('|')[0] if value.to_s.include? '|'
regexp_to_match = /\d{1,}/
if (not regexp_to_match.match(value).nil?)
|
ruby
|
{
"resource": ""
}
|
q25862
|
SauceLabs.ParsedValues.extract_platform
|
validation
|
def extract_platform(value)
platform = value.to_s.split('|')[1] if value.to_s.include?
|
ruby
|
{
"resource": ""
}
|
q25863
|
SauceLabs.ParsedValues.extract_device
|
validation
|
def extract_device(value)
device = value.to_s.split('|')[2] if value.to_s.include? '|'
sauce_devices
|
ruby
|
{
"resource": ""
}
|
q25864
|
StdNum.Helpers.extractNumber
|
validation
|
def extractNumber str
match = STDNUMPAT.match str
|
ruby
|
{
"resource": ""
}
|
q25865
|
StdNum.Helpers.extract_multiple_numbers
|
validation
|
def extract_multiple_numbers(str)
return [] if str == '' ||
|
ruby
|
{
"resource": ""
}
|
q25866
|
Mongoid::Acts::NestedSet.Update.set_default_left_and_right
|
validation
|
def set_default_left_and_right
maxright = nested_set_scope.remove_order_by.max(right_field_name) || 0
self[left_field_name] = maxright + 1
|
ruby
|
{
"resource": ""
}
|
q25867
|
Mongoid::Acts::NestedSet.Update.update_self_and_descendants_depth
|
validation
|
def update_self_and_descendants_depth
if depth?
scope_class.each_with_level(self_and_descendants) do |node, level|
node.with(:safe => true).set(:depth, level) unless
|
ruby
|
{
"resource": ""
}
|
q25868
|
Mongoid::Acts::NestedSet.Update.destroy_descendants
|
validation
|
def destroy_descendants
return if right.nil? || left.nil? || skip_before_destroy
if acts_as_nested_set_options[:dependent] == :destroy
descendants.each do |model|
model.skip_before_destroy = true
model.destroy
end
else
c = nested_set_scope.where(left_field_name.to_sym.gt => left, right_field_name.to_sym.lt => right)
|
ruby
|
{
"resource": ""
}
|
q25869
|
NLP.TextStatistics.add
|
validation
|
def add(word,categories)
categories.each do |category|
@cwords[category] = [] if @cwords[category].nil?
@cwords[category].push word
|
ruby
|
{
"resource": ""
}
|
q25870
|
Formula.FormulaFormBuilder.button
|
validation
|
def button(value = nil, options = {})
options[:button] ||= {}
options[:container] ||= {}
options[:container][:class] = arrayorize(options[:container][:class]) << ::Formula.block_class
|
ruby
|
{
"resource": ""
}
|
q25871
|
Formula.FormulaFormBuilder.block
|
validation
|
def block(method = nil, options = {}, &block)
options[:error] ||= error(method) if method
components = "".html_safe
if method
components << self.label(method, options[:label]) if options[:label] or options[:label].nil? and method
end
components << @template.capture(&block)
options[:container] ||= {}
options[:container][:class] = arrayorize(options[:container][:class]) <<
|
ruby
|
{
"resource": ""
}
|
q25872
|
Formula.FormulaFormBuilder.input
|
validation
|
def input(method, options = {})
options[:as] ||= as(method)
options[:input] ||= {}
return hidden_field method, options[:input] if options[:as] == :hidden
klass = [::Formula.input_class, options[:as]]
klass << ::Formula.input_error_class if ::Formula.input_error_class.present? and error?(method)
self.block(method, options) do
@template.content_tag(::Formula.input_tag, :class => klass) do
case options[:as]
when :text then text_area method, ::Formula.area_options.merge(options[:input] || {})
when :file then file_field method, ::Formula.file_options.merge(options[:input] || {})
when :string then text_field method, ::Formula.field_options.merge(options[:input] || {})
when :password then password_field method, ::Formula.field_options.merge(options[:input] || {})
when :url then url_field method, ::Formula.field_options.merge(options[:input] || {})
when :email then email_field method, ::Formula.field_options.merge(options[:input] || {})
when :phone then phone_field method, ::Formula.field_options.merge(options[:input] || {})
when :number then number_field method, ::Formula.field_options.merge(options[:input] || {})
when :boolean then check_box method, ::Formula.box_options.merge(options[:input] || {})
when :country then country_select method,
|
ruby
|
{
"resource": ""
}
|
q25873
|
Formula.FormulaFormBuilder.file?
|
validation
|
def file?(method)
@files ||= {}
@files[method] ||= begin
file = @object.send(method) if @object && @object.respond_to?(method)
|
ruby
|
{
"resource": ""
}
|
q25874
|
Formula.FormulaFormBuilder.arrayorize
|
validation
|
def arrayorize(value)
case value
when nil then return []
|
ruby
|
{
"resource": ""
}
|
q25875
|
YardTypes.KindType.check
|
validation
|
def check(obj)
if name == 'Boolean'
obj == true || obj == false
else
|
ruby
|
{
"resource": ""
}
|
q25876
|
NetBooter.HttpConnection.toggle
|
validation
|
def toggle(outlet, status)
current_status = status(outlet)
|
ruby
|
{
"resource": ""
}
|
q25877
|
NetBooter.HttpConnection.get_request
|
validation
|
def get_request(path)
resp = nil
begin
Timeout::timeout(5) do
resp = do_http_request(path)
end
rescue => e
|
ruby
|
{
"resource": ""
}
|
q25878
|
MotionModel.ArrayModelAdapter.encodeWithCoder
|
validation
|
def encodeWithCoder(coder)
columns.each do |attr|
# Serialize attributes except the proxy has_many and belongs_to ones.
unless [:belongs_to, :has_many, :has_one].include? column(attr).type
value = self.send(attr)
|
ruby
|
{
"resource": ""
}
|
q25879
|
MotionModel.ArrayFinderQuery.order
|
validation
|
def order(field = nil, &block)
if block_given?
@collection = @collection.sort{|o1, o2| yield(o1, o2)}
else
raise ArgumentError.new('you must supply a field name to sort unless you supply a block.') if field.nil?
|
ruby
|
{
"resource": ""
}
|
q25880
|
MotionModel.ArrayFinderQuery.contain
|
validation
|
def contain(query_string, options = {:case_sensitive => false})
do_comparison(query_string) do |comparator, item|
if options[:case_sensitive]
|
ruby
|
{
"resource": ""
}
|
q25881
|
MotionModel.ArrayFinderQuery.in
|
validation
|
def in(set)
@collection = @collection.collect do |item|
item
|
ruby
|
{
"resource": ""
}
|
q25882
|
MotionModel.ArrayFinderQuery.eq
|
validation
|
def eq(query_string, options = {:case_sensitive => false})
do_comparison(query_string,
|
ruby
|
{
"resource": ""
}
|
q25883
|
MotionModel.ArrayFinderQuery.gt
|
validation
|
def gt(query_string, options = {:case_sensitive => false})
do_comparison(query_string, options) do
|
ruby
|
{
"resource": ""
}
|
q25884
|
MotionModel.ArrayFinderQuery.lt
|
validation
|
def lt(query_string, options = {:case_sensitive => false})
do_comparison(query_string, options) do
|
ruby
|
{
"resource": ""
}
|
q25885
|
MotionModel.ArrayFinderQuery.gte
|
validation
|
def gte(query_string, options = {:case_sensitive => false})
do_comparison(query_string,
|
ruby
|
{
"resource": ""
}
|
q25886
|
MotionModel.ArrayFinderQuery.lte
|
validation
|
def lte(query_string, options = {:case_sensitive => false})
do_comparison(query_string,
|
ruby
|
{
"resource": ""
}
|
q25887
|
MotionModel.ArrayFinderQuery.ne
|
validation
|
def ne(query_string, options = {:case_sensitive => false})
do_comparison(query_string,
|
ruby
|
{
"resource": ""
}
|
q25888
|
Music.Chord.inversion
|
validation
|
def inversion(amount)
fail ArgumentError, 'Inversion amount must be greater than or equal to 1' if amount < 1
fail ArgumentError, 'Not enough notes in chord for inversion' if amount >= @notes.size
note_array =
|
ruby
|
{
"resource": ""
}
|
q25889
|
Stellar.Courses.mine
|
validation
|
def mine
page = @client.get_nokogiri '/atstellar'
class_links = page.css('a[href*="/S/course/"]').
map
|
ruby
|
{
"resource": ""
}
|
q25890
|
MotionModel.Validatable.error_messages_for
|
validation
|
def error_messages_for(field)
key = field.to_sym
|
ruby
|
{
"resource": ""
}
|
q25891
|
MotionModel.Validatable.validate_presence
|
validation
|
def validate_presence(field, value, setting)
if(value.is_a?(Numeric))
return true
elsif value.is_a?(String) || value.nil?
result = value.nil? || ((value.length == 0) == setting)
additional_message = setting ? "non-empty" :
|
ruby
|
{
"resource": ""
}
|
q25892
|
MotionModel.Validatable.validate_length
|
validation
|
def validate_length(field, value, setting)
if value.is_a?(String) || value.nil?
result = value.nil? || (value.length < setting.first || value.length > setting.last)
add_message(field, "incorrect value supplied for #{field.to_s} -- should
|
ruby
|
{
"resource": ""
}
|
q25893
|
MotionModel.Validatable.validate_format
|
validation
|
def validate_format(field, value, setting)
result = value.nil? || setting.match(value).nil?
add_message(field, "#{field.to_s} does
|
ruby
|
{
"resource": ""
}
|
q25894
|
MotionModel.Model.set_auto_date_field
|
validation
|
def set_auto_date_field(field_name)
unless self.class.protect_remote_timestamps?
method = "#{field_name}="
|
ruby
|
{
"resource": ""
}
|
q25895
|
MotionModel.Model.set_belongs_to_attr
|
validation
|
def set_belongs_to_attr(col, owner, options = {})
_col = column(col)
unless belongs_to_synced?(_col, owner)
_set_attr(_col.name, owner)
rebuild_relation(_col, owner, set_inverse: options[:set_inverse])
if _col.polymorphic
|
ruby
|
{
"resource": ""
}
|
q25896
|
Stellar.Homework.submissions
|
validation
|
def submissions
page = @client.get_nokogiri @url
@submissions ||= page.css('.gradeTable tbody tr').map { |tr|
begin
Stellar::Homework::Submission.new
|
ruby
|
{
"resource": ""
}
|
q25897
|
Stellar.Client.mech
|
validation
|
def mech(&block)
m = Mechanize.new do |m|
m.cert_store = OpenSSL::X509::Store.new
|
ruby
|
{
"resource": ""
}
|
q25898
|
Stellar.Client.get_nokogiri
|
validation
|
def get_nokogiri(path)
uri = URI.join('https://stellar.mit.edu',
|
ruby
|
{
"resource": ""
}
|
q25899
|
MotionModel.InputHelpers.field_at
|
validation
|
def field_at(index)
data = self.class.instance_variable_get('@binding_data'.to_sym)
|
ruby
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.