_id
stringlengths
2
6
title
stringlengths
9
130
partition
stringclasses
3 values
text
stringlengths
66
10.5k
language
stringclasses
1 value
meta_information
dict
q11700
Hutch.Broker.unbind_redundant_bindings
train
def unbind_redundant_bindings(queue, routing_keys) return unless http_api_use_enabled? bindings.each do |dest, keys| next unless dest == queue.name keys.reject { |key| routing_keys.include?(key) }.each do |key| logger.debug "removing redundant binding #{queue.name} <--> #{key}" queue.unbind(exchange, routing_key: key) end end end
ruby
{ "resource": "" }
q11701
Hutch.Broker.bind_queue
train
def bind_queue(queue, routing_keys) unbind_redundant_bindings(queue, routing_keys) # Ensure all the desired bindings are present routing_keys.each do |routing_key| logger.debug "creating binding #{queue.name} <--> #{routing_key}" queue.bind(exchange, routing_key: routing_key) end end
ruby
{ "resource": "" }
q11702
Hutch.CLI.run
train
def run(argv = ARGV) Hutch::Config.initialize parse_options(argv) daemonise_process write_pid if Hutch::Config.pidfile Hutch.logger.info "hutch booted with pid #{::Process.pid}" if load_app && start_work_loop == :success # If we got here, the worker was shut down nicely Hutch.logger.info 'hutch shut down gracefully' exit 0 else Hutch.logger.info 'hutch terminated due to an error' exit 1 end end
ruby
{ "resource": "" }
q11703
Geokit.Bounds.contains?
train
def contains?(point) point = Geokit::LatLng.normalize(point) res = point.lat > @sw.lat && point.lat < @ne.lat if crosses_meridian? res &= point.lng < @ne.lng || point.lng > @sw.lng else res &= point.lng < @ne.lng && point.lng > @sw.lng end res end
ruby
{ "resource": "" }
q11704
Geokit.GeoLoc.to_geocodeable_s
train
def to_geocodeable_s a = [street_address, district, city, state, zip, country_code].compact a.delete_if { |e| !e || e == '' } a.join(', ') end
ruby
{ "resource": "" }
q11705
ClosureTree.HashTreeSupport.build_hash_tree
train
def build_hash_tree(tree_scope) tree = ActiveSupport::OrderedHash.new id_to_hash = {} tree_scope.each do |ea| h = id_to_hash[ea.id] = ActiveSupport::OrderedHash.new (id_to_hash[ea._ct_parent_id] || tree)[ea] = h end tree end
ruby
{ "resource": "" }
q11706
ClosureTree.Finders.find_or_create_by_path
train
def find_or_create_by_path(path, attributes = {}) subpath = _ct.build_ancestry_attr_path(path, attributes) return self if subpath.empty? found = find_by_path(subpath, attributes) return found if found attrs = subpath.shift _ct.with_advisory_lock do # shenanigans because children.create is bound to the superclass # (in the case of polymorphism): child = self.children.where(attrs).first || begin # Support STI creation by using base_class: _ct.create(self.class, attrs).tap do |ea| # We know that there isn't a cycle, because we just created it, and # cycle detection is expensive when the node is deep. ea._ct_skip_cycle_detection! self.children << ea end end child.find_or_create_by_path(subpath, attributes) end end
ruby
{ "resource": "" }
q11707
Hyrax.HyraxHelperBehavior.iconify_auto_link
train
def iconify_auto_link(field, show_link = true) if field.is_a? Hash options = field[:config].separator_options || {} text = field[:value].to_sentence(options) else text = field end # this block is only executed when a link is inserted; # if we pass text containing no links, it just returns text. auto_link(html_escape(text)) do |value| "<span class='glyphicon glyphicon-new-window'></span>#{('&nbsp;' + value) if show_link}" end end
ruby
{ "resource": "" }
q11708
Hyrax.UserStatImporter.sorted_users
train
def sorted_users users = [] ::User.find_each do |user| users.push(UserRecord.new(user.id, user.user_key, date_since_last_cache(user))) end users.sort_by(&:last_stats_update) end
ruby
{ "resource": "" }
q11709
Hyrax.UserStatImporter.rescue_and_retry
train
def rescue_and_retry(fail_message) Retriable.retriable(retry_options) do return yield end rescue StandardError => exception log_message fail_message log_message "Last exception #{exception}" end
ruby
{ "resource": "" }
q11710
Hyrax.LeasesControllerBehavior.destroy
train
def destroy Hyrax::Actors::LeaseActor.new(curation_concern).destroy flash[:notice] = curation_concern.lease_history.last if curation_concern.work? && curation_concern.file_sets.present? redirect_to confirm_permission_path else redirect_to edit_lease_path end end
ruby
{ "resource": "" }
q11711
Hyrax.CollectionBehavior.bytes
train
def bytes return 0 if member_object_ids.empty? raise "Collection must be saved to query for bytes" if new_record? # One query per member_id because Solr is not a relational database member_object_ids.collect { |work_id| size_for_work(work_id) }.sum end
ruby
{ "resource": "" }
q11712
Hyrax.CollectionBehavior.size_for_work
train
def size_for_work(work_id) argz = { fl: "id, #{file_size_field}", fq: "{!join from=#{member_ids_field} to=id}id:#{work_id}" } files = ::FileSet.search_with_conditions({}, argz) files.reduce(0) { |sum, f| sum + f[file_size_field].to_i } end
ruby
{ "resource": "" }
q11713
Hyrax.AdminSetService.search_results_with_work_count
train
def search_results_with_work_count(access, join_field: "isPartOf_ssim") admin_sets = search_results(access) ids = admin_sets.map(&:id).join(',') query = "{!terms f=#{join_field}}#{ids}" results = ActiveFedora::SolrService.instance.conn.get( ActiveFedora::SolrService.select_path, params: { fq: query, rows: 0, 'facet.field' => join_field } ) counts = results['facet_counts']['facet_fields'][join_field].each_slice(2).to_h file_counts = count_files(admin_sets) admin_sets.map do |admin_set| SearchResultForWorkCount.new(admin_set, counts[admin_set.id].to_i, file_counts[admin_set.id].to_i) end end
ruby
{ "resource": "" }
q11714
Hyrax.AdminSetService.count_files
train
def count_files(admin_sets) file_counts = Hash.new(0) admin_sets.each do |admin_set| query = "{!join from=file_set_ids_ssim to=id}isPartOf_ssim:#{admin_set.id}" file_results = ActiveFedora::SolrService.instance.conn.get( ActiveFedora::SolrService.select_path, params: { fq: [query, "has_model_ssim:FileSet"], rows: 0 } ) file_counts[admin_set.id] = file_results['response']['numFound'] end file_counts end
ruby
{ "resource": "" }
q11715
Hyrax.Configuration.register_curation_concern
train
def register_curation_concern(*curation_concern_types) Array.wrap(curation_concern_types).flatten.compact.each do |cc_type| @registered_concerns << cc_type unless @registered_concerns.include?(cc_type) end end
ruby
{ "resource": "" }
q11716
Hyrax.AdminSetOptionsPresenter.select_options
train
def select_options(access = :deposit) @service.search_results(access).map do |admin_set| [admin_set.to_s, admin_set.id, data_attributes(admin_set)] end end
ruby
{ "resource": "" }
q11717
Hyrax.AdminSetOptionsPresenter.data_attributes
train
def data_attributes(admin_set) # Get permission template associated with this AdminSet (if any) permission_template = PermissionTemplate.find_by(source_id: admin_set.id) # Only add data attributes if permission template exists return {} unless permission_template attributes_for(permission_template: permission_template) end
ruby
{ "resource": "" }
q11718
Hyrax.AdminSetOptionsPresenter.sharing?
train
def sharing?(permission_template:) wf = workflow(permission_template: permission_template) return false unless wf wf.allows_access_grant? end
ruby
{ "resource": "" }
q11719
Hyrax.LocalFileDownloadsControllerBehavior.send_local_content
train
def send_local_content response.headers['Accept-Ranges'] = 'bytes' if request.head? local_content_head elsif request.headers['Range'] send_range_for_local_file else send_local_file_contents end end
ruby
{ "resource": "" }
q11720
Hyrax.LocalFileDownloadsControllerBehavior.send_range_for_local_file
train
def send_range_for_local_file _, range = request.headers['Range'].split('bytes=') from, to = range.split('-').map(&:to_i) to = local_file_size - 1 unless to length = to - from + 1 response.headers['Content-Range'] = "bytes #{from}-#{to}/#{local_file_size}" response.headers['Content-Length'] = length.to_s self.status = 206 prepare_local_file_headers # For derivatives stored on the local file system send_data IO.binread(file, length, from), local_derivative_download_options.merge(status: status) end
ruby
{ "resource": "" }
q11721
Hyrax.AdminSetCreateService.create
train
def create admin_set.creator = [creating_user.user_key] if creating_user admin_set.save.tap do |result| if result ActiveRecord::Base.transaction do permission_template = create_permission_template workflow = create_workflows_for(permission_template: permission_template) create_default_access_for(permission_template: permission_template, workflow: workflow) if admin_set.default_set? end end end end
ruby
{ "resource": "" }
q11722
Hyrax.AdminSetCreateService.create_default_access_for
train
def create_default_access_for(permission_template:, workflow:) permission_template.access_grants.create(agent_type: 'group', agent_id: ::Ability.registered_group_name, access: Hyrax::PermissionTemplateAccess::DEPOSIT) deposit = Sipity::Role[Hyrax::RoleRegistry::DEPOSITING] workflow.update_responsibilities(role: deposit, agents: Hyrax::Group.new('registered')) end
ruby
{ "resource": "" }
q11723
Hyrax.Microdata.flatten
train
def flatten(hash) hash.each_with_object({}) do |(key, value), h| if value.instance_of?(Hash) value.map do |k, v| # We could add recursion here if we ever had more than 2 levels h["#{key}.#{k}"] = v end else h[key] = value end end end
ruby
{ "resource": "" }
q11724
Hyrax.MemberPresenterFactory.file_set_ids
train
def file_set_ids @file_set_ids ||= begin ActiveFedora::SolrService.query("{!field f=has_model_ssim}FileSet", rows: 10_000, fl: ActiveFedora.id_field, fq: "{!join from=ordered_targets_ssim to=id}id:\"#{id}/list_source\"") .flat_map { |x| x.fetch(ActiveFedora.id_field, []) } end end
ruby
{ "resource": "" }
q11725
ActionDispatch::Routing.Mapper.namespaced_resources
train
def namespaced_resources(target, opts = {}, &block) if target.include?('/') the_namespace = target[0..target.index('/') - 1] new_target = target[target.index('/') + 1..-1] namespace the_namespace, ROUTE_OPTIONS.fetch(the_namespace, {}) do namespaced_resources(new_target, opts, &block) end else resources target, opts do yield if block_given? end end end
ruby
{ "resource": "" }
q11726
Hyrax.WorkShowPresenter.manifest_metadata
train
def manifest_metadata metadata = [] Hyrax.config.iiif_metadata_fields.each do |field| metadata << { 'label' => I18n.t("simple_form.labels.defaults.#{field}"), 'value' => Array.wrap(send(field).map { |f| Loofah.fragment(f.to_s).scrub!(:whitewash).to_s }) } end metadata end
ruby
{ "resource": "" }
q11727
Hyrax.WorkShowPresenter.authorized_item_ids
train
def authorized_item_ids @member_item_list_ids ||= begin items = ordered_ids items.delete_if { |m| !current_ability.can?(:read, m) } if Flipflop.hide_private_items? items end end
ruby
{ "resource": "" }
q11728
Hyrax.WorkShowPresenter.paginated_item_list
train
def paginated_item_list(page_array:) Kaminari.paginate_array(page_array, total_count: page_array.size).page(current_page).per(rows_from_params) end
ruby
{ "resource": "" }
q11729
Hyrax.CollectionsHelper.single_item_action_form_fields
train
def single_item_action_form_fields(form, document, action) render 'hyrax/dashboard/collections/single_item_action_fields', form: form, document: document, action: action end
ruby
{ "resource": "" }
q11730
Hyrax.WorksControllerBehavior.show
train
def show @user_collections = user_collections respond_to do |wants| wants.html { presenter && parent_presenter } wants.json do # load and authorize @curation_concern manually because it's skipped for html @curation_concern = _curation_concern_type.find(params[:id]) unless curation_concern authorize! :show, @curation_concern render :show, status: :ok end additional_response_formats(wants) wants.ttl do render body: presenter.export_as_ttl, content_type: 'text/turtle' end wants.jsonld do render body: presenter.export_as_jsonld, content_type: 'application/ld+json' end wants.nt do render body: presenter.export_as_nt, content_type: 'application/n-triples' end end end
ruby
{ "resource": "" }
q11731
Hyrax.WorksControllerBehavior.search_result_document
train
def search_result_document(search_params) _, document_list = search_results(search_params) return document_list.first unless document_list.empty? document_not_found! end
ruby
{ "resource": "" }
q11732
Hyrax.WorksControllerBehavior.attributes_for_actor
train
def attributes_for_actor raw_params = params[hash_key_for_curation_concern] attributes = if raw_params work_form_service.form_class(curation_concern).model_attributes(raw_params) else {} end # If they selected a BrowseEverything file, but then clicked the # remove button, it will still show up in `selected_files`, but # it will no longer be in uploaded_files. By checking the # intersection, we get the files they added via BrowseEverything # that they have not removed from the upload widget. uploaded_files = params.fetch(:uploaded_files, []) selected_files = params.fetch(:selected_files, {}).values browse_everything_urls = uploaded_files & selected_files.map { |f| f[:url] } # we need the hash of files with url and file_name browse_everything_files = selected_files .select { |v| uploaded_files.include?(v[:url]) } attributes[:remote_files] = browse_everything_files # Strip out any BrowseEverthing files from the regular uploads. attributes[:uploaded_files] = uploaded_files - browse_everything_urls attributes end
ruby
{ "resource": "" }
q11733
Hyrax.ManifestHelper.build_rendering
train
def build_rendering(file_set_id) file_set_document = query_for_rendering(file_set_id) label = file_set_document.label.present? ? ": #{file_set_document.label}" : '' mime = file_set_document.mime_type.present? ? file_set_document.mime_type : I18n.t("hyrax.manifest.unknown_mime_text") { '@id' => Hyrax::Engine.routes.url_helpers.download_url(file_set_document.id, host: @hostname), 'format' => mime, 'label' => I18n.t("hyrax.manifest.download_text") + label } end
ruby
{ "resource": "" }
q11734
Selectors.Dashboard.select_user
train
def select_user(user, role = 'Depositor') first('a.select2-choice').click find('.select2-input').set(user.user_key) sleep 1 first('div.select2-result-label').click within('div.add-users') do select(role) find('input.edit-collection-add-sharing-button').click end end
ruby
{ "resource": "" }
q11735
Selectors.Dashboard.select_collection
train
def select_collection(collection) first('a.select2-choice').click find('.select2-input').set(collection.title.first) expect(page).to have_css('div.select2-result-label') first('div.select2-result-label').click first('[data-behavior~=add-relationship]').click within('[data-behavior~=collection-relationships]') do within('table.table.table-striped') do expect(page).to have_content(collection.title.first) end end end
ruby
{ "resource": "" }
q11736
Selectors.Dashboard.select_member_of_collection
train
def select_member_of_collection(collection) find('#s2id_member_of_collection_ids').click find('.select2-input').set(collection.title.first) # Crude way of waiting for the AJAX response select2_results = [] time_elapsed = 0 while select2_results.empty? && time_elapsed < 30 begin_time = Time.now.to_f doc = Nokogiri::XML.parse(page.body) select2_results = doc.xpath('//html:li[contains(@class,"select2-result")]', html: 'http://www.w3.org/1999/xhtml') end_time = Time.now.to_f time_elapsed += end_time - begin_time end expect(page).to have_css('.select2-result') within ".select2-result" do find("span", text: collection.title.first).click end end
ruby
{ "resource": "" }
q11737
Hyrax.DisplaysImage.display_image
train
def display_image return nil unless ::FileSet.exists?(id) && solr_document.image? && current_ability.can?(:read, id) # @todo this is slow, find a better way (perhaps index iiif url): original_file = ::FileSet.find(id).original_file url = Hyrax.config.iiif_image_url_builder.call( original_file.id, request.base_url, Hyrax.config.iiif_image_size_default ) # @see https://github.com/samvera-labs/iiif_manifest IIIFManifest::DisplayImage.new(url, width: 640, height: 480, iiif_endpoint: iiif_endpoint(original_file.id)) end
ruby
{ "resource": "" }
q11738
Hyrax.FileSetFixityCheckService.fixity_check_file_version
train
def fixity_check_file_version(file_id, version_uri) latest_fixity_check = ChecksumAuditLog.logs_for(file_set.id, checked_uri: version_uri).first return latest_fixity_check unless needs_fixity_check?(latest_fixity_check) if async_jobs FixityCheckJob.perform_later(version_uri.to_s, file_set_id: file_set.id, file_id: file_id) else FixityCheckJob.perform_now(version_uri.to_s, file_set_id: file_set.id, file_id: file_id) end end
ruby
{ "resource": "" }
q11739
Hyrax.FileSetFixityCheckService.needs_fixity_check?
train
def needs_fixity_check?(latest_fixity_check) return true unless latest_fixity_check unless latest_fixity_check.updated_at logger.warn "***FIXITY*** problem with fixity check log! Latest Fixity check is not nil, but updated_at is not set #{latest_fixity_check}" return true end days_since_last_fixity_check(latest_fixity_check) >= max_days_between_fixity_checks end
ruby
{ "resource": "" }
q11740
Hyrax.EmbargoesControllerBehavior.destroy
train
def destroy Hyrax::Actors::EmbargoActor.new(curation_concern).destroy flash[:notice] = curation_concern.embargo_history.last if curation_concern.work? && curation_concern.file_sets.present? redirect_to confirm_permission_path else redirect_to edit_embargo_path end end
ruby
{ "resource": "" }
q11741
Hyrax.EmbargoesControllerBehavior.update
train
def update filter_docs_with_edit_access! copy_visibility = params[:embargoes].values.map { |h| h[:copy_visibility] } ActiveFedora::Base.find(batch).each do |curation_concern| Hyrax::Actors::EmbargoActor.new(curation_concern).destroy # if the concern is a FileSet, set its visibility and skip the copy_visibility_to_files, which is built for Works if curation_concern.file_set? curation_concern.visibility = curation_concern.to_solr["visibility_after_embargo_ssim"] curation_concern.save! elsif copy_visibility.include?(curation_concern.id) curation_concern.copy_visibility_to_files end end redirect_to embargoes_path, notice: t('.embargo_deactivated') end
ruby
{ "resource": "" }
q11742
Hyrax.IndexesWorkflow.index_workflow_fields
train
def index_workflow_fields(solr_document) return unless object.persisted? entity = PowerConverter.convert_to_sipity_entity(object) return if entity.nil? solr_document[workflow_role_field] = workflow_roles(entity).map { |role| "#{entity.workflow.permission_template.source_id}-#{entity.workflow.name}-#{role}" } solr_document[workflow_state_name_field] = entity.workflow_state.name if entity.workflow_state end
ruby
{ "resource": "" }
q11743
Sipity.Workflow.add_workflow_responsibilities
train
def add_workflow_responsibilities(role, agents) Hyrax::Workflow::PermissionGenerator.call(roles: role, workflow: self, agents: agents) end
ruby
{ "resource": "" }
q11744
Sipity.Workflow.remove_workflow_responsibilities
train
def remove_workflow_responsibilities(role, allowed_agents) wf_role = Sipity::WorkflowRole.find_by(workflow: self, role_id: role) wf_role.workflow_responsibilities.where.not(agent: allowed_agents).destroy_all end
ruby
{ "resource": "" }
q11745
Hyrax.PresentsAttributes.attribute_to_html
train
def attribute_to_html(field, options = {}) unless respond_to?(field) Rails.logger.warn("#{self.class} attempted to render #{field}, but no method exists with that name.") return end if options[:html_dl] renderer_for(field, options).new(field, send(field), options).render_dl_row else renderer_for(field, options).new(field, send(field), options).render end end
ruby
{ "resource": "" }
q11746
Hyrax.DeepIndexingService.append_to_solr_doc
train
def append_to_solr_doc(solr_doc, solr_field_key, field_info, val) return super unless object.controlled_properties.include?(solr_field_key.to_sym) case val when ActiveTriples::Resource append_label_and_uri(solr_doc, solr_field_key, field_info, val) when String append_label(solr_doc, solr_field_key, field_info, val) else raise ArgumentError, "Can't handle #{val.class}" end end
ruby
{ "resource": "" }
q11747
Hyrax.DeepIndexingService.fetch_external
train
def fetch_external object.controlled_properties.each do |property| object[property].each do |value| resource = value.respond_to?(:resource) ? value.resource : value next unless resource.is_a?(ActiveTriples::Resource) next if value.is_a?(ActiveFedora::Base) fetch_with_persistence(resource) end end end
ruby
{ "resource": "" }
q11748
Hyrax.DeepIndexingService.append_label
train
def append_label(solr_doc, solr_field_key, field_info, val) ActiveFedora::Indexing::Inserter.create_and_insert_terms(solr_field_key, val, field_info.behaviors, solr_doc) ActiveFedora::Indexing::Inserter.create_and_insert_terms("#{solr_field_key}_label", val, field_info.behaviors, solr_doc) end
ruby
{ "resource": "" }
q11749
Hyrax.DepositSearchBuilder.include_depositor_facet
train
def include_depositor_facet(solr_parameters) solr_parameters[:"facet.field"].concat([DepositSearchBuilder.depositor_field]) # default facet limit is 10, which will only show the top 10 users. # As we want to show all user deposits, so set the facet.limit to the # the number of users in the database solr_parameters[:"facet.limit"] = ::User.count # we only want the facte counts not the actual data solr_parameters[:rows] = 0 end
ruby
{ "resource": "" }
q11750
Hyrax.UsersController.show
train
def show user = ::User.from_url_component(params[:id]) return redirect_to root_path, alert: "User '#{params[:id]}' does not exist" if user.nil? @presenter = Hyrax::UserProfilePresenter.new(user, current_ability) end
ruby
{ "resource": "" }
q11751
Hyrax.PresenterFactory.query
train
def query(query, args = {}) args[:q] = query args[:qt] = 'standard' conn = ActiveFedora::SolrService.instance.conn result = conn.post('select', data: args) result.fetch('response').fetch('docs') end
ruby
{ "resource": "" }
q11752
Hyrax.RedisEventStore.push
train
def push(value) RedisEventStore.instance.lpush(@key, value) rescue Redis::CommandError, Redis::CannotConnectError RedisEventStore.logger.error("unable to push event: #{@key}") nil end
ruby
{ "resource": "" }
q11753
Hyrax.Operation.rollup_messages
train
def rollup_messages [].tap do |messages| messages << message if message.present? children&.pluck(:message)&.uniq&.each do |child_message| messages << child_message if child_message.present? end end end
ruby
{ "resource": "" }
q11754
Hyrax.Operation.fail!
train
def fail!(message = nil) run_callbacks :failure do update(status: FAILURE, message: message) parent&.rollup_status end end
ruby
{ "resource": "" }
q11755
Hyrax.Operation.pending_job
train
def pending_job(job) update(job_class: job.class.to_s, job_id: job.job_id, status: Hyrax::Operation::PENDING) end
ruby
{ "resource": "" }
q11756
Hyrax.Admin::AdminSetsController.files
train
def files result = form.select_files.map { |label, id| { id: id, text: label } } render json: result end
ruby
{ "resource": "" }
q11757
Wings.ActiveFedoraConverter.id
train
def id id_attr = resource[:id] return id_attr.to_s if id_attr.present? && id_attr.is_a?(::Valkyrie::ID) && !id_attr.blank? return "" unless resource.respond_to?(:alternate_ids) resource.alternate_ids.first.to_s end
ruby
{ "resource": "" }
q11758
Wings.ActiveFedoraConverter.add_access_control_attributes
train
def add_access_control_attributes(af_object) af_object.visibility = attributes[:visibility] unless attributes[:visibility].blank? af_object.read_users = attributes[:read_users] unless attributes[:read_users].blank? af_object.edit_users = attributes[:edit_users] unless attributes[:edit_users].blank? af_object.read_groups = attributes[:read_groups] unless attributes[:read_groups].blank? af_object.edit_groups = attributes[:edit_groups] unless attributes[:edit_groups].blank? end
ruby
{ "resource": "" }
q11759
Hyrax.CollectionPresenter.managed_access
train
def managed_access return I18n.t('hyrax.dashboard.my.collection_list.managed_access.manage') if current_ability.can?(:edit, solr_document) return I18n.t('hyrax.dashboard.my.collection_list.managed_access.deposit') if current_ability.can?(:deposit, solr_document) return I18n.t('hyrax.dashboard.my.collection_list.managed_access.view') if current_ability.can?(:read, solr_document) '' end
ruby
{ "resource": "" }
q11760
Hyrax.CollectionType.gid
train
def gid URI::GID.build(app: GlobalID.app, model_name: model_name.name.parameterize.to_sym, model_id: id).to_s if id end
ruby
{ "resource": "" }
q11761
Hyrax.PermissionTemplate.release_date
train
def release_date # If no release delays allowed, return today's date as release date return Time.zone.today if release_no_delay? # If this isn't an embargo, just return release_date from database return self[:release_date] unless release_max_embargo? # Otherwise (if an embargo), return latest embargo date by adding specified months to today's date Time.zone.today + RELEASE_EMBARGO_PERIODS.fetch(release_period).months end
ruby
{ "resource": "" }
q11762
Hyrax.Ability.download_users
train
def download_users(id) doc = permissions_doc(id) return [] if doc.nil? users = Array(doc[self.class.read_user_field]) + Array(doc[self.class.edit_user_field]) Rails.logger.debug("[CANCAN] download_users: #{users.inspect}") users end
ruby
{ "resource": "" }
q11763
Hyrax.Ability.trophy_abilities
train
def trophy_abilities can [:create, :destroy], Trophy do |t| doc = ActiveFedora::Base.search_by_id(t.work_id, fl: 'depositor_ssim') current_user.user_key == doc.fetch('depositor_ssim').first end end
ruby
{ "resource": "" }
q11764
Hyrax.Ability.user_is_depositor?
train
def user_is_depositor?(document_id) Hyrax::WorkRelation.new.search_with_conditions( id: document_id, DepositSearchBuilder.depositor_field => current_user.user_key ).any? end
ruby
{ "resource": "" }
q11765
Hyrax.CharacterizationBehavior.primary_characterization_values
train
def primary_characterization_values(term) values = values_for(term) values.slice!(Hyrax.config.fits_message_length, (values.length - Hyrax.config.fits_message_length)) truncate_all(values) end
ruby
{ "resource": "" }
q11766
Hyrax.CharacterizationBehavior.secondary_characterization_values
train
def secondary_characterization_values(term) values = values_for(term) additional_values = values.slice(Hyrax.config.fits_message_length, values.length - Hyrax.config.fits_message_length) return [] unless additional_values truncate_all(additional_values) end
ruby
{ "resource": "" }
q11767
LinkedIn.Search.search
train
def search(options={}, type='people') path = "/#{type.to_s}-search" if options.is_a?(Hash) fields = options.delete(:fields) path += field_selector(fields) if fields end options = { :keywords => options } if options.is_a?(String) options = format_options_for_query(options) result_json = get(to_uri(path, options)) Mash.from_json(result_json) end
ruby
{ "resource": "" }
q11768
LinkedIn.Mash.timestamp
train
def timestamp value = self['timestamp'] if value.kind_of? Integer value = value / 1000 if value > 9999999999 Time.at(value) else value end end
ruby
{ "resource": "" }
q11769
Bibliothecary.Runner.identify_manifests
train
def identify_manifests(file_list) ignored_dirs_with_slash = ignored_dirs.map { |d| if d.end_with?("/") then d else d + "/" end } allowed_file_list = file_list.reject do |f| ignored_dirs.include?(f) || f.start_with?(*ignored_dirs_with_slash) end allowed_file_list = allowed_file_list.reject{|f| ignored_files.include?(f)} package_managers.map do |pm| allowed_file_list.select do |file_path| # this is a call to match? without file contents, which will skip # ambiguous filenames that are only possibly a manifest pm.match?(file_path) end end.flatten.uniq.compact end
ruby
{ "resource": "" }
q11770
SquareConnect.CreateOrderRequest.to_hash
train
def to_hash hash = {} self.class.attribute_map.each_pair do |attr, param| value = self.send(attr) next if value.nil? hash[param] = _to_hash(value) end hash end
ruby
{ "resource": "" }
q11771
SquareConnect.CreateOrderRequest._to_hash
train
def _to_hash(value) if value.is_a?(Array) value.compact.map{ |v| _to_hash(v) } elsif value.is_a?(Hash) {}.tap do |hash| value.each { |k, v| hash[k] = _to_hash(v) } end elsif value.respond_to? :to_hash value.to_hash else value end end
ruby
{ "resource": "" }
q11772
SquareConnect.ApiClient.get_v1_batch_token_from_headers
train
def get_v1_batch_token_from_headers(headers) if headers.is_a?(Hash) && headers.has_key?('Link') match = /^<([^>]+)>;rel='next'$/.match(headers['Link']) if match uri = URI.parse(match[1]) params = CGI.parse(uri.query) return params['batch_token'][0] end end end
ruby
{ "resource": "" }
q11773
SquareConnect.V1EmployeesApi.list_cash_drawer_shifts
train
def list_cash_drawer_shifts(location_id, opts = {}) data, _status_code, _headers = list_cash_drawer_shifts_with_http_info(location_id, opts) return data end
ruby
{ "resource": "" }
q11774
SquareConnect.V1EmployeesApi.retrieve_cash_drawer_shift
train
def retrieve_cash_drawer_shift(location_id, shift_id, opts = {}) data, _status_code, _headers = retrieve_cash_drawer_shift_with_http_info(location_id, shift_id, opts) return data end
ruby
{ "resource": "" }
q11775
SquareConnect.V1EmployeesApi.retrieve_employee
train
def retrieve_employee(employee_id, opts = {}) data, _status_code, _headers = retrieve_employee_with_http_info(employee_id, opts) return data end
ruby
{ "resource": "" }
q11776
SquareConnect.V1EmployeesApi.retrieve_employee_role
train
def retrieve_employee_role(role_id, opts = {}) data, _status_code, _headers = retrieve_employee_role_with_http_info(role_id, opts) return data end
ruby
{ "resource": "" }
q11777
SquareConnect.V1EmployeesApi.update_employee_role
train
def update_employee_role(role_id, body, opts = {}) data, _status_code, _headers = update_employee_role_with_http_info(role_id, body, opts) return data end
ruby
{ "resource": "" }
q11778
SquareConnect.V1EmployeesApi.update_timecard
train
def update_timecard(timecard_id, body, opts = {}) data, _status_code, _headers = update_timecard_with_http_info(timecard_id, body, opts) return data end
ruby
{ "resource": "" }
q11779
SquareConnect.CustomersApi.create_customer_card
train
def create_customer_card(customer_id, body, opts = {}) data, _status_code, _headers = create_customer_card_with_http_info(customer_id, body, opts) return data end
ruby
{ "resource": "" }
q11780
SquareConnect.CustomersApi.delete_customer
train
def delete_customer(customer_id, opts = {}) data, _status_code, _headers = delete_customer_with_http_info(customer_id, opts) return data end
ruby
{ "resource": "" }
q11781
SquareConnect.CustomersApi.delete_customer_card
train
def delete_customer_card(customer_id, card_id, opts = {}) data, _status_code, _headers = delete_customer_card_with_http_info(customer_id, card_id, opts) return data end
ruby
{ "resource": "" }
q11782
SquareConnect.CustomersApi.retrieve_customer
train
def retrieve_customer(customer_id, opts = {}) data, _status_code, _headers = retrieve_customer_with_http_info(customer_id, opts) return data end
ruby
{ "resource": "" }
q11783
SquareConnect.CustomersApi.search_customers
train
def search_customers(body, opts = {}) data, _status_code, _headers = search_customers_with_http_info(body, opts) return data end
ruby
{ "resource": "" }
q11784
SquareConnect.V1ItemsApi.adjust_inventory
train
def adjust_inventory(location_id, variation_id, body, opts = {}) data, _status_code, _headers = adjust_inventory_with_http_info(location_id, variation_id, body, opts) return data end
ruby
{ "resource": "" }
q11785
SquareConnect.V1ItemsApi.apply_fee
train
def apply_fee(location_id, item_id, fee_id, opts = {}) data, _status_code, _headers = apply_fee_with_http_info(location_id, item_id, fee_id, opts) return data end
ruby
{ "resource": "" }
q11786
SquareConnect.V1ItemsApi.apply_modifier_list
train
def apply_modifier_list(location_id, modifier_list_id, item_id, opts = {}) data, _status_code, _headers = apply_modifier_list_with_http_info(location_id, modifier_list_id, item_id, opts) return data end
ruby
{ "resource": "" }
q11787
SquareConnect.V1ItemsApi.create_category
train
def create_category(location_id, body, opts = {}) data, _status_code, _headers = create_category_with_http_info(location_id, body, opts) return data end
ruby
{ "resource": "" }
q11788
SquareConnect.V1ItemsApi.create_discount
train
def create_discount(location_id, body, opts = {}) data, _status_code, _headers = create_discount_with_http_info(location_id, body, opts) return data end
ruby
{ "resource": "" }
q11789
SquareConnect.V1ItemsApi.create_item
train
def create_item(location_id, body, opts = {}) data, _status_code, _headers = create_item_with_http_info(location_id, body, opts) return data end
ruby
{ "resource": "" }
q11790
SquareConnect.V1ItemsApi.create_modifier_list
train
def create_modifier_list(location_id, body, opts = {}) data, _status_code, _headers = create_modifier_list_with_http_info(location_id, body, opts) return data end
ruby
{ "resource": "" }
q11791
SquareConnect.V1ItemsApi.create_modifier_option
train
def create_modifier_option(location_id, modifier_list_id, body, opts = {}) data, _status_code, _headers = create_modifier_option_with_http_info(location_id, modifier_list_id, body, opts) return data end
ruby
{ "resource": "" }
q11792
SquareConnect.V1ItemsApi.create_page
train
def create_page(location_id, body, opts = {}) data, _status_code, _headers = create_page_with_http_info(location_id, body, opts) return data end
ruby
{ "resource": "" }
q11793
SquareConnect.V1ItemsApi.create_variation
train
def create_variation(location_id, item_id, body, opts = {}) data, _status_code, _headers = create_variation_with_http_info(location_id, item_id, body, opts) return data end
ruby
{ "resource": "" }
q11794
SquareConnect.V1ItemsApi.list_categories
train
def list_categories(location_id, opts = {}) data, _status_code, _headers = list_categories_with_http_info(location_id, opts) return data end
ruby
{ "resource": "" }
q11795
SquareConnect.V1ItemsApi.list_discounts
train
def list_discounts(location_id, opts = {}) data, _status_code, _headers = list_discounts_with_http_info(location_id, opts) return data end
ruby
{ "resource": "" }
q11796
SquareConnect.V1ItemsApi.list_inventory
train
def list_inventory(location_id, opts = {}) data, _status_code, _headers = list_inventory_with_http_info(location_id, opts) return data end
ruby
{ "resource": "" }
q11797
SquareConnect.V1ItemsApi.list_items
train
def list_items(location_id, opts = {}) data, _status_code, _headers = list_items_with_http_info(location_id, opts) return data end
ruby
{ "resource": "" }
q11798
SquareConnect.V1ItemsApi.list_modifier_lists
train
def list_modifier_lists(location_id, opts = {}) data, _status_code, _headers = list_modifier_lists_with_http_info(location_id, opts) return data end
ruby
{ "resource": "" }
q11799
SquareConnect.V1ItemsApi.list_pages
train
def list_pages(location_id, opts = {}) data, _status_code, _headers = list_pages_with_http_info(location_id, opts) return data end
ruby
{ "resource": "" }