buzzcore 0.3.5 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/buzzcore.gemspec +4 -2
- data/lib/buzzcore/config.rb +1 -0
- data/lib/buzzcore/tweaks.rb +107 -0
- data/rails/init.rb +16 -0
- metadata +4 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.4.0
|
data/buzzcore.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{buzzcore}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.4.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["buzzware"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-04-08}
|
13
13
|
s.description = %q{buzzcore is the ruby core library developed and used by Buzzware Solutions.}
|
14
14
|
s.email = %q{contact@buzzware.com.au}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -42,8 +42,10 @@ Gem::Specification.new do |s|
|
|
42
42
|
"lib/buzzcore/string_utils.rb",
|
43
43
|
"lib/buzzcore/text_doc.rb",
|
44
44
|
"lib/buzzcore/thread_utils.rb",
|
45
|
+
"lib/buzzcore/tweaks.rb",
|
45
46
|
"lib/buzzcore/xml_utils.rb",
|
46
47
|
"lib/buzzcore_dev.rb",
|
48
|
+
"rails/init.rb",
|
47
49
|
"test/buzzcore_test.rb",
|
48
50
|
"test/config_test.rb",
|
49
51
|
"test/credentials_test.rb",
|
data/lib/buzzcore/config.rb
CHANGED
@@ -76,6 +76,7 @@ class ConfigClass < Hash
|
|
76
76
|
when :Fixnum then set_int(aKey,aHash[aKey]);
|
77
77
|
when :TrueClass, :FalseClass then set_boolean(aKey,aHash[aKey]);
|
78
78
|
when :Symbol then self[aKey] = (aHash[aKey].to_sym rescue nil)
|
79
|
+
when :Proc then self[aKey] = aHash[aKey] if aHash[aKey].is_a?(Proc)
|
79
80
|
else
|
80
81
|
raise StandardError.new('unsupported type')
|
81
82
|
end
|
@@ -0,0 +1,107 @@
|
|
1
|
+
module Buzzcore
|
2
|
+
|
3
|
+
#class Tweak
|
4
|
+
#
|
5
|
+
# attr_reader :name
|
6
|
+
#
|
7
|
+
# def initialize(aName)
|
8
|
+
# @name = aName.to_sym
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# def config
|
12
|
+
# Tweaks.config_for(name)
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
#end
|
16
|
+
|
17
|
+
class Tweaks
|
18
|
+
|
19
|
+
@@configs = {}
|
20
|
+
@@switch = {}
|
21
|
+
@@switch_default = {}
|
22
|
+
|
23
|
+
#cattr_accessor :rails_config
|
24
|
+
|
25
|
+
# load all tweaks from a path
|
26
|
+
def self.load_all(aPath)
|
27
|
+
aPath = File.expand_path(aPath)
|
28
|
+
# get list of tweak_files
|
29
|
+
tweak_files = Dir.glob(File.join(aPath,'*_tweak.rb'))
|
30
|
+
tweak_files.each do |f|
|
31
|
+
Tweaks.load(f)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.load(aTweakFile)
|
36
|
+
#name = aTweakFile.scan(/.*\/(.+)_tweak\.rb$/).flatten.pop
|
37
|
+
#@@tweaks[name.to_sym] = Tweak.new(name)
|
38
|
+
if defined? Rails
|
39
|
+
require_dependency aTweakFile
|
40
|
+
else
|
41
|
+
::Kernel.load(aTweakFile)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.enable(*aTweakNames)
|
46
|
+
aTweakNames = [aTweakNames] unless aTweakNames.is_a?(Array)
|
47
|
+
aTweakNames.each do |n|
|
48
|
+
@@switch[n.to_sym] = true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.disable(*aTweakNames)
|
53
|
+
aTweakNames = [aTweakNames] unless aTweakNames.is_a?(Array)
|
54
|
+
aTweakNames.each do |n|
|
55
|
+
@@switch[n.to_sym] = false
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.header_enabled?(aTweak)
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.header_disabled?(aTweak)
|
63
|
+
end
|
64
|
+
|
65
|
+
# pass a hash to set
|
66
|
+
# returns config hash for modification
|
67
|
+
def self.config_for(aTweak,aHash=nil)
|
68
|
+
aTweak = aTweak.to_sym
|
69
|
+
if !(cf = @@configs[aTweak])
|
70
|
+
cf = {}
|
71
|
+
@@configs[aTweak] = cf
|
72
|
+
end
|
73
|
+
if aHash
|
74
|
+
if cf.is_a?(ConfigClass)
|
75
|
+
cf.reset()
|
76
|
+
cf.read(aHash)
|
77
|
+
else
|
78
|
+
@@configs[aTweak] = cf = aHash
|
79
|
+
end
|
80
|
+
end
|
81
|
+
cf
|
82
|
+
end
|
83
|
+
|
84
|
+
# pass a hash to set
|
85
|
+
# returns config hash for modification
|
86
|
+
#def self.defaults_for(aTweak,aHash=nil)
|
87
|
+
# c = config
|
88
|
+
#end
|
89
|
+
|
90
|
+
# called by tweak code (not sure if necessary)
|
91
|
+
# aDefaults creates an optional config object for this tweak with the given defaults and previously given values
|
92
|
+
# aNormally :enabled or :disabled
|
93
|
+
def self.define(aName,aNormally,aDefaults=nil)
|
94
|
+
config = @@configs[aName.to_sym]
|
95
|
+
@@configs[aName.to_sym] = config = ConfigClass.new(aDefaults,config) if aDefaults
|
96
|
+
@@switch_default[aName.to_sym] = (aNormally==:enabled || aNormally==true ? true : false)
|
97
|
+
en = enabled?(aName)
|
98
|
+
yield(config,aName) if en
|
99
|
+
en
|
100
|
+
end
|
101
|
+
|
102
|
+
def self.enabled?(aTweakName)
|
103
|
+
@@switch[aTweakName.to_sym]==nil ? @@switch_default[aTweakName.to_sym] : @@switch[aTweakName.to_sym]
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
data/rails/init.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#gem_root = File.expand_path(File.join(File.dirname(__FILE__), ".."))
|
2
|
+
#Cms.add_to_rails_paths gem_root
|
3
|
+
#
|
4
|
+
#throw RuntimeError.new('thumbs_cache folder must exist') unless File.exists? APP_CONFIG[:thumbs_cache]
|
5
|
+
#
|
6
|
+
#Cms::PageHelper.module_eval do
|
7
|
+
#
|
8
|
+
# extend BcmsTools::PageHelper
|
9
|
+
#
|
10
|
+
#end
|
11
|
+
#
|
12
|
+
config.after_initialize do
|
13
|
+
#Buzzcore::Tweaks.rails_config = config
|
14
|
+
Buzzcore::Tweaks.load_all(File.join(File.dirname(__FILE__),'../tweaks'))
|
15
|
+
Buzzcore::Tweaks.load_all(File.join(RAILS_ROOT,'tweaks'))
|
16
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: buzzcore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- buzzware
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-04-08 00:00:00 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -66,8 +66,10 @@ files:
|
|
66
66
|
- lib/buzzcore/string_utils.rb
|
67
67
|
- lib/buzzcore/text_doc.rb
|
68
68
|
- lib/buzzcore/thread_utils.rb
|
69
|
+
- lib/buzzcore/tweaks.rb
|
69
70
|
- lib/buzzcore/xml_utils.rb
|
70
71
|
- lib/buzzcore_dev.rb
|
72
|
+
- rails/init.rb
|
71
73
|
- test/buzzcore_test.rb
|
72
74
|
- test/config_test.rb
|
73
75
|
- test/credentials_test.rb
|