Sha256: 4a5bf440761140b7e1f87e6fe0242649fd6020d29707d34f6e8c5837e836d661

Contents?: true

Size: 1.44 KB

Versions: 8

Compression:

Stored size: 1.44 KB

Contents

module LicenseFinder
  class Dependency < Sequel::Model
    plugin :boolean_readers
    many_to_one :license, class: LicenseAlias
    many_to_one :approval
    many_to_many :children, join_table: :ancestries, left_key: :parent_dependency_id, right_key: :child_dependency_id, class: self
    many_to_many :parents, join_table: :ancestries, left_key: :child_dependency_id, right_key: :parent_dependency_id, class: self
    many_to_many :bundler_groups

    dataset_module do
      def bundler
        exclude(manual: true)
      end

      def non_bundler
        bundler.invert
      end

      def obsolete(current)
        exclude(id: current.map(&:id))
      end
    end

    def self.unapproved
      all.reject(&:approved?)
    end

    def self.named(name)
      d = find_or_create(name: name.to_s)
      d.ensure_approval_exists!
      d
    end

    def approve!
      approval.state = true
      approval.save
    end

    def approved?
      # jruby adapter receives approval.state as Fixnum '0', which ruby evaluates
      # as truthy, so we catch this here for jruby support.
      (license && license.whitelisted?) || (approval.state && approval.state != 0)
    end

    def set_license_manually!(license_name)
      self.license = LicenseAlias.find_or_create(name: license_name)
      self.license_manual = true
      save
    end

    def ensure_approval_exists!
      return if approval
      self.approval = Approval.create
      save
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
license_finder-0.9.4-java lib/license_finder/tables/dependency.rb
license_finder-0.9.4 lib/license_finder/tables/dependency.rb
license_finder-0.9.3-java lib/license_finder/tables/dependency.rb
license_finder-0.9.3 lib/license_finder/tables/dependency.rb
license_finder-0.9.2-java lib/license_finder/tables/dependency.rb
license_finder-0.9.2 lib/license_finder/tables/dependency.rb
license_finder-0.9.1-java lib/license_finder/tables/dependency.rb
license_finder-0.9.1 lib/license_finder/tables/dependency.rb