Class: Study::Metadata

Inherits:
Object
  • Object
show all
Defined in:
app/models/study.rb

Instance Method Summary collapse

Instance Method Details

#data_release_timing_must_be_never?Boolean

Returns:

  • (Boolean)


632
633
634
635
# File 'app/models/study.rb', line 632

def data_release_timing_must_be_never?
  Flipper.enabled?(:y24_052_enable_data_release_timing_validation) && data_release_strategy.present? &&
    strategy_not_applicable?
end

#data_release_timing_must_not_be_never?Boolean

Returns:

  • (Boolean)


637
638
639
640
# File 'app/models/study.rb', line 637

def data_release_timing_must_not_be_never?
  Flipper.enabled?(:y24_052_enable_data_release_timing_validation) && data_release_strategy.present? &&
    !strategy_not_applicable?
end

#delayed_for_long_time?Boolean

Returns:

  • (Boolean)


607
608
609
# File 'app/models/study.rb', line 607

def delayed_for_long_time?
  DATA_RELEASE_DELAY_PERIODS.include?(data_release_delay_period)
end

#delayed_for_other_reasons?Boolean

Returns:

  • (Boolean)


603
604
605
# File 'app/models/study.rb', line 603

def delayed_for_other_reasons?
  data_release_delay_reason == DATA_RELEASE_DELAY_FOR_OTHER
end

#delayed_release?Boolean

Returns:

  • (Boolean)


595
596
597
# File 'app/models/study.rb', line 595

def delayed_release?
  data_release_timing == DATA_RELEASE_TIMING_DELAYED
end

#managed?Boolean

Returns:

  • (Boolean)


587
588
589
# File 'app/models/study.rb', line 587

def managed?
  data_release_strategy == DATA_RELEASE_STRATEGY_MANAGED
end

#never_release?Boolean

Returns:

  • (Boolean)


599
600
601
# File 'app/models/study.rb', line 599

def never_release?
  data_release_timing == DATA_RELEASE_TIMING_NEVER
end

#non_standard_agreement?Boolean

Returns:

  • (Boolean)


656
657
658
# File 'app/models/study.rb', line 656

def non_standard_agreement?
  data_release_standard_agreement == NO
end

#remove_x_and_autosomes?Boolean

Returns:

  • (Boolean)


583
584
585
# File 'app/models/study.rb', line 583

def remove_x_and_autosomes?
  remove_x_and_autosomes == YES
end

#sanity_check_y_separationObject



642
643
644
645
646
647
# File 'app/models/study.rb', line 642

def sanity_check_y_separation
  if remove_x_and_autosomes?
    errors.add(:separate_y_chromosome_data, 'cannot be selected with remove x and autosomes.')
  end
  !remove_x_and_autosomes?
end

#snp_child_studiesObject



702
703
704
705
706
# File 'app/models/study.rb', line 702

def snp_child_studies
  return nil if snp_study_id.nil?

  self.class.where(snp_parent_study_id: snp_study_id).includes(:study).map(&:study)
end

#snp_parent_studyObject



696
697
698
699
700
# File 'app/models/study.rb', line 696

def snp_parent_study
  return nil if snp_parent_study_id.nil?

  self.class.where(snp_study_id: snp_parent_study_id).includes(:study).try(:study)
end

#strategy_not_applicable?Boolean

Returns:

  • (Boolean)


591
592
593
# File 'app/models/study.rb', line 591

def strategy_not_applicable?
  data_release_strategy == DATA_RELEASE_STRATEGY_NOT_APPLICABLE
end

#study_type_valid?Boolean

Returns:

  • (Boolean)


660
661
662
# File 'app/models/study.rb', line 660

def study_type_valid?
  errors.add(:study_type, 'is not specified') if study_type.name == 'Not specified'
end

#valid_policy_url?Boolean

rubocop:todo Metrics/MethodLength

Returns:

  • (Boolean)


665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
# File 'app/models/study.rb', line 665

def valid_policy_url? # rubocop:todo Metrics/AbcSize
  # Rails 2.3 has no inbuilt URL validation, but rather than rolling our own, we'll
  # use the inbuilt ruby URI parser, a bit like here:
  # http://www.simonecarletti.com/blog/2009/04/validating-the-format-of-an-url-with-rails/
  return true if dac_policy.blank?

  dac_policy.insert(0, 'http://') unless dac_policy.include?('://') # Add an http protocol if no protocol is defined
  begin
    uri = URI.parse(dac_policy)
    if configatron.invalid_policy_url_domains.include?(uri.host)
      errors.add(
        :dac_policy,
        ": #{dac_policy} is not an acceptable URL. Please ensure you haven't provided an internal URL."
      )
    end
  rescue URI::InvalidURIError
    errors.add(:dac_policy, ": #{dac_policy} is not a valid URL")
  end
end