ballonizer 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 282a861cf0c674960e6940c33424e7c293b5d9dd
4
- data.tar.gz: f7a18ba42d1641b5ee18edf56c957eb731a8898b
3
+ metadata.gz: fae524ac2bd239ca97a2332350f57961305dd1b4
4
+ data.tar.gz: ded555e83b156f4113bf33ced804187b2a96a83c
5
5
  SHA512:
6
- metadata.gz: f9d393608f7b9e2f0804552ec647d0f51b301658932e5ae4c3cb7dc5b83ae10e917382e441922f0cab05771170746b31be5b15becc13b1390697afb68fe3c0aa
7
- data.tar.gz: 3fc55d454749542a5dd6f440943e9da6307bda837ea358cea76397e57ce2efac737be6824a6d1a655dcf85c69b2cb749846192c3810ee3f7400c1fa7902c7100
6
+ metadata.gz: b461fd77e5331552c7cd600cb43e3db10ebadc3e961ca3691b354436311e3b6dd7a216523f9f3142da0beee9db5d86814cb1176e81230a66b30b3fbc3c861876
7
+ data.tar.gz: f67061e8582c4759133835109e56428f749e3252d6d85c4464489d0f30ef6deca8ff23d156513a06a2c3480c1e4455b8b093735af057e5615f257d3bf4a154eb
@@ -4,22 +4,16 @@ require 'sprockets'
4
4
  require 'ballonizer'
5
5
 
6
6
  path_rake_to_app = 'examples/ballonizer_app/'
7
+
7
8
  db_name = 'test.db'
8
9
  db_path = "#{path_rake_to_app}#{db_name}"
9
10
  db_uri = "sqlite://#{db_path}"
10
11
 
11
- DB = nil
12
- if File.exists?(db_path)
13
- DB = Sequel.connect(db_uri)
14
- else
15
- DB = Sequel.connect(db_uri)
16
- Ballonizer.create_tables(DB)
17
- end
18
-
19
12
  html_name = 'index.html'
20
13
  html = File.read("#{path_rake_to_app}#{html_name}")
21
14
 
22
- ballonizer = Ballonizer.new(DB, {
15
+ ballonizer = Ballonizer.new(db_uri, {
16
+ create_tables_if_none: true,
23
17
  form_handler_url: '/request_handler',
24
18
  add_required_css: true,
25
19
  css_asset_path_for_link: '/assets',
@@ -28,7 +22,6 @@ ballonizer = Ballonizer.new(DB, {
28
22
  })
29
23
 
30
24
  app = Rack::Builder.new do
31
-
32
25
  map '/' do
33
26
  run(lambda do | env |
34
27
  # the url is needed to make relative paths to images absolute
data/lib/ballonizer.rb CHANGED
@@ -145,21 +145,45 @@ class Ballonizer
145
145
  js_asset_path_for_link: nil,
146
146
  # If the ballonize_page method will add or not the html generated by
147
147
  # #js_libs_html_links (require the :js_asset_path_for_link to be defined).
148
- add_required_js_libs_for_edition: false
148
+ add_required_js_libs_for_edition: false,
149
+ # If true and the database argument don't have any of the tables used by
150
+ # the class call create_tables over the database argument. If false or the
151
+ # database has at leat one of the tables does nothing.
152
+ create_tables_if_none: false
149
153
  }.freeze.each { | _, v| v.freeze }
150
154
 
155
+ USED_TABLES = [ :images, :ballons, :ballonized_image_ballons,
156
+ :ballonized_image_versions].freeze
157
+ private_constant :USED_TABLES
158
+
159
+ # The names (as symbols) of the tables used by instances of the class.
160
+ # @return [Array<Symbol>] An frozen array of symbols
161
+ def self.used_tables
162
+ USED_TABLES
163
+ end
164
+
151
165
  # Create a new Ballonizer object from a Sequel Database (with the expected
152
166
  # tables, that can be created with Ballonizer.create_tables) and a optional
153
167
  # hash of settings.
154
- # @param db [Sequel::Database] A Sequel::Database with tables as described
168
+ # @param db [String, Sequel::Database] A Sequel::Database or a String to be
169
+ # used with Sequel::Database.connect. Is necessary to create the tables
170
+ # with Ballonizer.create_tables unless you have set the :create_table_if_none
171
+ # setting to true.
155
172
  # @param settings [Hash{Symbol => String}] A optional hash of settings. The
156
173
  # default value and explanation of each option are documented in the
157
174
  # DEFAULT_SETTINGS constant.
158
175
  # @return [Ballonizer] A new ballonizer instance.
159
176
  # @see Ballonizer.create_tables
160
177
  def initialize(db, settings = {})
161
- @db = db
162
178
  @settings = DEFAULT_SETTINGS.merge(settings)
179
+ if db.is_a? String
180
+ db = Sequel::Database.connect(db)
181
+ end
182
+ if @settings[:create_tables_if_none] &&
183
+ ! (self.class.used_tables.any? { | name | db.table_exists? name })
184
+ self.class.create_tables(db)
185
+ end
186
+ @db = db
163
187
  end
164
188
 
165
189
  # Convenience method for process_submit_json, extract the json from the
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ballonizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Henrique Becker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-07-03 00:00:00.000000000 Z
11
+ date: 2013-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri