Class: MrMurano::SyncRoot
- Inherits:
-
Object
- Object
- MrMurano::SyncRoot
- Defined in:
- lib/MrMurano/SyncUpDown.rb
Overview
Track what things are syncable.
Defined Under Namespace
Classes: Syncable
Class Method Summary collapse
-
.add(name, klass, type, desc, bydefault = false) ⇒ Object
- Add a new entry to syncable things
name - The name to use for the long option
klass - The class to instanciate from
type - Single letter for short option and status listing
desc -
Summary of what this syncs.
- Single letter for short option and status listing
- The class to instanciate from
- The name to use for the long option
- Add a new entry to syncable things
-
.bydefault ⇒ Object
Get the list of default syncables.
-
.checkSAME(opt) ⇒ Object
Adjust options based on all or none If none are selected, select the bydefault ones.
-
.each(&block) ⇒ Object
- Iterate over all syncables
block -
code to run on each.
- Iterate over all syncables
-
.each_filtered(opt, &block) ⇒ Object
Iterate over just the selected syncables.
-
.each_option(&block) ⇒ Object
Iterate over all syncables with option arguments.
-
.reset ⇒ Object
Remove all syncables.
Class Method Details
.add(name, klass, type, desc, bydefault = false) ⇒ Object
Add a new entry to syncable things
name-
The name to use for the long option
klass-
The class to instanciate from
type-
Single letter for short option and status listing
desc-
Summary of what this syncs.
bydefault-
Is this part of the default sync group
returns nil
23 24 25 26 27 |
# File 'lib/MrMurano/SyncUpDown.rb', line 23 def self.add(name, klass, type, desc, bydefault=false) @@syncset = [] unless defined?(@@syncset) @@syncset << Syncable.new(name.to_s, klass, type, desc, bydefault) nil end |
.bydefault ⇒ Object
Get the list of default syncables. returns array of names
38 39 40 |
# File 'lib/MrMurano/SyncUpDown.rb', line 38 def self.bydefault @@syncset.select{|a| a.bydefault }.map{|a| a.name} end |
.checkSAME(opt) ⇒ Object
Adjust options based on all or none If none are selected, select the bydefault ones.
opt-
Options hash of which to select from
returns nil
75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/MrMurano/SyncUpDown.rb', line 75 def self.checkSAME(opt) if opt[:all] then @@syncset.each {|a| opt[a.name.to_sym] = true } else any = @@syncset.select {|a| opt[a.name.to_sym] or opt[a.type.to_sym]} if any.empty? then bydef = $cfg['sync.bydefault'].split @@syncset.select{|a| bydef.include? a.name }.each{|a| opt[a.name.to_sym] = true} end end nil end |
.each(&block) ⇒ Object
Iterate over all syncables
block-
code to run on each
45 46 47 |
# File 'lib/MrMurano/SyncUpDown.rb', line 45 def self.each(&block) @@syncset.each{|a| yield a.name, a.type, a.class } end |
.each_filtered(opt, &block) ⇒ Object
Iterate over just the selected syncables.
opt-
Options hash of which to select from
block-
code to run on each
60 61 62 63 64 65 66 67 |
# File 'lib/MrMurano/SyncUpDown.rb', line 60 def self.each_filtered(opt, &block) self.checkSAME(opt) @@syncset.each do |a| if opt[a.name.to_sym] or opt[a.type.to_sym] then yield a.name, a.type, a.class end end end |
.each_option(&block) ⇒ Object
Iterate over all syncables with option arguments.
block-
code to run on each
52 53 54 |
# File 'lib/MrMurano/SyncUpDown.rb', line 52 def self.each_option(&block) @@syncset.each{|a| yield "-#{a.type.downcase}", "--[no-]#{a.name}", a.desc} end |
.reset ⇒ Object
Remove all syncables.
31 32 33 |
# File 'lib/MrMurano/SyncUpDown.rb', line 31 def self.reset() @@syncset = [] end |