_id
stringlengths 2
6
| title
stringlengths 9
130
| partition
stringclasses 3
values | text
stringlengths 30
4.3k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q25000
|
AdwordsApi.ReportUtils.download_report_as_stream_with_awql
|
validation
|
def download_report_as_stream_with_awql(
report_query, format, cid = nil, &block)
|
ruby
|
{
"resource": ""
}
|
q25001
|
AdwordsApi.ReportUtils.get_stream_helper_with_awql
|
validation
|
def get_stream_helper_with_awql(report_query, format, cid = nil)
|
ruby
|
{
"resource": ""
}
|
q25002
|
AdwordsApi.ReportUtils.get_report_response
|
validation
|
def get_report_response(report_definition, cid, &block)
definition_text = get_report_definition_text(report_definition)
data = '__rdxml=%s'
|
ruby
|
{
"resource": ""
}
|
q25003
|
AdwordsApi.ReportUtils.get_report_response_with_awql
|
validation
|
def get_report_response_with_awql(report_query, format, cid, &block)
data = '__rdquery=%s&__fmt=%s' %
|
ruby
|
{
"resource": ""
}
|
q25004
|
AdwordsApi.ReportUtils.make_adhoc_request
|
validation
|
def make_adhoc_request(data, cid, &block)
@api.utils_reporter.report_utils_used()
url = @api.api_config.adhoc_report_download_url(@version)
headers = get_report_request_headers(url, cid)
log_request(url, headers, data)
# A given block indicates that we should make a stream request and yield
# the results, rather than return a full response.
if block_given?
|
ruby
|
{
"resource": ""
}
|
q25005
|
AdwordsApi.ReportUtils.get_report_request_headers
|
validation
|
def get_report_request_headers(url, cid)
@header_handler ||= AdwordsApi::ReportHeaderHandler.new(
|
ruby
|
{
"resource": ""
}
|
q25006
|
AdwordsApi.ReportUtils.save_to_file
|
validation
|
def save_to_file(data, path)
open(path,
|
ruby
|
{
"resource": ""
}
|
q25007
|
AdwordsApi.ReportUtils.log_headers
|
validation
|
def log_headers(headers)
@api.logger.debug('HTTP headers: [%s]'
|
ruby
|
{
"resource": ""
}
|
q25008
|
AdwordsApi.ReportUtils.check_for_errors
|
validation
|
def check_for_errors(response)
# Check for error code.
if response.code != 200
# Check for error in body.
report_body = response.body
check_for_xml_error(report_body, response.code)
|
ruby
|
{
"resource": ""
}
|
q25009
|
AdwordsApi.ReportUtils.check_for_xml_error
|
validation
|
def check_for_xml_error(report_body, response_code)
unless report_body.nil?
error_response = get_nori().parse(report_body)
if error_response.include?(:report_download_error) and
error_response[:report_download_error].include?(:api_error)
api_error = error_response[:report_download_error][:api_error]
|
ruby
|
{
"resource": ""
}
|
q25010
|
AdwordsApi.ReportUtils.report_definition_to_xml
|
validation
|
def report_definition_to_xml(report_definition)
check_report_definition_hash(report_definition)
add_report_definition_hash_order(report_definition)
begin
return Gyoku.xml({:report_definition => report_definition})
rescue ArgumentError => e
if e.message.include?("order!")
unknown_fields =
|
ruby
|
{
"resource": ""
}
|
q25011
|
AdwordsApi.ReportUtils.check_report_definition_hash
|
validation
|
def check_report_definition_hash(report_definition)
# Minimal set of fields required.
REQUIRED_FIELDS.each do |field|
unless report_definition.include?(field)
raise AdwordsApi::Errors::InvalidReportDefinitionError,
"Required field '%s' is missing in the definition" % field
end
end
# Fields list is also required.
unless report_definition[:selector].include?(:fields)
raise AdwordsApi::Errors::InvalidReportDefinitionError,
'Fields list is required'
end
|
ruby
|
{
"resource": ""
}
|
q25012
|
AdwordsApi.ReportUtils.add_report_definition_hash_order
|
validation
|
def add_report_definition_hash_order(node, name = :root)
def_order = REPORT_DEFINITION_ORDER[name]
var_order = def_order.reject { |field| !node.include?(field) }
node.keys.each do |key|
if REPORT_DEFINITION_ORDER.include?(key)
|
ruby
|
{
"resource": ""
}
|
q25013
|
AdwordsApi.ReportHeaderHandler.headers
|
validation
|
def headers(url, cid)
override = (cid.nil?) ? nil : {:client_customer_id => cid}
credentials = @credential_handler.credentials(override)
headers = {
'Content-Type' => 'application/x-www-form-urlencoded',
'Authorization' => @auth_handler.auth_string(credentials),
'User-Agent' => @credential_handler.generate_user_agent(),
'clientCustomerId' => credentials[:client_customer_id].to_s,
'developerToken' => credentials[:developer_token]
}
skip_report_header = @config.read('library.skip_report_header')
unless skip_report_header.nil?
headers['skipReportHeader'] = skip_report_header.to_s
end
skip_report_summary = @config.read('library.skip_report_summary')
unless skip_report_summary.nil?
headers['skipReportSummary'] = skip_report_summary.to_s
end
skip_column_header = @config.read('library.skip_column_header')
unless skip_column_header.nil?
|
ruby
|
{
"resource": ""
}
|
q25014
|
AdsCommon.CredentialHandler.credentials
|
validation
|
def credentials(credentials_override = nil)
credentials = @credentials.dup()
|
ruby
|
{
"resource": ""
}
|
q25015
|
AdsCommon.CredentialHandler.credentials=
|
validation
|
def credentials=(new_credentials)
# Find new and changed properties.
diff = new_credentials.inject([]) do |result, (key, value)|
result << [key, value] if value != @credentials[key]
result
end
# Find removed properties.
diff = @credentials.inject(diff) do |result, (key, _)|
|
ruby
|
{
"resource": ""
}
|
q25016
|
AdsCommon.CredentialHandler.generate_user_agent
|
validation
|
def generate_user_agent(extra_ids = [], agent_app = nil)
agent_app ||= File.basename($0)
agent_data = extra_ids
agent_data << 'Common-Ruby/%s' % AdsCommon::ApiConfig::CLIENT_LIB_VERSION
agent_data << 'GoogleAdsSavon/%s' % GoogleAdsSavon::VERSION
|
ruby
|
{
"resource": ""
}
|
q25017
|
AdsCommon.CredentialHandler.get_extra_user_agents
|
validation
|
def get_extra_user_agents()
@extra_user_agents_lock.synchronize do
user_agents = @extra_user_agents.collect do |k, v|
v.nil? ? k : '%s/%s'
|
ruby
|
{
"resource": ""
}
|
q25018
|
AdsCommon.ResultsExtractor.extract_header_data
|
validation
|
def extract_header_data(response)
header_type = get_full_type_signature(:SoapResponseHeader)
headers = response.header[:response_header].dup
|
ruby
|
{
"resource": ""
}
|
q25019
|
AdsCommon.ResultsExtractor.extract_exception_data
|
validation
|
def extract_exception_data(soap_fault, exception_name)
exception_type = get_full_type_signature(exception_name)
|
ruby
|
{
"resource": ""
}
|
q25020
|
AdsCommon.ResultsExtractor.normalize_fields
|
validation
|
def normalize_fields(data, fields)
fields.each do |field|
field_name = field[:name]
if data.include?(field_name)
field_data = data[field_name]
field_data = normalize_output_field(field_data, field)
|
ruby
|
{
"resource": ""
}
|
q25021
|
AdsCommon.ResultsExtractor.normalize_output_field
|
validation
|
def normalize_output_field(field_data, field_def)
return case field_data
when Array
normalize_array_field(field_data, field_def)
when Hash
|
ruby
|
{
"resource": ""
}
|
q25022
|
AdsCommon.ResultsExtractor.normalize_array_field
|
validation
|
def normalize_array_field(data, field_def)
result = data
# Convert a specific structure to a handy hash if detected.
if check_key_value_struct(result)
result = convert_key_value_to_hash(result).inject({})
|
ruby
|
{
"resource": ""
}
|
q25023
|
AdsCommon.ResultsExtractor.normalize_hash_field
|
validation
|
def normalize_hash_field(field, field_def)
process_attributes(field, true)
field_type = field_def[:type]
field_def = get_full_type_signature(field_type)
# First checking for xsi:type provided.
xsi_type_override = determine_xsi_type_override(field, field_def)
unless xsi_type_override.nil?
field_def = get_full_type_signature(xsi_type_override)
return (field_def.nil?) ? field :
normalize_fields(field, field_def[:fields])
end
result = field
# Now checking for choice options from wsdl.
choice_type_override = determine_choice_type_override(field, field_def)
unless choice_type_override.nil?
# For overrides we need to process sub-field and than return it
# in the original structure.
field_key = field.keys.first
field_data = field[field_key]
|
ruby
|
{
"resource": ""
}
|
q25024
|
AdsCommon.ResultsExtractor.determine_choice_type_override
|
validation
|
def determine_choice_type_override(field_data, field_def)
result = nil
if field_data.kind_of?(Hash) and field_def.include?(:choices)
|
ruby
|
{
"resource": ""
}
|
q25025
|
AdsCommon.ResultsExtractor.determine_choice
|
validation
|
def determine_choice(field_data, field_choices)
result = nil
key_name = field_data.keys.first
unless key_name.nil?
choice = find_named_entry(field_choices, key_name)
|
ruby
|
{
"resource": ""
}
|
q25026
|
AdsCommon.ResultsExtractor.normalize_item
|
validation
|
def normalize_item(item, field_def)
return case field_def[:type]
when 'long', 'int' then Integer(item)
when 'double', 'float' then Float(item)
|
ruby
|
{
"resource": ""
}
|
q25027
|
AdsCommon.ResultsExtractor.check_array_collapse
|
validation
|
def check_array_collapse(data, field_def)
result = data
if !field_def[:min_occurs].nil? &&
(field_def[:max_occurs] == :unbounded ||
(!field_def[:max_occurs].nil? && field_def[:max_occurs] > 1)) &&
|
ruby
|
{
"resource": ""
}
|
q25028
|
AdsCommon.ResultsExtractor.process_attributes
|
validation
|
def process_attributes(data, keep_xsi_type = false)
if keep_xsi_type
xsi_type = data.delete(:"@xsi:type")
|
ruby
|
{
"resource": ""
}
|
q25029
|
AdsCommon.Api.service
|
validation
|
def service(name, version = nil)
name = name.to_sym
version = (version.nil?) ? api_config.default_version : version.to_sym
# Check if the combination is available.
validate_service_request(version, name)
# Try to re-use the service for this version if it was requested before.
wrapper = if @wrappers.include?(version) && @wrappers[version][name]
|
ruby
|
{
"resource": ""
}
|
q25030
|
AdsCommon.Api.authorize
|
validation
|
def authorize(parameters = {}, &block)
parameters.each_pair do |key, value|
@credential_handler.set_credential(key, value)
end
auth_handler = get_auth_handler()
token = auth_handler.get_token()
# If token is invalid ask for a new one.
if token.nil?
begin
credentials = @credential_handler.credentials
token = auth_handler.get_token(credentials)
rescue AdsCommon::Errors::OAuth2VerificationRequired => e
verification_code
|
ruby
|
{
"resource": ""
}
|
q25031
|
AdsCommon.Api.save_oauth2_token
|
validation
|
def save_oauth2_token(token)
raise AdsCommon::Errors::Error, "Can't save nil token" if token.nil?
AdsCommon::Utils.save_oauth2_token(
|
ruby
|
{
"resource": ""
}
|
q25032
|
AdsCommon.Api.validate_service_request
|
validation
|
def validate_service_request(version, service)
# Check if the current config supports the requested version.
unless api_config.has_version(version)
raise AdsCommon::Errors::Error,
"Version '%s' not recognized" % version.to_s
end
# Check if the specified version has the requested service.
unless api_config.version_has_service(version,
|
ruby
|
{
"resource": ""
}
|
q25033
|
AdsCommon.Api.create_auth_handler
|
validation
|
def create_auth_handler()
auth_method = @config.read('authentication.method', :OAUTH2)
return case auth_method
when :OAUTH
raise AdsCommon::Errors::Error,
'OAuth authorization method is deprecated, use OAuth2 instead.'
when :OAUTH2
AdsCommon::Auth::OAuth2Handler.new(
|
ruby
|
{
"resource": ""
}
|
q25034
|
AdsCommon.Api.prepare_wrapper
|
validation
|
def prepare_wrapper(version, service)
api_config.do_require(version, service)
endpoint = api_config.endpoint(version, service)
interface_class_name = api_config.interface_name(version, service)
wrapper = class_for_path(interface_class_name).new(@config, endpoint)
auth_handler = get_auth_handler()
header_ns =
|
ruby
|
{
"resource": ""
}
|
q25035
|
AdsCommon.Api.create_default_logger
|
validation
|
def create_default_logger()
logger = Logger.new(STDOUT)
logger.level = get_log_level_for_string(
|
ruby
|
{
"resource": ""
}
|
q25036
|
AdsCommon.Api.load_config
|
validation
|
def load_config(provided_config = nil)
@config = (provided_config.nil?) ?
AdsCommon::Config.new(
|
ruby
|
{
"resource": ""
}
|
q25037
|
AdsCommon.Api.init_config
|
validation
|
def init_config()
# Set up logger.
provided_logger = @config.read('library.logger')
self.logger = (provided_logger.nil?) ?
create_default_logger() : provided_logger
# Set up default HTTPI adapter.
|
ruby
|
{
"resource": ""
}
|
q25038
|
AdsCommon.Api.symbolize_config_value
|
validation
|
def symbolize_config_value(key)
value_str = @config.read(key).to_s
if !value_str.nil? and !value_str.empty?
|
ruby
|
{
"resource": ""
}
|
q25039
|
AdsCommon.Api.class_for_path
|
validation
|
def class_for_path(path)
path.split('::').inject(Kernel) do |scope, const_name|
|
ruby
|
{
"resource": ""
}
|
q25040
|
Zold.Farm.to_json
|
validation
|
def to_json
{
threads: @threads.to_json,
pipeline: @pipeline.size,
best:
|
ruby
|
{
"resource": ""
}
|
q25041
|
Zold.AsyncEntrance.exists?
|
validation
|
def exists?(id, body)
DirItems.new(@dir).fetch.each do |f|
next unless f.start_with?("#{id}-")
|
ruby
|
{
"resource": ""
}
|
q25042
|
Zold.Tax.exists?
|
validation
|
def exists?(details)
[email protected] { |t| t.details.start_with?("#{PREFIX} ")
|
ruby
|
{
"resource": ""
}
|
q25043
|
Zold.SpreadEntrance.push
|
validation
|
def push(id, body)
mods = @entrance.push(id, body)
return mods if @remotes.all.empty?
mods.each do |m|
next if @seen.include?(m)
|
ruby
|
{
"resource": ""
}
|
q25044
|
Zold.Wallet.init
|
validation
|
def init(id, pubkey, overwrite: false, network: 'test')
raise "File '#{path}' already exists" if File.exist?(path) && !overwrite
raise "Invalid network name '#{network}'" unless network =~ /^[a-z]{4,16}$/
FileUtils.mkdir_p(File.dirname(path))
|
ruby
|
{
"resource": ""
}
|
q25045
|
Zold.Wallet.balance
|
validation
|
def balance
txns.inject(Amount::ZERO)
|
ruby
|
{
"resource": ""
}
|
q25046
|
Zold.Wallet.sub
|
validation
|
def sub(amount, invoice, pvt, details = '-', time: Time.now)
raise 'The amount has to be of type Amount' unless amount.is_a?(Amount)
raise "The amount can't be negative: #{amount}" if amount.negative?
raise 'The pvt has to be of type Key' unless pvt.is_a?(Key)
prefix, target = invoice.split('@')
tid = max + 1
raise 'Too many transactions already, can\'t add more' if max > 0xffff
txn = Txn.new(
tid,
time,
amount * -1,
|
ruby
|
{
"resource": ""
}
|
q25047
|
Zold.Wallet.add
|
validation
|
def add(txn)
raise 'The txn has to be of type Txn' unless txn.is_a?(Txn)
raise "Wallet #{id} can't pay itself: #{txn}" if txn.bnf == id
raise "The amount can't be zero in #{id}: #{txn}" if txn.amount.zero?
if txn.amount.negative? && includes_negative?(txn.id)
raise "Negative transaction with the same ID #{txn.id} already exists in #{id}"
end
if txn.amount.positive? && includes_positive?(txn.id, txn.bnf)
|
ruby
|
{
"resource": ""
}
|
q25048
|
Zold.Wallet.includes_negative?
|
validation
|
def includes_negative?(id, bnf = nil)
raise 'The txn ID has to be of type Integer' unless id.is_a?(Integer)
!txns.find
|
ruby
|
{
"resource": ""
}
|
q25049
|
Zold.Wallet.includes_positive?
|
validation
|
def includes_positive?(id, bnf)
raise 'The txn ID has to be of type Integer' unless id.is_a?(Integer)
raise 'The bnf has to be of type Id' unless bnf.is_a?(Id)
|
ruby
|
{
"resource": ""
}
|
q25050
|
Zold.Wallet.age
|
validation
|
def age
list = txns
list.empty? ? 0 : (Time.now
|
ruby
|
{
"resource": ""
}
|
q25051
|
Zold.Wallet.max
|
validation
|
def max
negative = txns.select { |t| t.amount.negative?
|
ruby
|
{
"resource": ""
}
|
q25052
|
Zold.Propagate.propagate
|
validation
|
def propagate(id, _)
start = Time.now
modified = []
total = 0
network = @wallets.acq(id, &:network)
@wallets.acq(id, &:txns).select { |t| t.amount.negative? }.each do |t|
total += 1
if t.bnf == id
@log.error("Paying itself in #{id}? #{t}")
next
end
@wallets.acq(t.bnf, exclusive: true) do |target|
unless target.exists?
@log.debug("#{t.amount * -1} from #{id} to #{t.bnf}: wallet is absent")
next
end
unless target.network == network
|
ruby
|
{
"resource": ""
}
|
q25053
|
Zold.Node.exec
|
validation
|
def exec(cmd, nohup_log)
start = Time.now
Open3.popen2e({ 'MALLOC_ARENA_MAX' => '2' }, cmd) do |stdin, stdout, thr|
nohup_log.print("Started process ##{thr.pid} from process ##{Process.pid}: #{cmd}\n")
stdin.close
until stdout.eof?
begin
line = stdout.gets
rescue IOError => e
line = Backtrace.new(e).to_s
end
nohup_log.print(line)
|
ruby
|
{
"resource": ""
}
|
q25054
|
Zold.ThreadPool.add
|
validation
|
def add
raise 'Block must be given to start()' unless block_given?
latch = Concurrent::CountDownLatch.new(1)
thread = Thread.start do
Thread.current.name = @title
VerboseThread.new(@log).run do
latch.count_down
yield
|
ruby
|
{
"resource": ""
}
|
q25055
|
Zold.ThreadPool.kill
|
validation
|
def kill
if @threads.empty?
@log.debug("Thread pool \"#{@title}\" terminated with no threads")
return
end
@log.debug("Stopping \"#{@title}\" thread pool with #{@threads.count} threads: \
#{@threads.map { |t| "#{t.name}/#{t.status}" }.join(', ')}...")
start = Time.new
begin
join(0.1)
ensure
@threads.each do |t|
(t.thread_variable_get(:kids) || []).each(&:kill)
t.kill
sleep(0.001) while t.alive? # I believe it's a bug in Ruby, this line fixes it
Thread.current.thread_variable_set(
|
ruby
|
{
"resource": ""
}
|
q25056
|
Zold.ThreadPool.to_json
|
validation
|
def to_json
@threads.map do |t|
{
name: t.name,
status: t.status,
alive: t.alive?,
|
ruby
|
{
"resource": ""
}
|
q25057
|
Zold.ThreadPool.to_s
|
validation
|
def to_s
@threads.map do |t|
[
"#{t.name}: status=#{t.status}; alive=#{t.alive?}",
'Vars: ' + t.thread_variables.map {
|
ruby
|
{
"resource": ""
}
|
q25058
|
Zold.Patch.legacy
|
validation
|
def legacy(wallet, hours: 24)
raise 'You can\'t add legacy to a non-empty patch' unless @id.nil?
wallet.txns.each do |txn|
@txns
|
ruby
|
{
"resource": ""
}
|
q25059
|
Zold.Patch.save
|
validation
|
def save(file, overwrite: false, allow_negative_balance: false)
raise 'You have to join at least one wallet in' if empty?
before = ''
wallet = Wallet.new(file)
before = wallet.digest if wallet.exists?
Tempfile.open([@id, Wallet::EXT]) do |f|
temp = Wallet.new(f.path)
temp.init(@id, @key, overwrite: overwrite, network: @network)
File.open(f.path, 'a') do |t|
@txns.each do |txn|
next if Id::BANNED.include?(txn.bnf.to_s)
t.print "#{txn}\n"
end
end
temp.refurbish
if temp.balance.negative?
|
ruby
|
{
"resource": ""
}
|
q25060
|
Zold.Copies.clean
|
validation
|
def clean(max: 24 * 60 * 60)
Futex.new(file, log: @log).open do
list = load
list.reject! do |s|
if s[:time] >= Time.now - max
false
else
@log.debug("Copy ##{s[:name]}/#{s[:host]}:#{s[:port]} is too old, over #{Age.new(s[:time])}")
true
end
end
save(list)
deleted = 0
files.each do |f|
next unless list.find { |s| s[:name] == File.basename(f, Copies::EXT) }.nil?
file
|
ruby
|
{
"resource": ""
}
|
q25061
|
Zold.Copies.add
|
validation
|
def add(content, host, port, score, time: Time.now, master: false)
raise "Content can't be empty" if content.empty?
raise 'TCP port must be of type Integer' unless port.is_a?(Integer)
raise "TCP port can't be negative: #{port}" if port.negative?
raise 'Time must be of type Time' unless time.is_a?(Time)
raise "Time must be in the past: #{time}" if time > Time.now
raise 'Score must be Integer' unless score.is_a?(Integer)
raise "Score can't be negative: #{score}" if score.negative?
FileUtils.mkdir_p(@dir)
Futex.new(file, log: @log).open do
list = load
target = list.find do |s|
f = File.join(@dir, "#{s[:name]}#{Copies::EXT}")
digest = OpenSSL::Digest::SHA256.new(content).hexdigest
File.exist?(f) && OpenSSL::Digest::SHA256.file(f).hexdigest == digest
end
if target.nil?
max = DirItems.new(@dir).fetch
.select { |f| File.basename(f, Copies::EXT) =~ /^[0-9]+$/ }
.map(&:to_i)
.max
max
|
ruby
|
{
"resource": ""
}
|
q25062
|
Zold.Remotes.iterate
|
validation
|
def iterate(log, farm: Farm::Empty.new, threads: 1)
raise 'Log can\'t be nil' if log.nil?
raise 'Farm can\'t be nil' if farm.nil?
Hands.exec(threads, all) do |r, idx|
Thread.current.name = "remotes-#{idx}@#{r[:host]}:#{r[:port]}"
start = Time.now
best = farm.best[0]
node = RemoteNode.new(
host: r[:host],
port: r[:port],
score: best.nil? ? Score::ZERO : best,
idx: idx,
master: master?(r[:host], r[:port]),
|
ruby
|
{
"resource": ""
}
|
q25063
|
Thredded.PostCommon.mark_as_unread
|
validation
|
def mark_as_unread(user)
if previous_post.nil?
read_state = postable.user_read_states.find_by(user_id: user.id)
read_state.destroy if read_state
|
ruby
|
{
"resource": ""
}
|
q25064
|
Thredded.BaseMailer.find_record
|
validation
|
def find_record(klass, id_or_record)
# Check by name because in development the Class might have been reloaded after id was initialized
|
ruby
|
{
"resource": ""
}
|
q25065
|
Thredded.ContentModerationState.moderation_state_visible_to_user?
|
validation
|
def moderation_state_visible_to_user?(user)
moderation_state_visible_to_all? ||
(!user.thredded_anonymous? &&
(user_id
|
ruby
|
{
"resource": ""
}
|
q25066
|
Spreadsheet.Worksheet.protect!
|
validation
|
def protect! password = ''
@protected = true
password = password.to_s
if password.size == 0
@password_hash = 0
|
ruby
|
{
"resource": ""
}
|
q25067
|
Spreadsheet.Worksheet.format_column
|
validation
|
def format_column idx, format=nil, opts={}
opts[:worksheet] = self
res = case idx
when Integer
column = nil
if format
|
ruby
|
{
"resource": ""
}
|
q25068
|
Spreadsheet.Worksheet.update_row
|
validation
|
def update_row idx, *cells
res = if row = @rows[idx]
row[0, cells.size] = cells
row
else
|
ruby
|
{
"resource": ""
}
|
q25069
|
Spreadsheet.Worksheet.merge_cells
|
validation
|
def merge_cells start_row, start_col, end_row, end_col
# FIXME enlarge or dup check
|
ruby
|
{
"resource": ""
}
|
q25070
|
Spreadsheet.Row.formatted
|
validation
|
def formatted
copy = dup
Helpers.rcompact(@formats)
if copy.length < @formats.size
|
ruby
|
{
"resource": ""
}
|
q25071
|
Spreadsheet.Workbook.set_custom_color
|
validation
|
def set_custom_color idx, red, green, blue
raise 'Invalid format'
|
ruby
|
{
"resource": ""
}
|
q25072
|
Spreadsheet.Workbook.format
|
validation
|
def format idx
case idx
when Integer
@formats[idx] || @default_format || Format.new
when String
|
ruby
|
{
"resource": ""
}
|
q25073
|
Spreadsheet.Workbook.worksheet
|
validation
|
def worksheet idx
case idx
when Integer
@worksheets[idx]
|
ruby
|
{
"resource": ""
}
|
q25074
|
Spreadsheet.Workbook.write
|
validation
|
def write io_path_or_writer
if io_path_or_writer.is_a? Writer
io_path_or_writer.write self
else
|
ruby
|
{
"resource": ""
}
|
q25075
|
ZendeskAPI.Sideloading._side_load
|
validation
|
def _side_load(name, klass, resources)
associations = klass.associated_with(name)
associations.each do |association|
association.side_load(resources, @included[name])
end
resources.each do |resource|
loaded_associations = resource.loaded_associations
loaded_associations.each do |association|
loaded =
|
ruby
|
{
"resource": ""
}
|
q25076
|
ZendeskAPI.Collection.<<
|
validation
|
def <<(item)
fetch
if item.is_a?(Resource)
if item.is_a?(@resource_class)
@resources << item
else
|
ruby
|
{
"resource": ""
}
|
q25077
|
ZendeskAPI.Collection.fetch!
|
validation
|
def fetch!(reload = false)
if @resources && (!@fetchable || !reload)
return @resources
elsif association && association.options.parent && association.options.parent.new_record?
return (@resources = [])
|
ruby
|
{
"resource": ""
}
|
q25078
|
ZendeskAPI.Collection.method_missing
|
validation
|
def method_missing(name, *args, &block)
if resource_methods.include?(name)
collection_method(name, *args, &block)
elsif [].respond_to?(name, false)
|
ruby
|
{
"resource": ""
}
|
q25079
|
ZendeskAPI.Association.side_load
|
validation
|
def side_load(resources, side_loads)
key = "#{options.name}_id"
plural_key = "#{Inflection.singular options.name.to_s}_ids"
resources.each do |resource|
if resource.key?(plural_key) # Grab associations from child_ids field on resource
side_load_from_child_ids(resource, side_loads, plural_key)
elsif resource.key?(key) || options.singular
|
ruby
|
{
"resource": ""
}
|
q25080
|
ZendeskAPI.Save.save
|
validation
|
def save(options = {}, &block)
save!(options, &block)
rescue ZendeskAPI::Error::RecordInvalid =>
|
ruby
|
{
"resource": ""
}
|
q25081
|
ZendeskAPI.Save.save_associations
|
validation
|
def save_associations
self.class.associations.each do |association_data|
association_name = association_data[:name]
next unless send("#{association_name}_used?") && association = send(association_name)
inline_creation = association_data[:inline] == :create && new_record?
changed = association.is_a?(Collection) || association.changed?
if association.respond_to?(:save) && changed && !inline_creation && association.save
|
ruby
|
{
"resource": ""
}
|
q25082
|
ZendeskAPI.Read.reload!
|
validation
|
def reload!
response = @client.connection.get(path) do |req|
yield req
|
ruby
|
{
"resource": ""
}
|
q25083
|
ZendeskAPI.CreateMany.create_many!
|
validation
|
def create_many!(client, attributes_array, association = Association.new(:class => self))
response = client.connection.post("#{association.generate_path}/create_many") do |req|
req.body = { resource_name => attributes_array }
|
ruby
|
{
"resource": ""
}
|
q25084
|
ZendeskAPI.CreateOrUpdate.create_or_update!
|
validation
|
def create_or_update!(client, attributes, association = Association.new(:class => self))
response = client.connection.post("#{association.generate_path}/create_or_update") do |req|
req.body = { resource_name => attributes }
|
ruby
|
{
"resource": ""
}
|
q25085
|
ZendeskAPI.CreateOrUpdateMany.create_or_update_many!
|
validation
|
def create_or_update_many!(client, attributes)
association = Association.new(:class => self)
response = client.connection.post("#{association.generate_path}/create_or_update_many") do
|
ruby
|
{
"resource": ""
}
|
q25086
|
ZendeskAPI.Destroy.destroy!
|
validation
|
def destroy!
return false if destroyed? || new_record?
@client.connection.delete(url || path) do |req|
|
ruby
|
{
"resource": ""
}
|
q25087
|
ZendeskAPI.DestroyMany.destroy_many!
|
validation
|
def destroy_many!(client, ids, association = Association.new(:class => self))
response = client.connection.delete("#{association.generate_path}/destroy_many") do |req|
req.params = { :ids => ids.join(',') }
|
ruby
|
{
"resource": ""
}
|
q25088
|
ZendeskAPI.UpdateMany.update_many!
|
validation
|
def update_many!(client, ids_or_attributes, attributes = {})
association = attributes.delete(:association) || Association.new(:class => self)
response = client.connection.put("#{association.generate_path}/update_many") do |req|
if attributes == {}
req.body = { resource_name => ids_or_attributes }
|
ruby
|
{
"resource": ""
}
|
q25089
|
ZendeskAPI.Macro.apply!
|
validation
|
def apply!(ticket = nil)
path = "#{self.path}/apply"
if ticket
path = "#{ticket.path}/#{path}"
|
ruby
|
{
"resource": ""
}
|
q25090
|
ZendeskAPI.Client.method_missing
|
validation
|
def method_missing(method, *args, &block)
method = method.to_s
options = args.last.is_a?(Hash) ? args.pop : {}
@resource_cache[method] ||= { :class => nil, :cache => ZendeskAPI::LRUCache.new }
if !options.delete(:reload) && (cached = @resource_cache[method][:cache].read(options.hash))
cached
else
@resource_cache[method][:class] ||= method_as_class(method)
raise
|
ruby
|
{
"resource": ""
}
|
q25091
|
Pliny.Router.version
|
validation
|
def version(*versions, &block)
condition = lambda { |env|
|
ruby
|
{
"resource": ""
}
|
q25092
|
Vanity.Metric.track_args
|
validation
|
def track_args(args)
case args
when Hash
timestamp, identity, values = args.values_at(:timestamp, :identity, :values)
when Array
values = args
when Numeric
values = [args]
|
ruby
|
{
"resource": ""
}
|
q25093
|
Vanity.Render.render
|
validation
|
def render(path_or_options, locals = {})
if path_or_options.respond_to?(:keys)
render_erb(
path_or_options[:file] || path_or_options[:partial],
|
ruby
|
{
"resource": ""
}
|
q25094
|
Vanity.Render.method_missing
|
validation
|
def method_missing(method, *args, &block)
%w(url_for
|
ruby
|
{
"resource": ""
}
|
q25095
|
Vanity.Render.vanity_simple_format
|
validation
|
def vanity_simple_format(text, options={})
open = "<p #{options.map { |k,v| "#{k}=\"#{CGI.escapeHTML v}\"" }.join(" ")}>"
text = open + text.gsub(/\r\n?/, "\n"). # \r\n and \r -> \n
|
ruby
|
{
"resource": ""
}
|
q25096
|
Vanity.Playground.experiment
|
validation
|
def experiment(name)
id = name.to_s.downcase.gsub(/\W/, "_").to_sym
Vanity.logger.warn("Deprecated: Please call experiment method with experiment identifier (a Ruby symbol)")
|
ruby
|
{
"resource": ""
}
|
q25097
|
Vanity.Templates.custom_template_path_valid?
|
validation
|
def custom_template_path_valid?
Vanity.playground.custom_templates_path &&
File.exist?(Vanity.playground.custom_templates_path) &&
|
ruby
|
{
"resource": ""
}
|
q25098
|
BenchmarkDriver.RubyInterface.run
|
validation
|
def run
unless @executables.empty?
@config.executables = @executables
end
jobs = @jobs.flat_map do |job|
BenchmarkDriver::JobParser.parse({
|
ruby
|
{
"resource": ""
}
|
q25099
|
Viewpoint::EWS::SOAP.ExchangeUserConfiguration.get_user_configuration
|
validation
|
def get_user_configuration(opts)
opts = opts.clone
[:user_config_name, :user_config_props].each do |k|
validate_param(opts, k, true)
end
req = build_soap! do |type, builder|
if(type == :header)
else
builder.nbuild.GetUserConfiguration {|x|
x.parent.default_namespace = @default_ns
builder.user_configuration_name!(opts[:user_config_name])
|
ruby
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.