caboose-cms 0.2.94 → 0.2.95

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NGUwMmFkNzY5NTVlYWJkYmNlMmUyZmQzMjc4NTk2NmFhN2Q0NTZjZA==
4
+ MTk4NzgwZDZiMDIyOGM5ZDhlMDY3YmMwYTE1MjIxZGQ0ZDA3ODA0NA==
5
5
  data.tar.gz: !binary |-
6
- ZmNlNjg1OTgzOWMyYmZiMmFjNGNkY2I5MTllMzM4OGEyZmY3MmQwNA==
6
+ ODcwMTk0ZWZkOWUyNDRmOTM2YzRlYmY2MDYxMjA0YzE3ZDAxNzdhZA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NThiN2FlNjM5M2Q5YzIyOGFjN2RlZGM2Y2FlZjFkMTBiYzVmZTQ5NjY3Zjdm
10
- YWYwYmMxYmFiMmIzNTdmNTkwY2ZkOGQ1MTk0ZWFiOGJjOTI0MjAyOGMwODkw
11
- ZjU4MWQxZTA4MjYxMzUwYzMwYmJmOWQzZDNkMDU5ZDIzMmFkNGQ=
9
+ NWJkMGQ0ZjkyMTljM2NjZTA2M2MxYTgwYjRhNjZkYmNjMTk0MjEwOGY5Mzc1
10
+ ZGVhMzQ3NjRlNDhkZTQwMWMwMTI4ZmU4ZmFkZDE3OTg3MjQ4MjAyOTdmNjVi
11
+ NGEzMTQzNWY1MWNkY2U2NGFkYjM2ZGEyMjNkMTVjYzNiOGQ3Yjk=
12
12
  data.tar.gz: !binary |-
13
- YmY4OGNkODZkZWRhOTIzODRkZmJhNWUxOWI2NGU3NDNhYWExMDRiMDRiNTVm
14
- YmJmOWVhNjRjNjUyODg5M2UwNmJhMmUxYTI4NTMwOGIxZTEwY2U4Y2IwMzRm
15
- NjdjNDc0MTk0OTQ3ZGJiZTIzYWRhZDU2M2I0MmE4NWE5ZjQwMjY=
13
+ NGQ1NDkxYzE4NTIzMDM1ZWMwYzU2YzFkZTZlMTc0NTJmYTU3NmI5NzE0YzNh
14
+ M2U3YTZiM2YwNzcwNTkyZTM4YzI2MmZlN2U3M2NiZDY3ZTNkODIxNzVjY2Iy
15
+ MjdkY2VkZDU3N2I5YjA5YTNmODI3OTcxMmUwNTA1YTRmMjQ3MDU=
@@ -132,7 +132,13 @@ module Caboose
132
132
  def get_vars()
133
133
  vars = []
134
134
  @params.each do |k,v|
135
- vars.push("#{k}=#{v}") if !v.nil? && v.length > 0
135
+ if v.kind_of?(Array)
136
+ v.each do |v2|
137
+ vars.push("#{k}[]=#{v2}") if !v2.nil? && v2.length > 0
138
+ end
139
+ else
140
+ vars.push("#{k}=#{v}") if !v.nil? && v.length > 0
141
+ end
136
142
  end
137
143
  return URI.escape(vars.join('&'))
138
144
  end
@@ -1,7 +1,6 @@
1
1
 
2
2
  require 'tinymce-rails'
3
3
  require 'jquery-ui-rails'
4
- #require 'modeljs'
5
4
  require 'colorbox-rails'
6
5
  require 'paperclip'
7
6
 
@@ -49,29 +48,53 @@ module Caboose
49
48
  return obj.to_json
50
49
  end
51
50
 
52
- def Caboose.create_schema(schema_file)
51
+ # Verifies (non-destructively) that the given schema exists in the database.
52
+ def Caboose.create_schema(schema)
53
53
  c = ActiveRecord::Base.connection
54
- require schema_file
55
- @schema.each do |table, columns|
56
- c.create_table table if !c.table_exists?(table)
57
- columns.each do |col|
54
+ schema.each do |model, columns|
55
+ tbl = model.table_name
56
+ c.create_table tbl if !c.table_exists?(tbl)
57
+ columns.each do |col|
58
58
 
59
59
  # Skip if the column exists with the proper data type
60
- next if c.column_exists?(table, col[0], col[1])
60
+ next if c.column_exists?(tbl, col[0], col[1])
61
61
 
62
- # If the column exists, but not with the correct data type, try to change it
63
- if c.column_exists?(table, col[0])
62
+ # If the column doesn't exists, add it
63
+ if !c.column_exists?(tbl, col[0])
64
64
  if col.count > 2
65
- c.change_column table, col[0], col[1], col[2]
65
+ c.add_column tbl, col[0], col[1], col[2]
66
66
  else
67
- c.change_column table, col[0], col[1]
67
+ c.add_column tbl, col[0], col[1]
68
68
  end
69
- else
70
- if col.count > 2
71
- c.add_column table, col[0], col[1], col[2]
72
- else
73
- c.add_column table, col[0], col[1]
69
+
70
+ # Column exists, but not with the correct data type, try to change it
71
+ else
72
+
73
+ # Add a temp column
74
+ if col.count > 2
75
+ c.add_column tbl, "#{col[0]}_temp", col[1], col[2]
76
+ else
77
+ c.add_column tbl, "#{col[0]}_temp", col[1]
74
78
  end
79
+
80
+ # Copy the old column and cast with correct data type to the new column
81
+ model.all.each do |m|
82
+ m["#{col[0]}_temp"] = case col[1]
83
+ when :integer then m[col[0]].to_i
84
+ when :string then m[col[0]].to_s
85
+ when :text then m[col[0]].to_s
86
+ when :numeric then m[col[0]].to_f
87
+ when :datetime then DateTime.parse(m[col[0]])
88
+ when :boolean then m[col[0]].to_i == 1
89
+ else nil
90
+ end
91
+ m.save
92
+ end
93
+
94
+ # Remove the old column and rename the new one
95
+ c.remove_column tbl, col[0]
96
+ c.rename_column tbl, "#{col[0]}_temp", col[0]
97
+
75
98
  end
76
99
  end
77
100
  end
@@ -1,3 +1,3 @@
1
1
  module Caboose
2
- VERSION = '0.2.94'
2
+ VERSION = '0.2.95'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: caboose-cms
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.94
4
+ version: 0.2.95
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Barry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-27 00:00:00.000000000 Z
11
+ date: 2013-12-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails