old_sql 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -4,6 +4,8 @@ source "http://rubygems.org"
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
 
6
6
  gem "sanitize"
7
+ gem "devise"
8
+ gem "cancan"
7
9
 
8
10
  # Add dependencies to develop your gem here.
9
11
  # Include everything needed to run rake, tests, features, etc.
@@ -2,6 +2,8 @@ require 'csv'
2
2
 
3
3
  module OldSql
4
4
  class ReportController < ApplicationController
5
+ before_filter :authenticate_user!
6
+ before_filter :ensure_old_sql_admin!
5
7
  before_filter :_init
6
8
  before_filter :_reports
7
9
 
@@ -99,6 +101,10 @@ module OldSql
99
101
 
100
102
 
101
103
  private
104
+ def ensure_old_sql_admin!
105
+ raise CanCan::AccessDenied unless current_user.old_sql_admin?
106
+ end
107
+
102
108
  def _init
103
109
  #todo add Devise support
104
110
  #@authorization_adapter.authorize(:index) if @authorization_adapter
@@ -108,7 +114,7 @@ module OldSql
108
114
  end
109
115
 
110
116
  def _reports
111
- template = File.read("#{Rails.root}/config/reports.yml")
117
+ template = File.read("#{Rails.root}/config/old_sql/reports.yml")
112
118
  @reports = YAML.load(Erubis::Eruby.new(template).result)
113
119
  end
114
120
 
@@ -0,0 +1,6 @@
1
+ -- Change the where clause so that it can be for your database
2
+
3
+ SELECT u.id, u.name
4
+ FROM users u
5
+ WHERE u.created_at > date('<%=start_date.gsub('/','-')%>')
6
+ AND u.created_at < date('<%=end_date.gsub('/','-')%>')
@@ -0,0 +1,15 @@
1
+ # Old SQL Reports YAML
2
+ # This is an example report. Replace it with your actual reports.
3
+ #
4
+ # 'processor:' is optional, and should point to a class in lib/old_sql.
5
+ # See lib/old_sql/user_processor.rb for an example.
6
+
7
+ user:
8
+ name: user
9
+ value: User
10
+ report_sql: user
11
+ virality: false
12
+ #processor: User_Processor
13
+ fields:
14
+ - 'id'
15
+ - 'name'
@@ -0,0 +1,15 @@
1
+ Description:
2
+ Installs Old SQL.
3
+
4
+ Examples:
5
+ `rails generate old_sql:install`
6
+
7
+ Creates locale and migration files:
8
+
9
+ Locales: config/locales/old_sql.XX.yml
10
+
11
+ Creates SQL and Parser directories and examples:
12
+
13
+ Reports: config/old_sql/reports.yml
14
+ SQL: config/old_sql/report_sql/
15
+ Parsers: lib/old_sql/report_processor/
@@ -0,0 +1,125 @@
1
+ module OldSql
2
+ class InstallGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ argument :model_name, :type => :string, :default => 'user'
5
+
6
+ desc "Old SQL Install"
7
+
8
+ def check_for_devise
9
+ puts "Hello!0
10
+ Old SQL works with devise. Checking for a current installation of devise!
11
+ "
12
+ if defined?(Devise)
13
+ check_for_devise_models
14
+ else
15
+ puts "Please put gem 'devise' into your Gemfile"
16
+ end
17
+
18
+ copy_locales_files
19
+ create_old_sql_dirs
20
+ copy_old_sql_files
21
+
22
+ puts "Also you need a new migration. We'll generate it for you now."
23
+ invoke 'old_sql:install_migrations'
24
+ end
25
+
26
+ private
27
+
28
+ def check_for_devise_models
29
+ # File.exists?
30
+ devise_path = FileUtils.pwd + "/config/initializers/devise.rb"
31
+
32
+ if File.exists?(devise_path)
33
+ parse_route_files
34
+ else
35
+ puts "Looks like you don't have devise install! We'll install it for you!"
36
+ invoke 'devise:install'
37
+ set_devise
38
+
39
+ end
40
+ end
41
+
42
+ def parse_route_files
43
+ # check if migrations exist
44
+ app_path = Rails.public_path.split("/")
45
+ app_path.delete_at(-1)
46
+ app_path = app_path.join("/")
47
+ routes_path = app_path + "/config/routes.rb"
48
+
49
+ content = ""
50
+
51
+ File.readlines(routes_path).each{|line|
52
+ content += line
53
+ }
54
+
55
+ unless content.index("devise_for").nil?
56
+ # there is a devise_for in routes => Do nothing
57
+ puts "Great! You have devise installed and setup!"
58
+ else
59
+ puts "Great you have devise installed, but not set up!"
60
+ set_devise
61
+ end
62
+ end
63
+
64
+ def set_devise
65
+ puts "Setting up devise for you!
66
+ ======================================================"
67
+ invoke 'devise', [model_name]
68
+ end
69
+
70
+ def copy_locales_files
71
+ print "Now copying locales files! "
72
+ gem_path = __FILE__
73
+ gem_path = gem_path.split("/")
74
+
75
+ gem_path = gem_path[0..-5]
76
+ gem_path = gem_path.join("/")
77
+ ###
78
+ locales_path = gem_path + "/config/locales/*.yml"
79
+
80
+ app_path = Rails.public_path.split("/")
81
+ app_path.delete_at(-1)
82
+ app_path = app_path.join("/")
83
+
84
+ app_path = app_path + "/config/locales"
85
+
86
+ unless File.directory?(app_path)
87
+ FileUtils.mkdir app_path
88
+ end
89
+
90
+ Dir.glob(locales_path).each do |file|
91
+ file_path = file.split("/")
92
+ file_path = file_path[-1]
93
+ FileUtils.copy_file(file, app_path + "/" + file_path)
94
+ print "."
95
+ end
96
+ print "\n"
97
+
98
+ end
99
+
100
+ def create_old_sql_dirs
101
+ app_path = Rails.public_path.split("/")
102
+ app_path.delete_at(-1)
103
+ app_path = app_path.join("/")
104
+
105
+ empty_directory(app_path + "/config/old_sql/")
106
+ empty_directory(app_path + "/config/old_sql/report_sql")
107
+ empty_directory(app_path + "/lib/old_sql/report_processor")
108
+ end
109
+
110
+ def copy_old_sql_files
111
+ app_path = Rails.public_path.split("/")
112
+ app_path.delete_at(-1)
113
+ app_path = app_path.join("/")
114
+
115
+ gem_path = __FILE__
116
+ gem_path = gem_path.split("/")
117
+ gem_path = gem_path[0..-5]
118
+ gem_path = gem_path.join("/")
119
+
120
+ copy_file gem_path + "/config/old_sql/reports.yml.example", app_path + "/config/old_sql/reports.yml"
121
+ copy_file gem_path + "/config/old_sql/report_sql/user.erb.example", app_path + "/config/old_sql/report_sql/user.erb"
122
+ copy_file gem_path + "/lib/old_sql/report_processor/user_processor.rb.example", app_path + "/lib/old_sql/report_processor/user_processor.rb"
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,24 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/migration'
3
+
4
+ module OldSql
5
+ class InstallMigrationsGenerator < Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+ source_root File.expand_path('../templates', __FILE__)
8
+
9
+ def self.next_migration_number(dirname)
10
+ if ActiveRecord::Base.timestamped_migrations
11
+ migration_number = Time.now.utc.strftime("%Y%m%d%H%M%S").to_i
12
+ migration_number += 1
13
+ migration_number.to_s
14
+ else
15
+ "%.3d" % (current_migration_number(dirname) + 1)
16
+ end
17
+ end
18
+
19
+ def create_migration_file
20
+ migration_template 'add_old_sql_admin_to_users_migration.rb', 'db/migrate/add_old_sql_admin_to_users.rb' rescue p $!.message
21
+ #sleep 1 # ensure scripts have different timestamps
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,23 @@
1
+ module OldSql
2
+ class OldSqlGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+ namespace "old_sql"
5
+
6
+ def print_instructions
7
+ puts "OldSql!
8
+
9
+ Hello, to install old_sql into your app you need to run:
10
+
11
+ rails g old_sql:install
12
+
13
+ By default Old SQL works with Devise to provide authentication. If you use
14
+ Devise, but want use another model than the default 'user' you can provide the
15
+ custom model name as an argument:
16
+
17
+ rails g old_sql:install member
18
+
19
+ "
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,9 @@
1
+ class AddOldSqlAdminToUsers < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :users, :old_sql_admin, :boolean, :default => false
4
+ end
5
+
6
+ def self.down
7
+ remove_column :users, :old_sql_admin
8
+ end
9
+ end
@@ -4,8 +4,6 @@ require "action_controller"
4
4
 
5
5
  module OldSql
6
6
  class Engine < Rails::Engine
7
- engine_name :old_sql
8
-
9
7
  initializer "static assets" do |app|
10
8
  app.middleware.use ::ActionDispatch::Static, "#{root}/public"
11
9
  end
@@ -15,7 +15,7 @@ module OldSql
15
15
  vars = vars.merge query_vars
16
16
  end
17
17
 
18
- template = File.read("#{Rails.root}/config/report_sql/#{report_sql}.erb")
18
+ template = File.read("#{Rails.root}/config/old_sql/report_sql/#{report_sql}.erb")
19
19
  sql = Erubis::Eruby.new(template).result(vars)
20
20
 
21
21
  Rails.logger.debug sql
@@ -0,0 +1,19 @@
1
+ require 'old_sql/report_processor/base'
2
+
3
+ module OldSql
4
+ module ReportProcessor
5
+ class UserProcessor < OldSql::ReportProcessor::Base
6
+
7
+ def parse(resultset)
8
+ init(resultset)
9
+
10
+ Rails.logger.debug "REC: #{@rec}"
11
+
12
+ new_row(nil, [@rec['id'], @rec['name']])
13
+ new_row('Totals', ['...'])
14
+
15
+ @data
16
+ end
17
+ end
18
+ end
19
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: old_sql
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.9.0
5
+ version: 0.10.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Eddie Gonzales
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-06 00:00:00 Z
13
+ date: 2011-06-08 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: sanitize
@@ -24,16 +24,38 @@ dependencies:
24
24
  prerelease: false
25
25
  version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
27
- name: jeweler
27
+ name: devise
28
28
  requirement: &id002 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: "0"
34
- type: :development
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: cancan
39
+ requirement: &id003 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
49
+ name: jeweler
50
+ requirement: &id004 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *id004
37
59
  description: OldSQL is a Rails Engine database reporting gem that uses plain old SQL
38
60
  email: egonzales@pureplay.com
39
61
  executables: []
@@ -54,11 +76,19 @@ files:
54
76
  - app/views/old_sql/report/index.html.erb
55
77
  - app/views/old_sql/report/print.html.erb
56
78
  - config/locales/old_sql.en.yml
79
+ - config/old_sql/report_sql/user.erb.example
80
+ - config/old_sql/reports.yml.example
57
81
  - config/routes.rb
58
82
  - lib/extensions/action_controller/base.rb
83
+ - lib/generators/old_sql/USAGE
84
+ - lib/generators/old_sql/install_generator.rb
85
+ - lib/generators/old_sql/install_migrations_generator.rb
86
+ - lib/generators/old_sql/old_sql_generator.rb
87
+ - lib/generators/old_sql/templates/add_old_sql_admin_to_users_migration.rb
59
88
  - lib/old_sql.rb
60
89
  - lib/old_sql/engine.rb
61
90
  - lib/old_sql/report_processor/base.rb
91
+ - lib/old_sql/report_processor/user_processor.rb.example
62
92
  - public/javascripts/old_sql/date_format.js
63
93
  - public/javascripts/old_sql/jqgrid/i18n/grid.locale-bg.js
64
94
  - public/javascripts/old_sql/jqgrid/i18n/grid.locale-bg1251.js
@@ -159,7 +189,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
159
189
  requirements:
160
190
  - - ">="
161
191
  - !ruby/object:Gem::Version
162
- hash: -772255520100120061
192
+ hash: -3491554766410394640
163
193
  segments:
164
194
  - 0
165
195
  version: "0"