Class: Licensee::LicenseRules

Inherits:
Struct
  • Object
show all
Includes:
HashHelper
Defined in:
lib/licensee/license_rules.rb

Overview

Exposes #conditions, #permissions, and #limitation arrays of LicenseRules

Constant Summary collapse

HASH_METHODS =
Rule.groups

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HashHelper

#to_h

Instance Attribute Details

#conditionsObject

Returns the value of attribute conditions

Returns:

  • (Object)

    the current value of conditions



3
4
5
# File 'lib/licensee/license_rules.rb', line 3

def conditions
  @conditions
end

#limitationsObject

Returns the value of attribute limitations

Returns:

  • (Object)

    the current value of limitations



3
4
5
# File 'lib/licensee/license_rules.rb', line 3

def limitations
  @limitations
end

#permissionsObject

Returns the value of attribute permissions

Returns:

  • (Object)

    the current value of permissions



3
4
5
# File 'lib/licensee/license_rules.rb', line 3

def permissions
  @permissions
end

Class Method Details

.from_hash(hash) ⇒ Object



22
23
24
25
# File 'lib/licensee/license_rules.rb', line 22

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

.from_license(license) ⇒ Object



8
9
10
# File 'lib/licensee/license_rules.rb', line 8

def from_license(license)
  from_meta(license.meta)
end

.from_meta(meta) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/licensee/license_rules.rb', line 12

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

Instance Method Details

#flattenObject



28
29
30
# File 'lib/licensee/license_rules.rb', line 28

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

#key?(key) ⇒ Boolean Also known as: has_key?

Returns:

  • (Boolean)


32
33
34
# File 'lib/licensee/license_rules.rb', line 32

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