Sha256: bf5bf9c3feb8ee94ee02648ed79fba946df198ba8a390ea727c1215c17b8dd99

Contents?: true

Size: 1.43 KB

Versions: 10

Compression:

Stored size: 1.43 KB

Contents

module Licensee
  module Matchers
    class Gemspec < Licensee::Matchers::Package
      # a value is a string surrounded by any amount of whitespace
      # optionally ended with (non-captured) ".freeze"
      VALUE_REGEX = /\s*[\'\"]([a-z\-0-9\.]+)[\'\"](?:\.freeze)?\s*/i

      # an array contains one or more values. all values, or array itself,
      # can be surrounded by any amount of whitespace.  do not capture
      # non-value groups
      ARRAY_REGEX = /\s*\[#{VALUE_REGEX}(?:,#{VALUE_REGEX})*\]\s*/i

      DECLARATION_REGEX = /
        ^\s*[a-z0-9_]+\.([a-z0-9_]+)\s*\=#{VALUE_REGEX}$
      /ix

      LICENSE_REGEX = /
        ^\s*[a-z0-9_]+\.license\s*\=#{VALUE_REGEX}$
      /ix

      LICENSE_ARRAY_REGEX = /
        ^\s*[a-z0-9_]+\.licenses\s*\=#{ARRAY_REGEX}$
      /ix

      private

      def license_property
        match = @file.content.match LICENSE_REGEX
        return match[1].downcase if match && match[1]

        # check for a licenses array property
        licenses = license_array_property
        return unless licenses

        # use 'other' if array contains multiple licenses
        return 'other' unless licenses.size == 1
        licenses[0]
      end

      def license_array_property
        match = @file.content.match LICENSE_ARRAY_REGEX
        match.captures.compact.map(&:downcase) if match
      end

      def declarations
        @declarations ||= @file.content.match DECLARATION_REGEX
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
licensee-9.10.0 lib/licensee/matchers/gemspec.rb
licensee-9.9.4 lib/licensee/matchers/gemspec.rb
licensee-9.9.3 lib/licensee/matchers/gemspec.rb
licensee-9.9.2 lib/licensee/matchers/gemspec.rb
licensee-9.9.1 lib/licensee/matchers/gemspec.rb
licensee-9.9.0 lib/licensee/matchers/gemspec.rb
licensee-9.9.0.beta.3 lib/licensee/matchers/gemspec.rb
licensee-9.9.0.beta.2 lib/licensee/matchers/gemspec.rb
licensee-9.8.0 lib/licensee/matchers/gemspec.rb
licensee-9.7.0 lib/licensee/matchers/gemspec.rb