make_exportable 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/spec/models.rb ADDED
@@ -0,0 +1,44 @@
1
+ class User < ActiveRecord::Base
2
+
3
+ has_many :posts
4
+
5
+ def self.nonsense_method_for_test
6
+ end
7
+
8
+ def full_name
9
+ "#{first_name} #{last_name}"
10
+ end
11
+
12
+ def is_admin
13
+ false
14
+ end
15
+
16
+ def admin_export
17
+ unless is_admin
18
+ "monkey"
19
+ end
20
+ end
21
+
22
+ if ActiveRecord::VERSION::MAJOR >= 3
23
+ scope :a_limiter, :limit => 1
24
+ scope :order_by, :order => "ID DESC"
25
+ scope :nothing, :conditions => {:first_name => "unfound"}
26
+ else
27
+ named_scope :a_limiter, :limit => 1
28
+ named_scope :order_by, :order => "ID DESC"
29
+ named_scope :nothing, :conditions => {:first_name => "unfound"}
30
+ end
31
+
32
+ end
33
+
34
+ class Post < ActiveRecord::Base
35
+
36
+ belongs_to :user
37
+
38
+ end
39
+
40
+ class Unexportable < ActiveRecord::Base
41
+
42
+ belongs_to :user
43
+
44
+ end
data/spec/schema.rb ADDED
@@ -0,0 +1,16 @@
1
+ ActiveRecord::Schema.define :version => 0 do
2
+
3
+ create_table :users, :force => true do |t|
4
+ t.string :first_name, :last_name, :password, :email
5
+ t.boolean :is_admin
6
+ t.timestamps
7
+ end
8
+
9
+ create_table :posts, :force => true do |t|
10
+ t.string :title
11
+ t.text :content
12
+ t.boolean :approved
13
+ t.timestamps
14
+ end
15
+
16
+ end
@@ -0,0 +1,55 @@
1
+ $LOAD_PATH << "." unless $LOAD_PATH.include?(".")
2
+
3
+ begin
4
+ require "rubygems"
5
+ require "bundler"
6
+ require "active_record"
7
+ require "fastercsv" unless ActiveRecord::VERSION::MAJOR >= 3
8
+
9
+
10
+
11
+ if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.5")
12
+ raise RuntimeError, "Your bundler version is too old." +
13
+ "Run `gem install bundler` to upgrade."
14
+ end
15
+
16
+ # Set up load paths for all bundled gems
17
+ Bundler.setup
18
+ rescue Bundler::GemNotFound
19
+ raise RuntimeError, "Bundler couldn't find some gems." +
20
+ "Did you run `bundle install`?"
21
+ end
22
+
23
+ Bundler.require(:default, :test)
24
+
25
+ require File.expand_path('../../lib/make_exportable', __FILE__)
26
+ Date::DATE_FORMATS[:default] = '%d/%m/%Y'
27
+ Time::DATE_FORMATS[:default] = '%A %B %d %Y at %I:%M%p'
28
+
29
+ ENV['DB'] ||= 'sqlite3'
30
+
31
+ database_yml = File.expand_path('../database.yml', __FILE__)
32
+ if File.exists?(database_yml)
33
+ active_record_configuration = YAML.load_file(database_yml)[ENV['DB']]
34
+
35
+ ActiveRecord::Base.establish_connection(active_record_configuration)
36
+ ActiveRecord::Base.logger = Logger.new(File.join(File.dirname(__FILE__), "debug.log"))
37
+
38
+ ActiveRecord::Base.silence do
39
+ ActiveRecord::Migration.verbose = false
40
+
41
+ load(File.dirname(__FILE__) + '/schema.rb')
42
+ load(File.dirname(__FILE__) + '/models.rb')
43
+ end
44
+
45
+ else
46
+ raise "Please create #{database_yml} first to configure your database. Take a look at: #{database_yml}.sample"
47
+ end
48
+
49
+ def clean_database!
50
+ models = [User, Post]
51
+ models.each do |model|
52
+ ActiveRecord::Base.connection.execute "DELETE FROM #{model.table_name}"
53
+ ActiveRecord::Base.connection.execute "delete from sqlite_sequence where name='#{model.table_name}'"
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: make_exportable
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Kevin Skoglund
14
+ - Matthew Bergman
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2010-06-21 00:00:00 -04:00
20
+ default_executable:
21
+ dependencies: []
22
+
23
+ description: MakeExportable is a Rails gem/plugin to assist in exporting application data as CSV, TSV, JSON, HTML, XML or Excel. Filter and limit the data exported using ActiveRecord. Export returned values from instance methods as easily as database columns.
24
+ email: kevin@novafabrica.com
25
+ executables: []
26
+
27
+ extensions: []
28
+
29
+ extra_rdoc_files:
30
+ - README.rdoc
31
+ files:
32
+ - Gemfile
33
+ - MIT-LICENSE
34
+ - README.rdoc
35
+ - Rakefile
36
+ - VERSION
37
+ - lib/make_exportable.rb
38
+ - lib/make_exportable/core.rb
39
+ - lib/make_exportable/errors.rb
40
+ - lib/make_exportable/exportable_format.rb
41
+ - lib/make_exportable/exportable_formats/csv.rb
42
+ - lib/make_exportable/exportable_formats/excel.rb
43
+ - lib/make_exportable/exportable_formats/html.rb
44
+ - lib/make_exportable/exportable_formats/json.rb
45
+ - lib/make_exportable/exportable_formats/tsv.rb
46
+ - lib/make_exportable/exportable_formats/xml.rb
47
+ - lib/make_exportable/make_exportable_helper.rb
48
+ - lib/make_exportable/version.rb
49
+ - rails/init.rb
50
+ - spec/database.yml
51
+ - spec/database.yml.sample
52
+ - spec/make_exportable/formats_spec.rb
53
+ - spec/make_exportable/make_exportable_helper_spec.rb
54
+ - spec/make_exportable/make_exportable_spec.rb
55
+ - spec/models.rb
56
+ - spec/schema.rb
57
+ - spec/spec_helper.rb
58
+ has_rdoc: true
59
+ homepage: http://github.com/novafabrica/make_exportable
60
+ licenses: []
61
+
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --charset=UTF-8
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ requirements: []
86
+
87
+ rubyforge_project:
88
+ rubygems_version: 1.3.7
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: Makes any Rails model easily exportable
92
+ test_files:
93
+ - spec/make_exportable/formats_spec.rb
94
+ - spec/make_exportable/make_exportable_helper_spec.rb
95
+ - spec/make_exportable/make_exportable_spec.rb
96
+ - spec/models.rb
97
+ - spec/schema.rb
98
+ - spec/spec_helper.rb