matholroyd-rails-standard-extensions 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/LICENSE +20 -0
- data/README.rdoc +8 -0
- data/Rakefile +46 -0
- data/VERSION.yml +4 -0
- data/lib/rails_standard_extensions.rb +63 -0
- data/spec/rails_standard_extensions_spec.rb +7 -0
- data/spec/spec_helper.rb +9 -0
- metadata +61 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Mat Holroyd
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "rails-standard-extensions"
|
8
|
+
gem.summary = "Standard rails extentions I find quite handy time to time"
|
9
|
+
gem.email = "matholroyd@gmail.com"
|
10
|
+
gem.homepage = "http://github.com/matholroyd/rails-standard-extensions"
|
11
|
+
gem.authors = ["Mat Holroyd"]
|
12
|
+
end
|
13
|
+
rescue LoadError
|
14
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
15
|
+
end
|
16
|
+
|
17
|
+
require 'spec/rake/spectask'
|
18
|
+
Spec::Rake::SpecTask.new(:spec) do |spec|
|
19
|
+
spec.libs << 'lib' << 'spec'
|
20
|
+
spec.spec_files = FileList['spec/**/*_spec.rb']
|
21
|
+
end
|
22
|
+
|
23
|
+
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
24
|
+
spec.libs << 'lib' << 'spec'
|
25
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
26
|
+
spec.rcov = true
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
task :default => :spec
|
31
|
+
|
32
|
+
require 'rake/rdoctask'
|
33
|
+
Rake::RDocTask.new do |rdoc|
|
34
|
+
if File.exist?('VERSION.yml')
|
35
|
+
config = YAML.load(File.read('VERSION.yml'))
|
36
|
+
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
|
37
|
+
else
|
38
|
+
version = ""
|
39
|
+
end
|
40
|
+
|
41
|
+
rdoc.rdoc_dir = 'rdoc'
|
42
|
+
rdoc.title = "rails-standard-extensions #{version}"
|
43
|
+
rdoc.rdoc_files.include('README*')
|
44
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
45
|
+
end
|
46
|
+
|
data/VERSION.yml
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
class String
|
2
|
+
def /(str_to_join)
|
3
|
+
File.join(self, str_to_join)
|
4
|
+
end
|
5
|
+
end
|
6
|
+
|
7
|
+
class Object
|
8
|
+
def pms
|
9
|
+
public_methods.sort.join(' ')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Time
|
14
|
+
def to_short
|
15
|
+
to_s('')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
if defined?(ActiveRecord)
|
20
|
+
|
21
|
+
class ActiveRecord::Base
|
22
|
+
def helpers
|
23
|
+
ActionController::Base.helpers
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.dump_to_yaml(dir = nil)
|
27
|
+
dir = RAILS_ROOT + (dir || "/db/backup/")
|
28
|
+
FileUtils.mkdir_p(dir)
|
29
|
+
file = dir + "#{self.table_name}.yml"
|
30
|
+
|
31
|
+
ActiveRecord::Base.transaction do
|
32
|
+
File.open(file, 'w+') do |f|
|
33
|
+
YAML.dump self.find(:all, :order => 'id').collect(&:attributes), f
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.load_from_yaml(dir = nil)
|
39
|
+
dir = RAILS_ROOT + (dir || "/db/backup/")
|
40
|
+
file = dir + "#{self.table_name}.yml"
|
41
|
+
|
42
|
+
ActiveRecord::Base.transaction do
|
43
|
+
self.delete_all
|
44
|
+
YAML.load_file(file).each do |fixture|
|
45
|
+
ActiveRecord::Base.connection.execute "INSERT INTO #{self.table_name} (#{fixture.keys.join(",")}) VALUES (#{fixture.values.collect { |value| ActiveRecord::Base.connection.quote(value) }.join(",")})", 'Fixture Insert'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.to_fixture
|
51
|
+
write_file(File.expand_path("test/fixtures/#{table_name}.yml", RAILS_ROOT),
|
52
|
+
self.find(:all).inject({}) { |hsh, record|
|
53
|
+
hsh.merge("record_#{record.id}" => record.attributes)
|
54
|
+
}.to_yaml)
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.write_file(path, content)
|
58
|
+
f = File.new(path, "w+")
|
59
|
+
f.puts content
|
60
|
+
f.close
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: matholroyd-rails-standard-extensions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mat Holroyd
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-04-13 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: matholroyd@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- LICENSE
|
27
|
+
- README.rdoc
|
28
|
+
- Rakefile
|
29
|
+
- VERSION.yml
|
30
|
+
- lib/rails_standard_extensions.rb
|
31
|
+
- spec/rails_standard_extensions_spec.rb
|
32
|
+
- spec/spec_helper.rb
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://github.com/matholroyd/rails-standard-extensions
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options:
|
37
|
+
- --charset=UTF-8
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: "0"
|
45
|
+
version:
|
46
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: "0"
|
51
|
+
version:
|
52
|
+
requirements: []
|
53
|
+
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.2.0
|
56
|
+
signing_key:
|
57
|
+
specification_version: 2
|
58
|
+
summary: Standard rails extentions I find quite handy time to time
|
59
|
+
test_files:
|
60
|
+
- spec/rails_standard_extensions_spec.rb
|
61
|
+
- spec/spec_helper.rb
|