tweaks 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/LICENSE +23 -0
- data/README.rdoc +77 -0
- data/Rakefile +66 -0
- data/VERSION +2 -0
- data/lib/tweak_config.rb +109 -0
- data/lib/tweaks.rb +87 -0
- data/pkg/tweaks-0.0.1.gem +0 -0
- data/rails/init.rb +5 -0
- data/rails_generators/tweak/templates/tweak.erb +12 -0
- data/rails_generators/tweak/tweak_generator.rb +34 -0
- data/test/config_spec.rb +26 -0
- data/test/main_spec.rb +91 -0
- data/test/test_helper.rb +10 -0
- data/tweaks.gemspec +63 -0
- data/tweaks.vpj +85 -0
- data/tweaks.vpw +6 -0
- metadata +101 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2008-2009 Gary McGhee - Buzzware Solutions, Western Australia - gary@buzzware.com.au
|
2
|
+
|
3
|
+
MIT Licence
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
= tweaks
|
2
|
+
|
3
|
+
* Author : Gary McGhee http://www.buzzware.com.au
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Tweaks are like tiny gems. In a single file you declare its name and default configuration,
|
8
|
+
and implement it. Project specific configuration can be provided seperately in your app, and
|
9
|
+
a defined tweak doesn't have to be installed at all.
|
10
|
+
|
11
|
+
What Tweaks does for you
|
12
|
+
|
13
|
+
Tweaks provides a minimal framework for implementing, configuring and distributing those
|
14
|
+
little pieces of code you develop and collect through developing multiple rails projects.
|
15
|
+
A tweak can be developed in the context of a Rails project with minimal friction. When the
|
16
|
+
project is delivered (and the pressure is off) you can move the tweak into its own gem or
|
17
|
+
copy it to the next Rails project (if you must - not recommended)
|
18
|
+
|
19
|
+
Why bother ?
|
20
|
+
|
21
|
+
* to be DRY
|
22
|
+
|
23
|
+
* to make those little hacks easy to develop during a project, then easily extractable from it for wider use
|
24
|
+
|
25
|
+
* to share with others
|
26
|
+
|
27
|
+
Advanced
|
28
|
+
|
29
|
+
* Tweaks can be moved to another rails app by copying or moving the *_tweak.rb files to a tweaks folder, then adding
|
30
|
+
the config to tweaks_config.rb
|
31
|
+
|
32
|
+
* Multiple tweaks could be stored in your own gem, and then loaded by a rails/init.rb file like the one in this gem
|
33
|
+
|
34
|
+
== FEATURES/PROBLEMS:
|
35
|
+
|
36
|
+
* untested with Rails 3
|
37
|
+
|
38
|
+
== REQUIREMENTS:
|
39
|
+
|
40
|
+
* tested on MacOS and Linux
|
41
|
+
|
42
|
+
== INSTALL:
|
43
|
+
|
44
|
+
> gem install tweaks
|
45
|
+
> cd <RAILS_ROOT>
|
46
|
+
> script/generate tweak blah
|
47
|
+
|
48
|
+
Now
|
49
|
+
|
50
|
+
- Define your tweak in the new file tweaks/blah_tweak.rb, with default values
|
51
|
+
- Configure it in config/initializers/tweaks_config.rb for your app
|
52
|
+
|
53
|
+
== LICENSE:
|
54
|
+
|
55
|
+
(The MIT License)
|
56
|
+
|
57
|
+
Copyright (c) 2010 (at Rails Camp Perth, Australia) by Gary McGhee, Buzzware Solutions
|
58
|
+
|
59
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
60
|
+
a copy of this software and associated documentation files (the
|
61
|
+
'Software'), to deal in the Software without restriction, including
|
62
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
63
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
64
|
+
permit persons to whom the Software is furnished to do so, subject to
|
65
|
+
the following conditions:
|
66
|
+
|
67
|
+
The above copyright notice and this permission notice shall be
|
68
|
+
included in all copies or substantial portions of the Software.
|
69
|
+
|
70
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
71
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
72
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
73
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
74
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
75
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
76
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
77
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "tweaks"
|
8
|
+
gem.summary = %Q{A minimal framework for implementing, configuring and distributing those little pieces of code}
|
9
|
+
gem.description = %Q{Tweaks provides a minimal framework for implementing, configuring and distributing those
|
10
|
+
little pieces of code you develop and collect through developing multiple rails projects.}
|
11
|
+
gem.email = "contact@buzzware.com.au"
|
12
|
+
gem.homepage = "http://github.com/buzzware/tweaks"
|
13
|
+
gem.authors = ["buzzware"]
|
14
|
+
gem.add_development_dependency "shoulda"
|
15
|
+
gem.files.include %w(
|
16
|
+
lib/tweaks.rb
|
17
|
+
)
|
18
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
19
|
+
end
|
20
|
+
Jeweler::GemcutterTasks.new
|
21
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
22
|
+
rubyforge.doc_task = "rdoc"
|
23
|
+
end
|
24
|
+
rescue LoadError
|
25
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |test|
|
30
|
+
test.libs << 'lib' << 'test'
|
31
|
+
test.pattern = 'test/**/*_test.rb'
|
32
|
+
test.verbose = true
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/*_test.rb'
|
40
|
+
test.verbose = true
|
41
|
+
end
|
42
|
+
rescue LoadError
|
43
|
+
task :rcov do
|
44
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
task :test => :check_dependencies
|
49
|
+
|
50
|
+
task :default => :test
|
51
|
+
|
52
|
+
require 'rake/rdoctask'
|
53
|
+
|
54
|
+
Rake::RDocTask.new do |rdoc|
|
55
|
+
if File.exist?('VERSION')
|
56
|
+
version = File.read('VERSION')
|
57
|
+
else
|
58
|
+
version = ""
|
59
|
+
end
|
60
|
+
|
61
|
+
rdoc.rdoc_dir = 'rdoc'
|
62
|
+
rdoc.title = "tweaks #{version}"
|
63
|
+
rdoc.rdoc_files.include('README*')
|
64
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
65
|
+
end
|
66
|
+
|
data/VERSION
ADDED
data/lib/tweak_config.rb
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# This is a cutdown version of ConfigClass from the buzzcore gem, and still is a bit messy.
|
2
|
+
# The idea is that the config can be declared with default values (enabling a reset to defaults),
|
3
|
+
# and that fields are implicitly declared with a type and value. New values for existing fields
|
4
|
+
# will then be converted to the original type. This is particularly useful eg if the values all
|
5
|
+
# come in as strings, but need to operate as other types
|
6
|
+
#
|
7
|
+
# use like this :
|
8
|
+
#
|
9
|
+
# config = TweakConfig.new(
|
10
|
+
# :something => String, # giving a class means the type is the given class, and the default value is nil
|
11
|
+
# :session_key => '_session',
|
12
|
+
# :upload_path=> 'cms/uploads',
|
13
|
+
# :thumbs_cache => File.expand_path('public/thumbs_cache',RAILS_ROOT), # make sure this exists with correct permissions
|
14
|
+
# :thumbs_url => '/thumbs_cache'
|
15
|
+
# :delay => 3.5,
|
16
|
+
# :log_level => :warn
|
17
|
+
# )
|
18
|
+
|
19
|
+
class TweakConfig < Hash
|
20
|
+
|
21
|
+
attr_reader :default_values
|
22
|
+
|
23
|
+
def initialize(aDefaultValues=nil,aGivenValues=nil)
|
24
|
+
@default_values = (aDefaultValues ? aDefaultValues.clone : {})
|
25
|
+
reset()
|
26
|
+
read(aGivenValues) if aGivenValues
|
27
|
+
end
|
28
|
+
|
29
|
+
# reset values back to defaults
|
30
|
+
def reset
|
31
|
+
self.clear
|
32
|
+
me = self
|
33
|
+
@default_values.each {|n,v| me[n] = v.is_a?(Class) ? nil : v}
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.to_integer(aValue,aDefault=nil)
|
37
|
+
t = aValue.strip
|
38
|
+
return aDefault if t.empty? || !t.index(/^-{0,1}[0-9]+$/)
|
39
|
+
return t.to_i
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.to_float(aValue,aDefault=nil)
|
43
|
+
t = aValue.strip
|
44
|
+
return aDefault if !t =~ /(\+|-)?([0-9]+\.?[0-9]*|\.[0-9]+)([eE](\+|-)?[0-9]+)?/
|
45
|
+
return t.to_f
|
46
|
+
end
|
47
|
+
|
48
|
+
def set_int(aKey,aValue)
|
49
|
+
case aValue
|
50
|
+
when String then self[aKey] = TweakConfig::to_integer(aValue,self[aKey]); # aValue.to_integer(self[aKey]);
|
51
|
+
when Fixnum then self[aKey] = aValue;
|
52
|
+
when Float then self[aKey] = aValue.to_i;
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def set_float(aKey,aValue)
|
57
|
+
case aValue
|
58
|
+
when String then self[aKey] = TweakConfig::to_float(aValue,self[aKey]) # aValue.to_float(self[aKey]);
|
59
|
+
when Fixnum then self[aKey] = aValue.to_f;
|
60
|
+
when Float then self[aKey] = aValue;
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def set_boolean(aKey,aValue)
|
65
|
+
case aValue
|
66
|
+
when TrueClass,FalseClass then self[aKey] = aValue;
|
67
|
+
when String then self[aKey] = (['1','yes','y','true','on'].include?(aValue.downcase))
|
68
|
+
else
|
69
|
+
set_boolean(aKey,aValue.to_s)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def set_symbol(aKey,aValue)
|
74
|
+
case aValue
|
75
|
+
when String then self[aKey] = (aValue.to_sym rescue nil);
|
76
|
+
when Symbol then self[aKey] = aValue;
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def copy_item(aHash,aKey)
|
81
|
+
d = default_values[aKey]
|
82
|
+
d_class = (d.is_a?(Class) ? d : d.class)
|
83
|
+
cname = d_class.name.to_sym
|
84
|
+
case cname
|
85
|
+
when :NilClass then ;
|
86
|
+
when :String then self[aKey] = aHash[aKey].to_s unless aHash[aKey].nil?
|
87
|
+
when :Float then set_float(aKey,aHash[aKey]);
|
88
|
+
when :Fixnum then set_int(aKey,aHash[aKey]);
|
89
|
+
when :TrueClass, :FalseClass then set_boolean(aKey,aHash[aKey]);
|
90
|
+
when :Symbol then self[aKey] = (aHash[aKey].to_sym rescue nil)
|
91
|
+
when :Proc then self[aKey] = aHash[aKey] if aHash[aKey].is_a?(Proc)
|
92
|
+
else
|
93
|
+
self[aKey] = aHash[aKey]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def read(aSource,aLimitToDefaults=false)
|
98
|
+
aSource.each do |k,v|
|
99
|
+
copy_item(aSource,k) unless aLimitToDefaults && !default_values.include?[k]
|
100
|
+
end
|
101
|
+
self
|
102
|
+
end
|
103
|
+
|
104
|
+
def to_hash
|
105
|
+
{}.merge(self)
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
data/lib/tweaks.rb
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__),'tweak_config')
|
2
|
+
|
3
|
+
class Tweaks
|
4
|
+
|
5
|
+
def self.reset
|
6
|
+
@@configs = {}
|
7
|
+
@@procs = {}
|
8
|
+
@@installed = []
|
9
|
+
end
|
10
|
+
reset()
|
11
|
+
|
12
|
+
# load all tweaks from a path
|
13
|
+
def self.load_all(aPath)
|
14
|
+
aPath = File.expand_path(aPath)
|
15
|
+
# get list of tweak_files
|
16
|
+
tweak_files = Dir.glob(File.join(aPath,'*_tweak.rb'))
|
17
|
+
tweak_files.each do |f|
|
18
|
+
Tweaks.load(f)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.load(aTweakFile)
|
23
|
+
if defined? Rails
|
24
|
+
require_dependency aTweakFile
|
25
|
+
else
|
26
|
+
::Kernel.load(aTweakFile)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.do_it(aName,&block)
|
31
|
+
return unless block_given? || (p = @@procs[aName])
|
32
|
+
@@installed << aName
|
33
|
+
config = @@configs[aName]
|
34
|
+
if block_given?
|
35
|
+
yield(config,aName)
|
36
|
+
else
|
37
|
+
p.call(config,aName)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# called by tweak code (not sure if necessary)
|
42
|
+
# aDefaults creates an optional config object for this tweak with the given defaults and previously given values
|
43
|
+
# aNormally :enabled or :disabled
|
44
|
+
def self.define(aName,aDefaults=nil,&block)
|
45
|
+
aName = aName.to_sym
|
46
|
+
aDefaults = TweakConfig.new(aDefaults)
|
47
|
+
app_config = @@configs[aName.to_sym]
|
48
|
+
if app_config
|
49
|
+
@@configs[aName] = (app_config ? aDefaults.read(app_config) : aDefaults)
|
50
|
+
do_it(aName,&block)
|
51
|
+
else
|
52
|
+
@@configs[aName] = aDefaults
|
53
|
+
@@procs[aName] = block.to_proc
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.have_config?(aName)
|
58
|
+
!!@@configs[aName.to_sym]
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.installed?(aName)
|
62
|
+
!!@@installed.include?(aName.to_sym)
|
63
|
+
end
|
64
|
+
|
65
|
+
# pass a hash to set
|
66
|
+
# returns config hash for modification
|
67
|
+
def self.configure(aName,aConfig=nil)
|
68
|
+
aName = aName.to_sym
|
69
|
+
if have_defaults = have_config?(aName) # will be defaults from define, so merge in app config
|
70
|
+
config = @@configs[aName]
|
71
|
+
config.read(aConfig) if aConfig
|
72
|
+
@@configs[aName] = config
|
73
|
+
else # store app config for merge later
|
74
|
+
@@configs[aName] = TweakConfig.new(aConfig)
|
75
|
+
end
|
76
|
+
do_it(aName) if have_defaults && !installed?(aName)
|
77
|
+
@@configs[aName]
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.define_and_install(aName,aConfig=nil,&block)
|
81
|
+
define(aName,aConfig,&block)
|
82
|
+
configure(aName)
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
end
|
87
|
+
|
Binary file
|
data/rails/init.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
Tweaks.define(
|
2
|
+
:<%= args.first %>, # name of tweak
|
3
|
+
{
|
4
|
+
# default config values here
|
5
|
+
}
|
6
|
+
) do |config,name|
|
7
|
+
|
8
|
+
# The tweak does its thing here, using the config given above
|
9
|
+
# Of course, you can declare a class or whatever above define to call here
|
10
|
+
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
class TweakGenerator < Rails::Generator::Base
|
2
|
+
|
3
|
+
TWEAKS_CONFIG_FILENAME = 'config/initializers/tweaks_config.rb'
|
4
|
+
|
5
|
+
def manifest
|
6
|
+
record do |m|
|
7
|
+
m.directory "tweaks"
|
8
|
+
m.template "tweak.erb", File.join("tweaks", "#{m.target.args.first}_tweak.rb") #:assigns => { :args => @gen_args }
|
9
|
+
|
10
|
+
tweaks_config_filepath = File.expand_path(TWEAKS_CONFIG_FILENAME,RAILS_ROOT)
|
11
|
+
tweaks_config_s = ''
|
12
|
+
File.open(tweaks_config_filepath, "r") { |f| tweaks_config_s = f.read } if File.exists?(tweaks_config_filepath)
|
13
|
+
STDOUT.puts "\n Creating/appending #{m.target.args.first} config to #{tweaks_config_filepath}\n\n"
|
14
|
+
tweaks_config_s += <<CONFIG_TEMPLATE
|
15
|
+
|
16
|
+
Tweaks.configure(
|
17
|
+
:#{m.target.args.first},
|
18
|
+
{
|
19
|
+
# config values here
|
20
|
+
}
|
21
|
+
)
|
22
|
+
|
23
|
+
CONFIG_TEMPLATE
|
24
|
+
|
25
|
+
File.open(tweaks_config_filepath,'w') {|file| file.write tweaks_config_s }
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
protected
|
30
|
+
def banner
|
31
|
+
"Usage: #{$0} #{spec.name} tweak_name"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/test/config_spec.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
gem "buzzcore"; require 'buzzcore'
|
2
|
+
require_paths '.','../lib'
|
3
|
+
require 'tweaks'
|
4
|
+
#require File.join(File.dirname(__FILE__),'test_helper')
|
5
|
+
|
6
|
+
describe "tweaks" do
|
7
|
+
it "create config and access" do
|
8
|
+
|
9
|
+
default_config = {
|
10
|
+
:name => String,
|
11
|
+
:age => 52,
|
12
|
+
:number_string => String,
|
13
|
+
:a_symbol => Symbol
|
14
|
+
}
|
15
|
+
later_config = {
|
16
|
+
:number_string => 5, :name => 'Roger', :a_symbol => 'apple'
|
17
|
+
}
|
18
|
+
result_config = TweakConfig.new(default_config,later_config)
|
19
|
+
result_config.should == {
|
20
|
+
:name => 'Roger',
|
21
|
+
:number_string => '5',
|
22
|
+
:age => 52,
|
23
|
+
:a_symbol => :apple
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
data/test/main_spec.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
gem "buzzcore"; require 'buzzcore'
|
2
|
+
require_paths '.','../lib'
|
3
|
+
require 'tweaks'
|
4
|
+
#require File.join(File.dirname(__FILE__),'test_helper')
|
5
|
+
|
6
|
+
describe "tweaks" do
|
7
|
+
|
8
|
+
before(:each) do
|
9
|
+
Tweaks.reset()
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should get execute immediately with define_and_install and correct config" do
|
13
|
+
received_config = nil
|
14
|
+
input_config = {:food => [:bacon, :bacon_salad, :pizza]}
|
15
|
+
|
16
|
+
Tweaks.define_and_install(
|
17
|
+
:lunch,
|
18
|
+
input_config
|
19
|
+
) do |config,name|
|
20
|
+
received_config = config
|
21
|
+
end
|
22
|
+
received_config.should == input_config
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should not get executed immediately on define, but is executed on config" do
|
26
|
+
received_config = nil
|
27
|
+
input_config = {:food => [:bacon, :bacon_salad, :pizza]}
|
28
|
+
Tweaks.define(
|
29
|
+
:lunch,
|
30
|
+
input_config
|
31
|
+
) do |config,name|
|
32
|
+
received_config = config
|
33
|
+
end
|
34
|
+
received_config.should == nil
|
35
|
+
Tweaks.configure(:lunch)
|
36
|
+
received_config.should == input_config
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
it "should not get executed immediately, but is executed on config and has merged config" do
|
41
|
+
received_config = nil
|
42
|
+
input_config = {
|
43
|
+
:name => String,
|
44
|
+
:age => 52,
|
45
|
+
:number_string => String,
|
46
|
+
:a_symbol => Symbol
|
47
|
+
}
|
48
|
+
Tweaks.define(
|
49
|
+
:person,
|
50
|
+
input_config
|
51
|
+
) do |config,name|
|
52
|
+
received_config = config
|
53
|
+
end
|
54
|
+
received_config.should == nil
|
55
|
+
Tweaks.configure(:person,{:number_string => 5, :name => 'Roger', :a_symbol => 'apple'})
|
56
|
+
received_config.should == {
|
57
|
+
:name => 'Roger',
|
58
|
+
:number_string => '5',
|
59
|
+
:age => 52,
|
60
|
+
:a_symbol => :apple
|
61
|
+
}
|
62
|
+
received_config.class.should == TweakConfig
|
63
|
+
end
|
64
|
+
|
65
|
+
it "when configured before defined, should be executed on define and has merged config" do
|
66
|
+
received_config = nil
|
67
|
+
input_config = {
|
68
|
+
:name => String,
|
69
|
+
:age => 52,
|
70
|
+
:number_string => String,
|
71
|
+
:a_symbol => Symbol
|
72
|
+
}
|
73
|
+
Tweaks.configure(:person,{:number_string => 5, :name => 'Roger', :a_symbol => 'apple'})
|
74
|
+
received_config.should == nil
|
75
|
+
Tweaks.define(
|
76
|
+
:person,
|
77
|
+
input_config
|
78
|
+
) do |config,name|
|
79
|
+
received_config = config
|
80
|
+
end
|
81
|
+
received_config.should == {
|
82
|
+
:name => 'Roger',
|
83
|
+
:number_string => '5',
|
84
|
+
:age => 52,
|
85
|
+
:a_symbol => :apple
|
86
|
+
}
|
87
|
+
received_config.class.should == TweakConfig
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
data/test/test_helper.rb
ADDED
data/tweaks.gemspec
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{tweaks}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["buzzware"]
|
12
|
+
s.date = %q{2010-11-15}
|
13
|
+
s.description = %q{Tweaks provides a minimal framework for implementing, configuring and distributing those
|
14
|
+
little pieces of code you develop and collect through developing multiple rails projects.}
|
15
|
+
s.email = %q{contact@buzzware.com.au}
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".gitignore",
|
22
|
+
"LICENSE",
|
23
|
+
"README.rdoc",
|
24
|
+
"Rakefile",
|
25
|
+
"VERSION",
|
26
|
+
"lib/tweak_config.rb",
|
27
|
+
"lib/tweaks.rb",
|
28
|
+
"pkg/tweaks-0.0.1.gem",
|
29
|
+
"rails/init.rb",
|
30
|
+
"rails_generators/tweak/templates/tweak.erb",
|
31
|
+
"rails_generators/tweak/tweak_generator.rb",
|
32
|
+
"test/config_spec.rb",
|
33
|
+
"test/main_spec.rb",
|
34
|
+
"test/test_helper.rb",
|
35
|
+
"tweaks.gemspec",
|
36
|
+
"tweaks.vpj",
|
37
|
+
"tweaks.vpw"
|
38
|
+
]
|
39
|
+
s.homepage = %q{http://github.com/buzzware/tweaks}
|
40
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
41
|
+
s.require_paths = ["lib"]
|
42
|
+
s.rubygems_version = %q{1.3.7}
|
43
|
+
s.summary = %q{A minimal framework for implementing, configuring and distributing those little pieces of code}
|
44
|
+
s.test_files = [
|
45
|
+
"test/config_spec.rb",
|
46
|
+
"test/main_spec.rb",
|
47
|
+
"test/test_helper.rb"
|
48
|
+
]
|
49
|
+
|
50
|
+
if s.respond_to? :specification_version then
|
51
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
52
|
+
s.specification_version = 3
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
55
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
58
|
+
end
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
data/tweaks.vpj
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
<!DOCTYPE Project SYSTEM "http://www.slickedit.com/dtd/vse/10.0/vpj.dtd">
|
2
|
+
<Project
|
3
|
+
Version="10.0"
|
4
|
+
VendorName="SlickEdit"
|
5
|
+
WorkingDir=".">
|
6
|
+
<Config
|
7
|
+
Name="Release"
|
8
|
+
OutputFile=""
|
9
|
+
CompilerConfigName="">
|
10
|
+
<Menu>
|
11
|
+
<Target
|
12
|
+
Name="Compile"
|
13
|
+
MenuCaption="&Compile"
|
14
|
+
CaptureOutputWith="ProcessBuffer"
|
15
|
+
SaveOption="SaveCurrent"
|
16
|
+
RunFromDir="%rw">
|
17
|
+
<Exec/>
|
18
|
+
</Target>
|
19
|
+
<Target
|
20
|
+
Name="Build"
|
21
|
+
MenuCaption="&Build"
|
22
|
+
CaptureOutputWith="ProcessBuffer"
|
23
|
+
SaveOption="SaveWorkspaceFiles"
|
24
|
+
RunFromDir="%rw">
|
25
|
+
<Exec/>
|
26
|
+
</Target>
|
27
|
+
<Target
|
28
|
+
Name="Rebuild"
|
29
|
+
MenuCaption="&Rebuild"
|
30
|
+
CaptureOutputWith="ProcessBuffer"
|
31
|
+
SaveOption="SaveWorkspaceFiles"
|
32
|
+
RunFromDir="%rw">
|
33
|
+
<Exec/>
|
34
|
+
</Target>
|
35
|
+
<Target
|
36
|
+
Name="Debug"
|
37
|
+
MenuCaption="&Debug"
|
38
|
+
SaveOption="SaveNone"
|
39
|
+
RunFromDir="%rw">
|
40
|
+
<Exec/>
|
41
|
+
</Target>
|
42
|
+
<Target
|
43
|
+
Name="Execute"
|
44
|
+
MenuCaption="E&xecute"
|
45
|
+
SaveOption="SaveNone"
|
46
|
+
RunFromDir="%rw">
|
47
|
+
<Exec CmdLine='".exe"'/>
|
48
|
+
</Target>
|
49
|
+
</Menu>
|
50
|
+
</Config>
|
51
|
+
<CustomFolders>
|
52
|
+
<Folder
|
53
|
+
Name="Source Files"
|
54
|
+
Filters="*.c;*.C;*.cc;*.cpp;*.cp;*.cxx;*.c++;*.prg;*.pas;*.dpr;*.asm;*.s;*.bas;*.java;*.cs;*.sc;*.e;*.cob;*.html;*.rc;*.tcl;*.py;*.pl;*.d"/>
|
55
|
+
<Folder
|
56
|
+
Name="Header Files"
|
57
|
+
Filters="*.h;*.H;*.hh;*.hpp;*.hxx;*.inc;*.sh;*.cpy;*.if"/>
|
58
|
+
<Folder
|
59
|
+
Name="Resource Files"
|
60
|
+
Filters="*.ico;*.cur;*.dlg"/>
|
61
|
+
<Folder
|
62
|
+
Name="Bitmaps"
|
63
|
+
Filters="*.bmp"/>
|
64
|
+
<Folder
|
65
|
+
Name="Other Files"
|
66
|
+
Filters="">
|
67
|
+
</Folder>
|
68
|
+
</CustomFolders>
|
69
|
+
<Files AutoFolders="DirectoryView">
|
70
|
+
<Folder Name="rails_generators">
|
71
|
+
<F
|
72
|
+
N="rails_generators/*"
|
73
|
+
Recurse="1"
|
74
|
+
Refilter="0"
|
75
|
+
Excludes=""/>
|
76
|
+
</Folder>
|
77
|
+
<F
|
78
|
+
N="*.rb"
|
79
|
+
Recurse="1"
|
80
|
+
Refilter="0"
|
81
|
+
Excludes=".git"/>
|
82
|
+
<F N="Rakefile"/>
|
83
|
+
<F N="README.rdoc"/>
|
84
|
+
</Files>
|
85
|
+
</Project>
|
data/tweaks.vpw
ADDED
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tweaks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- buzzware
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-11-15 00:00:00 +08:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: shoulda
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: |-
|
36
|
+
Tweaks provides a minimal framework for implementing, configuring and distributing those
|
37
|
+
little pieces of code you develop and collect through developing multiple rails projects.
|
38
|
+
email: contact@buzzware.com.au
|
39
|
+
executables: []
|
40
|
+
|
41
|
+
extensions: []
|
42
|
+
|
43
|
+
extra_rdoc_files:
|
44
|
+
- LICENSE
|
45
|
+
- README.rdoc
|
46
|
+
files:
|
47
|
+
- .gitignore
|
48
|
+
- LICENSE
|
49
|
+
- README.rdoc
|
50
|
+
- Rakefile
|
51
|
+
- VERSION
|
52
|
+
- lib/tweak_config.rb
|
53
|
+
- lib/tweaks.rb
|
54
|
+
- pkg/tweaks-0.0.1.gem
|
55
|
+
- rails/init.rb
|
56
|
+
- rails_generators/tweak/templates/tweak.erb
|
57
|
+
- rails_generators/tweak/tweak_generator.rb
|
58
|
+
- test/config_spec.rb
|
59
|
+
- test/main_spec.rb
|
60
|
+
- test/test_helper.rb
|
61
|
+
- tweaks.gemspec
|
62
|
+
- tweaks.vpj
|
63
|
+
- tweaks.vpw
|
64
|
+
has_rdoc: true
|
65
|
+
homepage: http://github.com/buzzware/tweaks
|
66
|
+
licenses: []
|
67
|
+
|
68
|
+
post_install_message:
|
69
|
+
rdoc_options:
|
70
|
+
- --charset=UTF-8
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
version: "0"
|
91
|
+
requirements: []
|
92
|
+
|
93
|
+
rubyforge_project:
|
94
|
+
rubygems_version: 1.3.7
|
95
|
+
signing_key:
|
96
|
+
specification_version: 3
|
97
|
+
summary: A minimal framework for implementing, configuring and distributing those little pieces of code
|
98
|
+
test_files:
|
99
|
+
- test/config_spec.rb
|
100
|
+
- test/main_spec.rb
|
101
|
+
- test/test_helper.rb
|