_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
66
10.5k
language
stringclasses
1 value
meta_information
dict
q12100
Generamba.CatalogDownloader.update_all_catalogs_and_return_filepaths
train
def update_all_catalogs_and_return_filepaths does_rambafile_exist = Dir[RAMBAFILE_NAME].count > 0 if does_rambafile_exist rambafile = YAML.load_file(RAMBAFILE_NAME) catalogs = rambafile[CATALOGS_KEY] end terminator = CatalogTerminator.new terminator.remove_all_catalogs ...
ruby
{ "resource": "" }
q12101
Generamba.CatalogDownloader.download_catalog
train
def download_catalog(name, url) catalogs_local_path = Pathname.new(ENV['HOME']) .join(GENERAMBA_HOME_DIR) .join(CATALOGS_DIR) current_catalog_path = catalogs_local_path .join(name) if File.exists?(current_c...
ruby
{ "resource": "" }
q12102
Generamba.TemplateInstallerFactory.installer_for_type
train
def installer_for_type(type) case type when TemplateDeclarationType::LOCAL_TEMPLATE return Generamba::LocalInstaller.new when TemplateDeclarationType::REMOTE_TEMPLATE return Generamba::RemoteInstaller.new when TemplateDeclarationType::CATALOG_TEMPLATE return G...
ruby
{ "resource": "" }
q12103
Generamba.CatalogInstaller.browse_catalog_for_a_template
train
def browse_catalog_for_a_template(catalog_path, template_name) template_path = catalog_path.join(template_name) if Dir.exist?(template_path) return template_path end return nil end
ruby
{ "resource": "" }
q12104
Generamba.TemplateProcessor.install_templates
train
def install_templates(rambafile) # We always clear previously installed templates to avoid conflicts in different versions clear_installed_templates templates = rambafile[TEMPLATES_KEY] if !templates || templates.count == 0 puts 'You must specify at least one template in Rambafile unde...
ruby
{ "resource": "" }
q12105
Generamba.TemplateProcessor.clear_installed_templates
train
def clear_installed_templates install_path = Pathname.new(TEMPLATES_FOLDER) FileUtils.rm_rf(Dir.glob(install_path)) end
ruby
{ "resource": "" }
q12106
Generamba.TemplateProcessor.update_catalogs_if_needed
train
def update_catalogs_if_needed(catalogs, templates) needs_update = templates.any? {|template| template.type == TemplateDeclarationType::CATALOG_TEMPLATE} return unless needs_update terminator = CatalogTerminator.new terminator.remove_all_catalogs puts('Updating shared generamba-catalog sp...
ruby
{ "resource": "" }
q12107
Xcodeproj.XCScheme.configure_with_targets
train
def configure_with_targets(runnable_target, test_target, launch_target: false) if runnable_target add_build_target(runnable_target) set_launch_target(runnable_target) if launch_target end if test_target add_build_target(test_target, false) if test_target != runnable_target ...
ruby
{ "resource": "" }
q12108
Xcodeproj.XCScheme.set_launch_target
train
def set_launch_target(build_target) launch_runnable = BuildableProductRunnable.new(build_target, 0) launch_action.buildable_product_runnable = launch_runnable profile_runnable = BuildableProductRunnable.new(build_target) profile_action.buildable_product_runnable = profile_runnable macro_...
ruby
{ "resource": "" }
q12109
Xcodeproj.XCScheme.save_as
train
def save_as(project_path, name, shared = true) scheme_folder_path = if shared self.class.shared_data_dir(project_path) else self.class.user_data_dir(project_path) end scheme_folder_path.mkpath ...
ruby
{ "resource": "" }
q12110
Xcodeproj.Project.initialize_from_file
train
def initialize_from_file pbxproj_path = path + 'project.pbxproj' plist = Plist.read_from_path(pbxproj_path.to_s) root_object.remove_referrer(self) if root_object @root_object = new_from_plist(plist['rootObject'], plist['objects'], self) @archive_version = plist['archiveVersion'] ...
ruby
{ "resource": "" }
q12111
Xcodeproj.Project.to_tree_hash
train
def to_tree_hash hash = {} objects_dictionary = {} hash['objects'] = objects_dictionary hash['archiveVersion'] = archive_version.to_s hash['objectVersion'] = object_version.to_s hash['classes'] = classes hash['rootObject'] = root_object.to_tree_hash ...
ruby
{ "resource": "" }
q12112
Xcodeproj.Project.generate_available_uuid_list
train
def generate_available_uuid_list(count = 100) new_uuids = (0..count).map { SecureRandom.hex(12).upcase } uniques = (new_uuids - (@generated_uuids + uuids)) @generated_uuids += uniques @available_uuids += uniques end
ruby
{ "resource": "" }
q12113
Xcodeproj.Project.reference_for_path
train
def reference_for_path(absolute_path) absolute_pathname = Pathname.new(absolute_path) unless absolute_pathname.absolute? raise ArgumentError, "Paths must be absolute #{absolute_path}" end objects.find do |child| child.isa == 'PBXFileReference' && child.real_path == absolute_pat...
ruby
{ "resource": "" }
q12114
Xcodeproj.Project.embedded_targets_in_native_target
train
def embedded_targets_in_native_target(native_target) native_targets.select do |target| host_targets_for_embedded_target(target).map(&:uuid).include? native_target.uuid end end
ruby
{ "resource": "" }
q12115
Xcodeproj.Project.host_targets_for_embedded_target
train
def host_targets_for_embedded_target(embedded_target) native_targets.select do |native_target| ((embedded_target.uuid != native_target.uuid) && (native_target.dependencies.map(&:native_target_uuid).include? embedded_target.uuid)) end end
ruby
{ "resource": "" }
q12116
Xcodeproj.Project.new_resources_bundle
train
def new_resources_bundle(name, platform, product_group = nil) product_group ||= products_group ProjectHelper.new_resources_bundle(self, name, platform, product_group) end
ruby
{ "resource": "" }
q12117
Xcodeproj.Project.add_build_configuration
train
def add_build_configuration(name, type) build_configuration_list = root_object.build_configuration_list if build_configuration = build_configuration_list[name] build_configuration else build_configuration = new(XCBuildConfiguration) build_configuration.name = name commo...
ruby
{ "resource": "" }
q12118
Xcodeproj.Config.save_as
train
def save_as(pathname, prefix = nil) if File.exist?(pathname) return if Config.new(pathname) == self end pathname.open('w') { |file| file << to_s(prefix) } end
ruby
{ "resource": "" }
q12119
Xcodeproj.Config.hash_from_file_content
train
def hash_from_file_content(string) hash = {} string.split("\n").each do |line| uncommented_line = strip_comment(line) if include = extract_include(uncommented_line) @includes.push normalized_xcconfig_path(include) else key, value = extract_key_value(uncommented_li...
ruby
{ "resource": "" }
q12120
Xcodeproj.Config.merge_attributes!
train
def merge_attributes!(attributes) @attributes.merge!(attributes) do |_, v1, v2| v1 = v1.strip v2 = v2.strip v1_split = v1.shellsplit v2_split = v2.shellsplit if (v2_split - v1_split).empty? || v1_split.first(v2_split.size) == v2_split v1 elsif v2_split.fir...
ruby
{ "resource": "" }
q12121
Xcodeproj.Config.extract_key_value
train
def extract_key_value(line) match = line.match(KEY_VALUE_PATTERN) if match key = match[1] value = match[2] [key.strip, value.strip] else [] end end
ruby
{ "resource": "" }
q12122
SpecHelper.ProjectHelper.compare_settings
train
def compare_settings(produced, expected, params) it 'should match build settings' do # Find faulty settings in different categories missing_settings = expected.keys.reject { |k| produced.key?(k) } unexpected_settings = produced.keys.reject { |k| expected.key?(k) } wrong_settings...
ruby
{ "resource": "" }
q12123
SpecHelper.ProjectHelper.load_settings
train
def load_settings(path, type) # Load fixture base_path = Pathname(fixture_path("CommonBuildSettings/configs/#{path}")) config_fixture = base_path + "#{path}_#{type}.xcconfig" config = Xcodeproj::Config.new(config_fixture) settings = config.to_hash # Filter exclusions settings ...
ruby
{ "resource": "" }
q12124
Xcodeproj.Workspace.save_as
train
def save_as(path) FileUtils.mkdir_p(path) File.open(File.join(path, 'contents.xcworkspacedata'), 'w') do |out| out << to_s end end
ruby
{ "resource": "" }
q12125
Xcodeproj.Workspace.load_schemes_from_project
train
def load_schemes_from_project(project_full_path) schemes = Xcodeproj::Project.schemes project_full_path schemes.each do |scheme_name| @schemes[scheme_name] = project_full_path end end
ruby
{ "resource": "" }
q12126
EPUBMaker.EPUBCommon.container
train
def container @opf_path = opf_path tmplfile = File.expand_path('./xml/container.xml.erb', ReVIEW::Template::TEMPLATE_DIR) tmpl = ReVIEW::Template.load(tmplfile) tmpl.result(binding) end
ruby
{ "resource": "" }
q12127
EPUBMaker.EPUBCommon.mytoc
train
def mytoc @title = CGI.escapeHTML(@producer.res.v('toctitle')) @body = %Q( <h1 class="toc-title">#{CGI.escapeHTML(@producer.res.v('toctitle'))}</h1>\n) if @producer.config['epubmaker']['flattoc'].nil? @body << hierarchy_ncx('ul') else @body << flat_ncx('ul', @producer.config['e...
ruby
{ "resource": "" }
q12128
ReVIEW.Compiler.compile_inline
train
def compile_inline(str) op, arg = /\A@<(\w+)>\{(.*?)\}\z/.match(str).captures unless inline_defined?(op) raise CompileError, "no such inline op: #{op}" end unless @strategy.respond_to?("inline_#{op}") raise "strategy does not support inline op: @<#{op}>" end @strategy...
ruby
{ "resource": "" }
q12129
EPUBMaker.Producer.load
train
def load(file) if file.nil? || !File.exist?(file) raise "Can't open #{file}." end loader = ReVIEW::YAMLLoader.new merge_config(@config.deep_merge(loader.load_file(file))) end
ruby
{ "resource": "" }
q12130
EPUBMaker.Producer.merge_config
train
def merge_config(config) @config.deep_merge!(config) complement unless @config['epubversion'].nil? case @config['epubversion'].to_i when 2 @epub = EPUBMaker::EPUBv2.new(self) when 3 @epub = EPUBMaker::EPUBv3.new(self) else raise "Invalid E...
ruby
{ "resource": "" }
q12131
EPUBMaker.Producer.mimetype
train
def mimetype(wobj) s = @epub.mimetype if !s.nil? && !wobj.nil? wobj.print s end end
ruby
{ "resource": "" }
q12132
EPUBMaker.Producer.opf
train
def opf(wobj) s = @epub.opf if !s.nil? && !wobj.nil? wobj.puts s end end
ruby
{ "resource": "" }
q12133
EPUBMaker.Producer.ncx
train
def ncx(wobj, indentarray = []) s = @epub.ncx(indentarray) if !s.nil? && !wobj.nil? wobj.puts s end end
ruby
{ "resource": "" }
q12134
EPUBMaker.Producer.container
train
def container(wobj) s = @epub.container if !s.nil? && !wobj.nil? wobj.puts s end end
ruby
{ "resource": "" }
q12135
EPUBMaker.Producer.colophon
train
def colophon(wobj) s = @epub.colophon if !s.nil? && !wobj.nil? wobj.puts s end end
ruby
{ "resource": "" }
q12136
EPUBMaker.Producer.mytoc
train
def mytoc(wobj) s = @epub.mytoc if !s.nil? && !wobj.nil? wobj.puts s end end
ruby
{ "resource": "" }
q12137
EPUBMaker.EPUBv2.ncx
train
def ncx(indentarray) @ncx_isbn = ncx_isbn @ncx_doctitle = ncx_doctitle @ncx_navmap = ncx_navmap(indentarray) tmplfile = File.expand_path('./ncx/epubv2.ncx.erb', ReVIEW::Template::TEMPLATE_DIR) ReVIEW::Template.load(tmplfile).result(binding) end
ruby
{ "resource": "" }
q12138
EPUBMaker.EPUBv2.produce
train
def produce(epubfile, basedir, tmpdir) produce_write_common(basedir, tmpdir) File.open("#{tmpdir}/OEBPS/#{@producer.config['bookname']}.ncx", 'w') do |f| @producer.ncx(f, @producer.config['epubmaker']['ncxindent']) end if @producer.config['mytoc'] File.open("#{tmpdir}/OEBPS/#{@p...
ruby
{ "resource": "" }
q12139
ReVIEW.LATEXBuilder.inline_i
train
def inline_i(str) if @book.config.check_version('2', exception: false) macro('textit', escape(str)) else macro('reviewit', escape(str)) end end
ruby
{ "resource": "" }
q12140
ReVIEW.YAMLLoader.load_file
train
def load_file(yamlfile) file_queue = [File.expand_path(yamlfile)] loaded_files = {} yaml = {} loop do # Check exit condition return yaml if file_queue.empty? current_file = file_queue.shift current_yaml = YAML.load_file(current_file) yaml = current_yaml....
ruby
{ "resource": "" }
q12141
EPUBMaker.Content.complement
train
def complement if @id.nil? @id = @file.gsub(%r{[\\/\. ]}, '-') end if @id =~ /\A[^a-z]/i @id = "rv-#{@id}" end if !@file.nil? && @media.nil? @media = @file.sub(/.+\./, '').downcase end case @media when 'xhtml', 'xml', 'html' @media = 'app...
ruby
{ "resource": "" }
q12142
Split.Trial.choose!
train
def choose!(context = nil) @user.cleanup_old_experiments! # Only run the process once return alternative if @alternative_choosen if override_is_alternative? self.alternative = @options[:override] if should_store_alternative? && !@user[@experiment.key] self.alternative....
ruby
{ "resource": "" }
q12143
Mysql2.Client.parse_connect_attrs
train
def parse_connect_attrs(conn_attrs) return {} if Mysql2::Client::CONNECT_ATTRS.zero? conn_attrs ||= {} conn_attrs[:program_name] ||= $PROGRAM_NAME conn_attrs.each_with_object({}) do |(key, value), hash| hash[key.to_s] = value.to_s end end
ruby
{ "resource": "" }
q12144
Mysql2.Error.clean_message
train
def clean_message(message) if @server_version && @server_version > 50500 message.encode(ENCODE_OPTS) else message.encode(Encoding::UTF_8, ENCODE_OPTS) end end
ruby
{ "resource": "" }
q12145
RspecApiDocumentation.DSL.resource
train
def resource(*args, &block) options = args.last.is_a?(Hash) ? args.pop : {} options[:api_doc_dsl] = :resource options[:resource_name] = args.first.to_s options[:document] = :all unless options.key?(:document) args.push(options) describe(*args, &block) end
ruby
{ "resource": "" }
q12146
RspecApiDocumentation.Configuration.define_group
train
def define_group(name, &block) subconfig = self.class.new(self) subconfig.filter = name subconfig.docs_dir = self.docs_dir.join(name.to_s) yield subconfig groups << subconfig end
ruby
{ "resource": "" }
q12147
ActiveRecordQueryTrace.CustomLogSubscriber.lines_to_display
train
def lines_to_display(full_trace) ActiveRecordQueryTrace.lines.zero? ? full_trace : full_trace.first(ActiveRecordQueryTrace.lines) end
ruby
{ "resource": "" }
q12148
ActiveRecordQueryTrace.CustomLogSubscriber.setup_backtrace_cleaner_path
train
def setup_backtrace_cleaner_path return unless Rails.backtrace_cleaner.instance_variable_get(:@root) == '/' Rails.backtrace_cleaner.instance_variable_set :@root, Rails.root.to_s end
ruby
{ "resource": "" }
q12149
Stripe.StripeObject.update_attributes
train
def update_attributes(values, opts = {}, dirty: true) values.each do |k, v| add_accessors([k], values) unless metaclass.method_defined?(k.to_sym) @values[k] = Util.convert_to_stripe_object(v, opts) dirty_value!(@values[k]) if dirty @unsaved_values.add(k) end end
ruby
{ "resource": "" }
q12150
Stripe.StripeObject.empty_values
train
def empty_values(obj) values = case obj when Hash then obj when StripeObject then obj.instance_variable_get(:@values) else raise ArgumentError, "#empty_values got unexpected object type: #{obj.class.name}" end values.each_...
ruby
{ "resource": "" }
q12151
Stripe.ListObject.auto_paging_each
train
def auto_paging_each(&blk) return enum_for(:auto_paging_each) unless block_given? page = self loop do page.each(&blk) page = page.next_page break if page.empty? end end
ruby
{ "resource": "" }
q12152
Stripe.StripeClient.format_app_info
train
def format_app_info(info) str = info[:name] str = "#{str}/#{info[:version]}" unless info[:version].nil? str = "#{str} (#{info[:url]})" unless info[:url].nil? str end
ruby
{ "resource": "" }
q12153
Stripe.StripeClient.specific_oauth_error
train
def specific_oauth_error(resp, error_code, context) description = resp.data[:error_description] || error_code Util.log_error("Stripe OAuth error", status: resp.http_status, error_code: error_code, error_description: description, ...
ruby
{ "resource": "" }
q12154
AwesomePrint.ActiveRecord.awesome_active_record_instance
train
def awesome_active_record_instance(object) return object.inspect if !defined?(::ActiveSupport::OrderedHash) return awesome_object(object) if @options[:raw] data = if object.class.column_names != object.attributes.keys object.attributes else object.class.colu...
ruby
{ "resource": "" }
q12155
AwesomePrint.Ripple.awesome_ripple_document_instance
train
def awesome_ripple_document_instance(object) return object.inspect if !defined?(::ActiveSupport::OrderedHash) return awesome_object(object) if @options[:raw] exclude_assoc = @options[:exclude_assoc] or @options[:exclude_associations] data = object.attributes.inject(::ActiveSupport::OrderedHash....
ruby
{ "resource": "" }
q12156
AwesomePrint.MongoMapper.awesome_mongo_mapper_instance
train
def awesome_mongo_mapper_instance(object) return object.inspect if !defined?(::ActiveSupport::OrderedHash) return awesome_object(object) if @options[:raw] data = object.keys.keys.sort_by { |k| k }.inject(::ActiveSupport::OrderedHash.new) do |hash, name| hash[name] = object[name] hash ...
ruby
{ "resource": "" }
q12157
AwesomePrint.ActionView.ap_debug
train
def ap_debug(object, options = {}) object.ai( options.merge(html: true) ).sub( /^<pre([\s>])/, '<pre class="debug_dump"\\1' ) end
ruby
{ "resource": "" }
q12158
ComfortableMexicanSofa::ActsAsTree.InstanceMethods.ancestors
train
def ancestors node = self nodes = [] nodes << node = node.parent while node.parent nodes end
ruby
{ "resource": "" }
q12159
ComfortableMexicanSofa::ActsAsTree.InstanceMethods.descendants
train
def descendants nodes = [] children.each do |c| nodes << c nodes << c.descendants end nodes.flatten end
ruby
{ "resource": "" }
q12160
ComfortableMexicanSofa::Seeds.Exporter.export!
train
def export!(classes = nil) classes ||= SEED_CLASSES classes.each do |klass| klass = "ComfortableMexicanSofa::Seeds::#{klass}::Exporter" klass.constantize.new(from, to).export! end end
ruby
{ "resource": "" }
q12161
ComfortableMexicanSofa::Seeds.Exporter.write_file_content
train
def write_file_content(path, data) ::File.open(::File.join(path), "wb") do |f| data.each do |item| f.write("[#{item[:header]}]\n") f.write("#{item[:content]}\n") end end end
ruby
{ "resource": "" }
q12162
ComfortableMexicanSofa::Seeds::Page.Exporter.fragments_data
train
def fragments_data(record, page_path) record.fragments.collect do |frag| header = "#{frag.tag} #{frag.identifier}" content = case frag.tag when "datetime", "date" frag.datetime when "checkbox" frag.boolean when "file", "files" ...
ruby
{ "resource": "" }
q12163
ComfortableMexicanSofa::Seeds::Page.Importer.import_translations
train
def import_translations(path, page) old_translations = page.translations.pluck(:locale) new_translations = [] Dir["#{path}content.*.html"].each do |file_path| locale = File.basename(file_path).match(%r{content\.(\w+)\.html})[1] new_translations << locale translation = page.tr...
ruby
{ "resource": "" }
q12164
ComfortableMexicanSofa::Seeds::Page.Importer.construct_fragments_attributes
train
def construct_fragments_attributes(hash, record, path) frag_identifiers = [] frag_attributes = hash.collect do |frag_header, frag_content| tag, identifier = frag_header.split frag_hash = { identifier: identifier, tag: tag } # tracking fragments tha...
ruby
{ "resource": "" }
q12165
ComfortableMexicanSofa::Seeds::Page.Importer.files_content
train
def files_content(record, identifier, path, frag_content) # preparing attachments files = frag_content.split("\n").collect do |filename| file_handler = File.open(File.join(path, filename)) { io: file_handler, filename: filename, content_type: MimeM...
ruby
{ "resource": "" }
q12166
Comfy.CmsHelper.cms_fragment_render
train
def cms_fragment_render(identifier, page = @cms_page) node = page.fragment_nodes.detect { |n| n.identifier == identifier.to_s } return "" unless node node.renderable = true render inline: page.render([node]) end
ruby
{ "resource": "" }
q12167
Comfy.CmsHelper.cms_snippet_render
train
def cms_snippet_render(identifier, cms_site = @cms_site) cms_site ||= cms_site_detect snippet = cms_site&.snippets&.find_by_identifier(identifier) return "" unless snippet r = ComfortableMexicanSofa::Content::Renderer.new(snippet) render inline: r.render(r.nodes(r.tokenize(snippet.content)...
ruby
{ "resource": "" }
q12168
Comfy.CmsHelper.comfy_paginate
train
def comfy_paginate(collection) return unless collection if defined?(WillPaginate) will_paginate collection elsif defined?(Kaminari) paginate collection, theme: "comfy" end end
ruby
{ "resource": "" }
q12169
JIRA.Client.post
train
def post(path, body = '', headers = {}) headers = { 'Content-Type' => 'application/json' }.merge(headers) request(:post, path, body, merge_default_headers(headers)) end
ruby
{ "resource": "" }
q12170
JIRA.Base.respond_to?
train
def respond_to?(method_name, _include_all = false) if attrs.key?(method_name.to_s) true else super(method_name) end end
ruby
{ "resource": "" }
q12171
JIRA.Base.method_missing
train
def method_missing(method_name, *_args) if attrs.key?(method_name.to_s) attrs[method_name.to_s] else super(method_name) end end
ruby
{ "resource": "" }
q12172
JIRA.Base.fetch
train
def fetch(reload = false, query_params = {}) return if expanded? && !reload response = client.get(url_with_query_params(url, query_params)) set_attrs_from_response(response) @expanded = true end
ruby
{ "resource": "" }
q12173
JIRA.Base.set_attrs_from_response
train
def set_attrs_from_response(response) unless response.body.nil? || (response.body.length < 2) json = self.class.parse_json(response.body) set_attrs(json) end end
ruby
{ "resource": "" }
q12174
JIRA.Base.set_attrs
train
def set_attrs(hash, clobber = true, target = nil) target ||= @attrs if clobber target.merge!(hash) hash else hash.each do |k, v| if v.is_a?(Hash) set_attrs(v, clobber, target[k]) else target[k] = v end end end ...
ruby
{ "resource": "" }
q12175
Que.JobMethods._run
train
def _run(args: nil, reraise_errors: false) if args.nil? && que_target args = que_target.que_attrs.fetch(:args) end run(*args) default_resolve_action if que_target && !que_target.que_resolved rescue => error raise error unless que_target que_target.que_error = error ...
ruby
{ "resource": "" }
q12176
Que.JobMethods.handle_error
train
def handle_error(error) return unless que_target max = resolve_que_setting(:maximum_retry_count) if max && error_count > max expire else retry_in_default_interval end end
ruby
{ "resource": "" }
q12177
Que.JobMethods.retry_in
train
def retry_in(period) return unless que_target if id = que_target.que_attrs[:id] values = [period] if e = que_target.que_error values << "#{e.class}: #{e.message}".slice(0, 500) << e.backtrace.join("\n").slice(0, 10000) else values << nil << nil end ...
ruby
{ "resource": "" }
q12178
Que.JobBuffer.push
train
def push(*metajobs) Que.internal_log(:job_buffer_push, self) do { maximum_size: maximum_size, ids: metajobs.map(&:id), current_queue: to_a, } end sync do return metajobs if _stopping? @array.concat(metajobs).sort! # Re...
ruby
{ "resource": "" }
q12179
Middleman.DnsResolver.ips_for
train
def ips_for(name) resolvers.each do |r| ips = r.getaddresses(name) return ips unless ips.nil? || ips.empty? end [] end
ruby
{ "resource": "" }
q12180
Middleman.ConfigContext.mime_type
train
def mime_type(type, value) type = ".#{type}" unless type.to_s[0] == '.' ::Rack::Mime::MIME_TYPES[type] = value end
ruby
{ "resource": "" }
q12181
Middleman.ExtensionManager.activate
train
def activate(ext_name, options_hash = ::Middleman::EMPTY_HASH, &block) begin extension = ::Middleman::Extensions.load(ext_name) rescue LoadError => e logger.debug "== Failed Activation `#{ext_name}` : #{e.message}" return end logger.debug "== Activating: #{ext_name}" ...
ruby
{ "resource": "" }
q12182
Middleman.Application.apply_cli_options
train
def apply_cli_options config[:cli_options].each do |k, v| setting = config.setting(k.to_sym) next unless setting v = setting.options[:import].call(v) if setting.options[:import] config[k.to_sym] = v end end
ruby
{ "resource": "" }
q12183
Middleman.Application.prune_tilt_templates!
train
def prune_tilt_templates! mapping = ::Tilt.default_mapping mapping.lazy_map.each_key do |key| begin mapping[key] rescue LoadError, NameError end end mapping.lazy_map.clear end
ruby
{ "resource": "" }
q12184
Middleman::Cli.Extension.extension
train
def extension copy_file 'extension/gitignore', File.join(name, '.gitignore') unless options[:'skip-git'] template 'extension/Rakefile', File.join(name, 'Rakefile') template 'extension/gemspec', File.join(name, "#{name}.gemspec") template 'extension/Gemfile', File.join(name, 'Gemfile') temp...
ruby
{ "resource": "" }
q12185
Middleman.Extension.add_exposed_to_context
train
def add_exposed_to_context(context) (self.class.exposed_to_template || {}).each do |k, v| context.define_singleton_method(k, &method(v)) end end
ruby
{ "resource": "" }
q12186
Middleman::Cli.Init.init
train
def init require 'fileutils' require 'tmpdir' unless git_present? msg = 'You need to install the git command line tool to initialize a new project. ' msg << "For help installing git, please refer to GitHub's tutorial at https://help.github.com/articles/set-up-git" say msg, :r...
ruby
{ "resource": "" }
q12187
Middleman::Cli.Init.which
train
def which(executable) if File.file?(executable) && File.executable?(executable) executable elsif ENV['PATH'] path = ENV['PATH'].split(File::PATH_SEPARATOR).find do |p| abs_path = File.join(p, executable) File.file?(abs_path) && File.executable?(abs_path) end ...
ruby
{ "resource": "" }
q12188
Middleman::Cli.Build.build
train
def build root = ENV['MM_ROOT'] || Dir.pwd raise Thor::Error, 'Error: Could not find a Middleman project config, perhaps you are in the wrong folder?' unless File.exist?(File.join(root, 'config.rb')) require 'middleman-core' require 'middleman-core/logger' require 'middleman-core/builder...
ruby
{ "resource": "" }
q12189
Middleman::Cli.Build.on_event
train
def on_event(event_type, target, extra = nil) case event_type when :error say_status :error, target, :red shell.say extra, :red if options['verbose'] || options['bail'] raise 'Build error' if options['bail'] when :deleted say_status :remove, target, :green when :...
ruby
{ "resource": "" }
q12190
Middleman::Cli.Build.clean_directories!
train
def clean_directories! all_build_files = File.join(@app.config[:build_dir], '**', '*') empty_directories = Dir[all_build_files].select do |d| File.directory?(d) end empty_directories.each do |d| remove_file d, force: true if Pathname(d).children.empty? end end
ruby
{ "resource": "" }
q12191
Middleman.Rack.process_request
train
def process_request(env, req, res) start_time = Time.now request_path = URI.decode(env['PATH_INFO'].dup) request_path.force_encoding('UTF-8') if request_path.respond_to? :force_encoding request_path = ::Middleman::Util.full_path(request_path, @middleman) full_request_path = File.join(env[...
ruby
{ "resource": "" }
q12192
Middleman.Rack.not_found
train
def not_found(res, path) path = ::Rack::Utils.escape_html(path) res.status = 404 res.write "<html><head></head><body><h1>File Not Found</h1><p>#{path}</p></body></html>" res.finish end
ruby
{ "resource": "" }
q12193
Middleman.Rack.send_file
train
def send_file(resource, env) file = ::Rack::File.new nil path = resource.file_descriptor[:full_path] if !file.respond_to?(:path=) request = ::Rack::Request.new(env) response = file.serving(request, path) else file.path = path response = file.serving(env) ...
ruby
{ "resource": "" }
q12194
Middleman::Cli.Server.server
train
def server require 'middleman-core' require 'middleman-core/preview_server' unless ENV['MM_ROOT'] puts '== Could not find a Middleman project config.rb' exit end params = { debug: options['verbose'], instrumenting: options['instrument'], reload_pat...
ruby
{ "resource": "" }
q12195
Middleman.TemplateContext.wrap_layout
train
def wrap_layout(layout_name, &block) # Save current buffer for later buf_was = save_buffer # Find a layout for this file layout_file = ::Middleman::TemplateRenderer.locate_layout(@app, layout_name, current_engine) # Get the layout engine extension = File.extname(layout_file[:relati...
ruby
{ "resource": "" }
q12196
Middleman.TemplateContext.render_file
train
def render_file(file, locs, opts, &block) _render_with_all_renderers(file[:relative_path].to_s, locs, self, opts, &block) end
ruby
{ "resource": "" }
q12197
Middleman.Util.glob_directory
train
def glob_directory(path) results = ::Dir[path] return results unless RUBY_PLATFORM =~ /darwin/ results.map { |r| r.encode('UTF-8', 'UTF-8-MAC') } end
ruby
{ "resource": "" }
q12198
Razorpay.Request.create_instance
train
def create_instance(res) response = res.parsed_response # if there was an error, throw it raise_error(response['error'], res.code) if response.nil? || response.key?('error') # There must be a top level entity # This is either one of payment, refund, or collection at present begin ...
ruby
{ "resource": "" }
q12199
AttrEncrypted.InstanceMethods.decrypt
train
def decrypt(attribute, encrypted_value) encrypted_attributes[attribute.to_sym][:operation] = :decrypting encrypted_attributes[attribute.to_sym][:value_present] = self.class.not_empty?(encrypted_value) self.class.decrypt(attribute, encrypted_value, evaluated_attr_encrypted_options_for(attribute)) e...
ruby
{ "resource": "" }