Sha256: 47006b474cd30762ad9e100ac03bffd43e432e4d798cccfef2b1bf58047683eb

Contents?: true

Size: 913 Bytes

Versions: 15

Compression:

Stored size: 913 Bytes

Contents

# frozen_string_literal: true

module Licensee
  # Exposes #conditions, #permissions, and #limitation arrays of LicenseRules
  class LicenseRules < Struct.new(:conditions, :permissions, :limitations)
    include Licensee::HashHelper
    HASH_METHODS = Rule.groups

    class << self
      def from_license(license)
        from_meta(license.meta)
      end

      def from_meta(meta)
        rules = {}
        Rule.groups.each do |group|
          rules[group] = (meta[group] || []).map do |tag|
            Rule.find_by_tag_and_group(tag, group)
          end
        end
        from_hash(rules)
      end

      def from_hash(hash)
        ordered_array = hash.values_at(*members.map(&:to_s))
        new(*ordered_array)
      end
    end

    def flatten
      members.map { |m| public_send(m) }.flatten
    end

    def key?(key)
      members.include?(key.to_sym)
    end
    alias has_key? key?
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
licensee-9.18.0 lib/licensee/license_rules.rb
licensee-9.17.1 lib/licensee/license_rules.rb
licensee-9.17.0 lib/licensee/license_rules.rb
licensee-9.16.1 lib/licensee/license_rules.rb
licensee-9.16.0 lib/licensee/license_rules.rb
licensee-9.15.3 lib/licensee/license_rules.rb
licensee-9.15.2 lib/licensee/license_rules.rb
licensee-9.15.1 lib/licensee/license_rules.rb
licensee-9.15.0 lib/licensee/license_rules.rb
licensee-9.14.1 lib/licensee/license_rules.rb
licensee-9.14.0 lib/licensee/license_rules.rb
licensee-9.13.2 lib/licensee/license_rules.rb
licensee-9.13.1 lib/licensee/license_rules.rb
licensee-9.13.0 lib/licensee/license_rules.rb
licensee-9.12.0 lib/licensee/license_rules.rb