Class: LicenseFinder::Decisions
- Inherits:
-
Object
- Object
- LicenseFinder::Decisions
- Defined in:
- lib/license_finder/decisions.rb
Defined Under Namespace
Classes: TXN
Instance Attribute Summary collapse
-
#ignored ⇒ Object
readonly
READ.
-
#ignored_groups ⇒ Object
readonly
READ.
-
#packages ⇒ Object
readonly
READ.
-
#project_name ⇒ Object
readonly
READ.
-
#whitelisted ⇒ Object
readonly
READ.
Class Method Summary collapse
Instance Method Summary collapse
- #add_package(name, version, txn = {}) ⇒ Object
- #approval_of(name) ⇒ Object
- #approve(name, txn = {}) ⇒ Object
- #approved?(name) ⇒ Boolean
- #heed(name, txn = {}) ⇒ Object
- #heed_group(name, txn = {}) ⇒ Object
- #ignore(name, txn = {}) ⇒ Object
- #ignore_group(name, txn = {}) ⇒ Object
- #ignored?(name) ⇒ Boolean
- #ignored_group?(name) ⇒ Boolean
-
#initialize ⇒ Decisions
constructor
A new instance of Decisions.
- #license(name, lic, txn = {}) ⇒ Object
- #licenses_of(name) ⇒ Object
- #name_project(name, txn = {}) ⇒ Object
- #persist ⇒ Object
- #remove_package(name, txn = {}) ⇒ Object
- #save!(file) ⇒ Object
- #unapprove(name, txn = {}) ⇒ Object
- #unlicense(name, lic, txn = {}) ⇒ Object
- #unname_project(txn = {}) ⇒ Object
- #unwhitelist(lic, txn = {}) ⇒ Object
- #whitelist(lic, txn = {}) ⇒ Object
- #whitelisted?(lic) ⇒ Boolean
- #write!(value, file) ⇒ Object
Constructor Details
#initialize ⇒ Decisions
Returns a new instance of Decisions.
43 44 45 46 47 48 49 50 51 |
# File 'lib/license_finder/decisions.rb', line 43 def initialize @decisions = [] @packages = Set.new @licenses = Hash.new { |h, k| h[k] = Set.new } @approvals = {} @whitelisted = Set.new @ignored = Set.new @ignored_groups = Set.new end |
Instance Attribute Details
#ignored ⇒ Object (readonly)
READ
7 8 9 |
# File 'lib/license_finder/decisions.rb', line 7 def ignored @ignored end |
#ignored_groups ⇒ Object (readonly)
READ
7 8 9 |
# File 'lib/license_finder/decisions.rb', line 7 def ignored_groups @ignored_groups end |
#packages ⇒ Object (readonly)
READ
7 8 9 |
# File 'lib/license_finder/decisions.rb', line 7 def packages @packages end |
#project_name ⇒ Object (readonly)
READ
7 8 9 |
# File 'lib/license_finder/decisions.rb', line 7 def project_name @project_name end |
#whitelisted ⇒ Object (readonly)
READ
7 8 9 |
# File 'lib/license_finder/decisions.rb', line 7 def whitelisted @whitelisted end |
Class Method Details
.read!(file) ⇒ Object
163 164 165 |
# File 'lib/license_finder/decisions.rb', line 163 def self.read!(file) file.read if file.exist? end |
.restore(persisted) ⇒ Object
149 150 151 152 153 154 155 156 157 |
# File 'lib/license_finder/decisions.rb', line 149 def self.restore(persisted) result = new if persisted YAML.load(persisted).each do |action, *args| result.send(action, *args) end end result end |
.saved!(file) ⇒ Object
PERSIST
141 142 143 |
# File 'lib/license_finder/decisions.rb', line 141 def self.saved!(file) restore(read!(file)) end |
Instance Method Details
#add_package(name, version, txn = {}) ⇒ Object
53 54 55 56 57 |
# File 'lib/license_finder/decisions.rb', line 53 def add_package(name, version, txn = {}) @decisions << [:add_package, name, version, txn] @packages << ManualPackage.new(name, version) self end |
#approval_of(name) ⇒ Object
13 14 15 |
# File 'lib/license_finder/decisions.rb', line 13 def approval_of(name) @approvals[name] end |
#approve(name, txn = {}) ⇒ Object
77 78 79 80 81 |
# File 'lib/license_finder/decisions.rb', line 77 def approve(name, txn = {}) @decisions << [:approve, name, txn] @approvals[name] = TXN.from_hash(txn) self end |
#approved?(name) ⇒ Boolean
17 18 19 |
# File 'lib/license_finder/decisions.rb', line 17 def approved?(name) @approvals.has_key?(name) end |
#heed(name, txn = {}) ⇒ Object
107 108 109 110 111 |
# File 'lib/license_finder/decisions.rb', line 107 def heed(name, txn = {}) @decisions << [:heed, name, txn] @ignored.delete(name) self end |
#heed_group(name, txn = {}) ⇒ Object
119 120 121 122 123 |
# File 'lib/license_finder/decisions.rb', line 119 def heed_group(name, txn = {}) @decisions << [:heed_group, name, txn] @ignored_groups.delete(name) self end |
#ignore(name, txn = {}) ⇒ Object
101 102 103 104 105 |
# File 'lib/license_finder/decisions.rb', line 101 def ignore(name, txn = {}) @decisions << [:ignore, name, txn] @ignored << name self end |
#ignore_group(name, txn = {}) ⇒ Object
113 114 115 116 117 |
# File 'lib/license_finder/decisions.rb', line 113 def ignore_group(name, txn = {}) @decisions << [:ignore_group, name, txn] @ignored_groups << name self end |
#ignored?(name) ⇒ Boolean
25 26 27 |
# File 'lib/license_finder/decisions.rb', line 25 def ignored?(name) @ignored.include?(name) end |
#ignored_group?(name) ⇒ Boolean
29 30 31 |
# File 'lib/license_finder/decisions.rb', line 29 def ignored_group?(name) @ignored_groups.include?(name) end |
#license(name, lic, txn = {}) ⇒ Object
65 66 67 68 69 |
# File 'lib/license_finder/decisions.rb', line 65 def license(name, lic, txn = {}) @decisions << [:license, name, lic, txn] @licenses[name] << License.find_by_name(lic) self end |
#licenses_of(name) ⇒ Object
9 10 11 |
# File 'lib/license_finder/decisions.rb', line 9 def licenses_of(name) @licenses[name] end |
#name_project(name, txn = {}) ⇒ Object
125 126 127 128 129 |
# File 'lib/license_finder/decisions.rb', line 125 def name_project(name, txn = {}) @decisions << [:name_project, name, txn] @project_name = name self end |
#persist ⇒ Object
159 160 161 |
# File 'lib/license_finder/decisions.rb', line 159 def persist YAML.dump(@decisions) end |
#remove_package(name, txn = {}) ⇒ Object
59 60 61 62 63 |
# File 'lib/license_finder/decisions.rb', line 59 def remove_package(name, txn = {}) @decisions << [:remove_package, name, txn] @packages.delete(ManualPackage.new(name)) self end |
#save!(file) ⇒ Object
145 146 147 |
# File 'lib/license_finder/decisions.rb', line 145 def save!(file) write!(persist, file) end |
#unapprove(name, txn = {}) ⇒ Object
83 84 85 86 87 |
# File 'lib/license_finder/decisions.rb', line 83 def unapprove(name, txn = {}) @decisions << [:unapprove, name, txn] @approvals.delete(name) self end |
#unlicense(name, lic, txn = {}) ⇒ Object
71 72 73 74 75 |
# File 'lib/license_finder/decisions.rb', line 71 def unlicense(name, lic, txn= {}) @decisions << [:unlicense, name, lic, txn] @licenses[name].delete(License.find_by_name(lic)) self end |
#unname_project(txn = {}) ⇒ Object
131 132 133 134 135 |
# File 'lib/license_finder/decisions.rb', line 131 def unname_project(txn = {}) @decisions << [:unname_project, txn] @project_name = nil self end |
#unwhitelist(lic, txn = {}) ⇒ Object
95 96 97 98 99 |
# File 'lib/license_finder/decisions.rb', line 95 def unwhitelist(lic, txn = {}) @decisions << [:unwhitelist, lic, txn] @whitelisted.delete(License.find_by_name(lic)) self end |
#whitelist(lic, txn = {}) ⇒ Object
89 90 91 92 93 |
# File 'lib/license_finder/decisions.rb', line 89 def whitelist(lic, txn = {}) @decisions << [:whitelist, lic, txn] @whitelisted << License.find_by_name(lic) self end |
#whitelisted?(lic) ⇒ Boolean
21 22 23 |
# File 'lib/license_finder/decisions.rb', line 21 def whitelisted?(lic) @whitelisted.include?(lic) end |
#write!(value, file) ⇒ Object
167 168 169 170 171 172 |
# File 'lib/license_finder/decisions.rb', line 167 def write!(value, file) file.dirname.mkpath file.open('w+') do |f| f.print value end end |