Class: Tweaks
- Inherits:
-
Object
- Object
- Tweaks
- Defined in:
- lib/tweaks.rb
Class Method Summary collapse
-
.configure(aName, aConfig = nil) ⇒ Object
pass a hash to set returns config hash for modification.
-
.define(aName, aDefaults = nil, &block) ⇒ Object
called by tweak code (not sure if necessary) aDefaults creates an optional config object for this tweak with the given defaults and previously given values aNormally :enabled or :disabled.
- .define_and_install(aName, aConfig = nil, &block) ⇒ Object
- .do_it(aName, &block) ⇒ Object
- .have_config?(aName) ⇒ Boolean
- .installed?(aName) ⇒ Boolean
- .load(aTweakFile) ⇒ Object
-
.load_all(aPath) ⇒ Object
load all tweaks from a path.
- .reset ⇒ Object
Class Method Details
.configure(aName, aConfig = nil) ⇒ Object
pass a hash to set returns config hash for modification
67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/tweaks.rb', line 67 def self.configure(aName,aConfig=nil) aName = aName.to_sym if have_config?(aName) # will be defaults from define, so merge in app config config = @@configs[aName] config.read(aConfig) if aConfig @@configs[aName] = config else # store app config for merge later @@configs[aName] = TweakConfig.new(aConfig) end do_it(aName) if @@procs[aName] && !installed?(aName) # we have configured here, so install if we have define proc and not already installed @@configs[aName] end |
.define(aName, aDefaults = nil, &block) ⇒ Object
called by tweak code (not sure if necessary) aDefaults creates an optional config object for this tweak with the given defaults and previously given values aNormally :enabled or :disabled
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/tweaks.rb', line 44 def self.define(aName,aDefaults=nil,&block) aName = aName.to_sym aDefaults = TweakConfig.new(aDefaults) app_config = @@configs[aName.to_sym] if app_config @@configs[aName] = (app_config ? aDefaults.read(app_config) : aDefaults) do_it(aName,&block) else @@configs[aName] = aDefaults @@procs[aName] = block.to_proc end end |
.define_and_install(aName, aConfig = nil, &block) ⇒ Object
80 81 82 83 |
# File 'lib/tweaks.rb', line 80 def self.define_and_install(aName,aConfig=nil,&block) define(aName,aConfig,&block) configure(aName) end |
.do_it(aName, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/tweaks.rb', line 30 def self.do_it(aName,&block) return unless block_given? || (p = @@procs[aName]) @@installed << aName config = @@configs[aName] if block_given? yield(config,aName) else p.call(config,aName) end end |
.have_config?(aName) ⇒ Boolean
57 58 59 |
# File 'lib/tweaks.rb', line 57 def self.have_config?(aName) !!@@configs[aName.to_sym] end |
.installed?(aName) ⇒ Boolean
61 62 63 |
# File 'lib/tweaks.rb', line 61 def self.installed?(aName) !!@@installed.include?(aName.to_sym) end |
.load(aTweakFile) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/tweaks.rb', line 22 def self.load(aTweakFile) if defined? Rails require_dependency aTweakFile else ::Kernel.load(aTweakFile) end end |
.load_all(aPath) ⇒ Object
load all tweaks from a path
13 14 15 16 17 18 19 20 |
# File 'lib/tweaks.rb', line 13 def self.load_all(aPath) aPath = File.(aPath) # get list of tweak_files tweak_files = Dir.glob(File.join(aPath,'*_tweak.rb')) tweak_files.each do |f| Tweaks.load(f) end end |
.reset ⇒ Object
5 6 7 8 9 |
# File 'lib/tweaks.rb', line 5 def self.reset @@configs = {} # may contain defaults or config @@procs = {} @@installed = [] end |