platform 3.1.3 → 3.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. data/.rvmrc +1 -1
  2. data/Gemfile.lock +100 -103
  3. data/app/models/platform/application.rb +109 -57
  4. data/app/models/platform/application_category.rb +41 -22
  5. data/app/models/platform/application_developer.rb +39 -22
  6. data/app/models/platform/application_filter.rb +41 -22
  7. data/app/models/platform/application_log.rb +48 -22
  8. data/app/models/platform/application_log_filter.rb +41 -22
  9. data/app/models/platform/application_metric.rb +42 -23
  10. data/app/models/platform/application_metric_filter.rb +41 -22
  11. data/app/models/platform/application_permission.rb +38 -22
  12. data/app/models/platform/application_permission_filter.rb +41 -22
  13. data/app/models/platform/application_usage_metric.rb +43 -22
  14. data/app/models/platform/application_usage_metric_filter.rb +41 -22
  15. data/app/models/platform/application_user.rb +40 -22
  16. data/app/models/platform/application_user_filter.rb +41 -22
  17. data/app/models/platform/base_filter.rb +41 -22
  18. data/app/models/platform/category.rb +43 -22
  19. data/app/models/platform/daily_application_metric.rb +41 -22
  20. data/app/models/platform/developer.rb +42 -22
  21. data/app/models/platform/developer_filter.rb +41 -22
  22. data/app/models/platform/forum_message.rb +40 -22
  23. data/app/models/platform/forum_message_filter.rb +41 -22
  24. data/app/models/platform/forum_topic.rb +41 -22
  25. data/app/models/platform/forum_topic_filter.rb +41 -22
  26. data/app/models/platform/logged_exception.rb +47 -22
  27. data/app/models/platform/logged_exception_filter.rb +41 -22
  28. data/app/models/platform/monthly_application_metric.rb +41 -22
  29. data/app/models/platform/permission.rb +38 -22
  30. data/app/models/platform/rating.rb +42 -22
  31. data/app/models/platform/rating_filter.rb +41 -22
  32. data/app/models/platform/rollup_log.rb +39 -22
  33. data/app/models/platform/rollup_log_filter.rb +41 -22
  34. data/app/models/platform/total_application_metric.rb +41 -22
  35. data/app/models/platform/weekly_application_metric.rb +41 -22
  36. data/app/views/platform/developer/api_explorer/index.html.erb +4 -4
  37. data/app/views/platform/developer/apps/index.html.erb +5 -2
  38. data/lib/platform/config.rb +4 -0
  39. data/lib/platform/version.rb +1 -1
  40. data/lib/tasks/dev.rake +154 -0
  41. data/platform.gemspec +5 -6
  42. data/test/dummy/config/application.rb +2 -2
  43. metadata +46 -60
@@ -1,25 +1,42 @@
1
- #--
2
- # Copyright (c) 2011 Michael Berkovich
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
1
+ #--
2
+ # Copyright (c) 2010-2012 Michael Berkovich
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+ #
24
+ #-- Platform::RollupLog Schema Information
25
+ #
26
+ # Table name: platform_rollup_logs
27
+ #
28
+ # id INTEGER not null, primary key
29
+ # interval datetime
30
+ # started_at datetime
31
+ # finished_at datetime
32
+ # created_at datetime
33
+ # updated_at datetime
34
+ #
35
+ # Indexes
36
+ #
37
+ # index_platform_rollup_logs_on_interval (interval)
38
+ #
39
+ #++
23
40
 
24
41
  class Platform::RollupLog < ActiveRecord::Base
25
42
  set_table_name :platform_rollup_logs
@@ -1,25 +1,44 @@
1
- #--
2
- # Copyright (c) 2011 Michael Berkovich
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
1
+ #--
2
+ # Copyright (c) 2010-2012 Michael Berkovich
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+ #
24
+ #-- Platform::RollupLogFilter Schema Information
25
+ #
26
+ # Table name: will_filter_filters
27
+ #
28
+ # id INTEGER not null, primary key
29
+ # type varchar(255)
30
+ # name varchar(255)
31
+ # data text
32
+ # user_id integer
33
+ # model_class_name varchar(255)
34
+ # created_at datetime
35
+ # updated_at datetime
36
+ #
37
+ # Indexes
38
+ #
39
+ # index_will_filter_filters_on_user_id (user_id)
40
+ #
41
+ #++
23
42
 
24
43
  class Platform::RollupLogFilter < Platform::BaseFilter
25
44
 
@@ -1,25 +1,44 @@
1
- #--
2
- # Copyright (c) 2011 Michael Berkovich
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
1
+ #--
2
+ # Copyright (c) 2010-2012 Michael Berkovich
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+ #
24
+ #-- Platform::TotalApplicationMetric Schema Information
25
+ #
26
+ # Table name: platform_application_metrics
27
+ #
28
+ # id INTEGER not null, primary key
29
+ # type varchar(255)
30
+ # interval datetime
31
+ # application_id integer
32
+ # active_user_count integer
33
+ # new_user_count integer
34
+ # created_at datetime
35
+ # updated_at datetime
36
+ #
37
+ # Indexes
38
+ #
39
+ # pamai (application_id, interval)
40
+ #
41
+ #++
23
42
 
24
43
  class Platform::TotalApplicationMetric < Platform::ApplicationMetric
25
44
 
@@ -1,25 +1,44 @@
1
- #--
2
- # Copyright (c) 2011 Michael Berkovich
3
- #
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
- #++
1
+ #--
2
+ # Copyright (c) 2010-2012 Michael Berkovich
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+ #
24
+ #-- Platform::WeeklyApplicationMetric Schema Information
25
+ #
26
+ # Table name: platform_application_metrics
27
+ #
28
+ # id INTEGER not null, primary key
29
+ # type varchar(255)
30
+ # interval datetime
31
+ # application_id integer
32
+ # active_user_count integer
33
+ # new_user_count integer
34
+ # created_at datetime
35
+ # updated_at datetime
36
+ #
37
+ # Indexes
38
+ #
39
+ # pamai (application_id, interval)
40
+ #
41
+ #++
23
42
 
24
43
  class Platform::WeeklyApplicationMetric < Platform::ApplicationMetric
25
44
 
@@ -36,17 +36,17 @@
36
36
  <div class="section blue" style="margin-top:10px;">
37
37
  <table>
38
38
  <tr>
39
- <td style="width:50px;">
40
- <%=select_tag("api_version", options_for_select(Platform::Config.api_supported_version_options, @api_version), :onChange=>"switchApiVersion()")%>
39
+ <td style="width:55px;">
40
+ <%=select_tag("api_version", options_for_select(Platform::Config.api_supported_version_options, @api_version), :style=>"width:55px;", :onChange=>"switchApiVersion()")%>
41
41
  </td>
42
42
  <td style="width:80px;">
43
- <%=select_tag("request_method", options_for_select(['GET', 'POST', 'PUT', 'DELETE'], params[:method] || 'GET'), :style=>"", :onChange=>"switchRequestMethod()")%>
43
+ <%=select_tag("request_method", options_for_select(['GET', 'POST', 'PUT', 'DELETE'], params[:method] || 'GET'), :style=>"width:78px;", :onChange=>"switchRequestMethod()")%>
44
44
  </td>
45
45
  <td>
46
46
  <table cellspacing="0" cellpadding="0" style="border:1px solid #ccc;padding:0px;margin:0px;font-size:12px;vertical-align:middle; background-color:white;height:23px;">
47
47
  <tr>
48
48
  <td style="background-color:#eee;"><span style="padding-left:5px;vertical-align:middle;white-space:nowrap;padding-right:0px;">http://<%=Platform::Config.api_base_url%>/</span></td>
49
- <td><%=text_field_tag(:api_path, params[:path], :style=>"width:500px;border:0px;padding:0px;margin:0px;font-size:12px;vertical-align:middle;", :onKeyUp=>"if (event.keyCode == 13) {api_history_index=-1; submitRequest();}")%></td>
49
+ <td><%=text_field_tag(:api_path, params[:path], :style=>"width:530px;border:0px;padding:0px;margin:0px;font-size:14px;vertical-align:middle;", :onKeyUp=>"if (event.keyCode == 13) {api_history_index=-1; submitRequest();}")%></td>
50
50
  <td><span style="float:right;padding-right:5px;"><%=link_to_function(image_tag("platform/arrow_down.gif"), "toggleApiOptions(this)")%></span></td>
51
51
  </tr>
52
52
  </table>
@@ -289,7 +289,7 @@
289
289
  <%=link_to(tr("edit"), :action => :edit, :id => @app.id)%>
290
290
  </span>
291
291
  <%= platform_toggler_tag("authentication") %>
292
- <%=tr('Authentication', 'Client application section')%>
292
+ <%=tr('Authorization', 'Client application section')%>
293
293
  </div>
294
294
  <div id="authentication">
295
295
  <div class="app_key_value">
@@ -300,7 +300,10 @@
300
300
  <div class="app_key"><%=tr('Callback URL:', 'Client application field label')%></div>
301
301
  <div class="app_value"><%=@app.callback_url%></div>
302
302
  </div>
303
-
303
+ <div class="app_key_value">
304
+ <div class="app_key"><%=tr('Authorization URL:', 'Client application field label')%></div>
305
+ <div class="app_value"><%=@app.oauth_url%></div>
306
+ </div>
304
307
  <div class="app_key_value">
305
308
  <div class="app_key"><%=tr('Deauthorize Callback URL:', 'Client application field label')%></div>
306
309
  <div class="app_value"><%=@app.deauthorize_callback_url%></div>
@@ -280,6 +280,10 @@ module Platform
280
280
  site_info[:oauth_web_layout]
281
281
  end
282
282
 
283
+ def self.oauth_fluid_layout
284
+ site_info[:oauth_fluid_layout]
285
+ end
286
+
283
287
  def self.oauth_popup_layout
284
288
  site_info[:oauth_popup_layout]
285
289
  end
@@ -22,5 +22,5 @@
22
22
  #++
23
23
 
24
24
  module Platform
25
- VERSION = "3.1.3"
25
+ VERSION = "3.1.4"
26
26
  end
@@ -0,0 +1,154 @@
1
+ #--
2
+ # Copyright (c) 2010-2012 Michael Berkovich
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ namespace :dev do
25
+
26
+ # <ActiveRecord::ConnectionAdapters::SQLiteColumn:0x007fdffc77bee0
27
+ # @coder=nil,
28
+ # @default=nil,
29
+ # @limit=nil,
30
+ # @name="id",
31
+ # @null=false,
32
+ # @precision=nil,
33
+ # @primary=true,
34
+ # @scale=nil,
35
+ # @sql_type="INTEGER",
36
+ # @type=:integer>
37
+
38
+ # <struct ActiveRecord::ConnectionAdapters::IndexDefinition
39
+ # table="will_filter_filters",
40
+ # name="index_will_filter_filters_on_user_id",
41
+ # unique=false,
42
+ # columns=["user_id"],
43
+ # lengths=nil>
44
+
45
+ desc "Annotates tr8n models"
46
+ task :annotate => :environment do
47
+ Dir[File.expand_path("#{File.dirname(__FILE__)}/../../app/models/platform/*.rb")].sort.each do |file|
48
+ class_name = file[file.rindex('platform')..-1].gsub('.rb', '').camelcase
49
+ klass = class_name.constantize
50
+ lines = []
51
+ lines << "#--"
52
+ lines << "# Copyright (c) 2010-2012 Michael Berkovich"
53
+ lines << "#"
54
+ lines << "# Permission is hereby granted, free of charge, to any person obtaining"
55
+ lines << "# a copy of this software and associated documentation files (the"
56
+ lines << "# \"Software\"), to deal in the Software without restriction, including"
57
+ lines << "# without limitation the rights to use, copy, modify, merge, publish,"
58
+ lines << "# distribute, sublicense, and/or sell copies of the Software, and to"
59
+ lines << "# permit persons to whom the Software is furnished to do so, subject to"
60
+ lines << "# the following conditions:"
61
+ lines << "#"
62
+ lines << "# The above copyright notice and this permission notice shall be"
63
+ lines << "# included in all copies or substantial portions of the Software."
64
+ lines << "#"
65
+ lines << "# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,"
66
+ lines << "# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF"
67
+ lines << "# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND"
68
+ lines << "# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE"
69
+ lines << "# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION"
70
+ lines << "# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION"
71
+ lines << "# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
72
+ lines << "#++"
73
+ lines << "#"
74
+ lines << "#-- #{class_name} Schema Information"
75
+ lines << "#"
76
+ lines << "# Table name: #{klass.table_name}"
77
+ lines << "#"
78
+
79
+ name_width = 0
80
+ type_width = 0
81
+ sql_type_width = 0
82
+
83
+ klass.columns.each do |column|
84
+ name_width = [column.name.to_s.length, name_width].max
85
+ type_width = [column.type.to_s.length, type_width].max
86
+ sql_type_width = [column.sql_type.to_s.length, sql_type_width].max
87
+ end
88
+
89
+ klass.columns.each do |column|
90
+ line = ["# "]
91
+ line << column.name
92
+ line << (" " * (name_width - column.name.length + 4))
93
+ # line << column.type.to_s
94
+ # line << (" " * (type_width - column.type.to_s.length + 4))
95
+ line << column.sql_type
96
+ line << (" " * (sql_type_width - column.sql_type.to_s.length + 4))
97
+
98
+ meta = []
99
+ meta << "not null" if !column.null
100
+ meta << "primary key" if column.primary
101
+ meta << "default = #{column.default.to_s}" if column.default
102
+ line << meta.join(', ')
103
+
104
+ lines << line.join('')
105
+ end
106
+
107
+ lines << "#"
108
+ lines << "# Indexes"
109
+ lines << "#"
110
+
111
+ indexes = ActiveRecord::Base.connection.indexes(klass.table_name)
112
+
113
+ name_width = 0
114
+
115
+ indexes.each do |index|
116
+ name_width = [index.name.to_s.length, name_width].max
117
+ end
118
+
119
+ indexes.each do |index|
120
+ line = ["# "]
121
+ line << index.name
122
+ line << (" " * (name_width - index.name.length + 4))
123
+ line << "(#{index.columns.join(', ')})"
124
+ line << " "
125
+ line << "UNIQUE" if index.unique
126
+ lines << line.join('')
127
+ end
128
+
129
+ lines << "#"
130
+ lines << "#++"
131
+
132
+ pp "Updating #{file}..."
133
+
134
+ model_file = File.open(file, "r+")
135
+ old_lines = model_file.readlines
136
+ model_file.close
137
+
138
+ model_file = File.new(file, "w")
139
+ lines.each do |line|
140
+ model_file.write(line + "\r\n")
141
+ end
142
+
143
+ in_class = false
144
+ old_lines.each do |line|
145
+ in_class = true unless line.index("#") == 0
146
+
147
+ next unless in_class
148
+ model_file.write(line)
149
+ end
150
+ model_file.close
151
+ end
152
+ end
153
+
154
+ end