bit_core 1.0.0 → 1.1.0

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: 46eb715d2ebf8df84b3bc19c1ef113babf53121d
4
- data.tar.gz: c5a4d7697a0154726c0bbcf72f5c3a8b01298678
3
+ metadata.gz: 6fc8f82c0070900575127dc85046ca7f02923e25
4
+ data.tar.gz: ebb2257d29c38e76d1aa06bb9b817ecbb57fd2c8
5
5
  SHA512:
6
- metadata.gz: 89d19c7babf025ead3e89f0bfecf6e7e671c6e4f9fbf65e9967ae058fc54df1f6a6013ca350b0aeb447d8b62cd7c6f086c77011792baa840b8c860540bc76f2a
7
- data.tar.gz: 70096b801ceb598d0a9044d015f6b298216cb09f1c74ed3b7b067c334a5aa5fbaff00e7a0e1dde36ab7c346f2a99146cda372fc95769a37b96cfc8809943bb86
6
+ metadata.gz: 2a35f2bf37f8c18ed4de50b112387bf390ddc06eb689d87862495e3a46c3dad6274c3d43b2171aba55e0995054097f577df2a12472a38db31b19c859c72dc262
7
+ data.tar.gz: c3244449083c1ae2e35cb270ee68d16a4514e5819bd722d76a37e0883ec6733eb1670be51f6debc067d59569f1bd23d22718bffb644082bc08b7204ab43ec101
data/Rakefile CHANGED
@@ -18,4 +18,4 @@ require "rspec/core/rake_task"
18
18
  desc "Run all specs in spec directory (excluding plugin specs)"
19
19
  RSpec::Core::RakeTask.new(:spec => "app:db:test:prepare")
20
20
 
21
- task :default => :spec
21
+ task default: :spec
@@ -12,15 +12,6 @@ module BitCore
12
12
  validates :position, numericality: { greater_than_or_equal_to: 1 }
13
13
  validates :position, uniqueness: { scope: :bit_core_slideshow_id }
14
14
 
15
- def self.update_positions(ids)
16
- transaction do
17
- connection.execute "SET CONSTRAINTS bit_core_slide_position DEFERRED"
18
- ids.each_with_index do |id, index|
19
- where(id: id).update_all(position: index + 1)
20
- end
21
- end
22
- end
23
-
24
15
  def render_body
25
16
  return "" if body.nil?
26
17
 
@@ -7,10 +7,40 @@ module BitCore
7
7
  foreign_key: :bit_core_slideshow_id,
8
8
  dependent: :destroy,
9
9
  inverse_of: :slideshow
10
- has_one :content_provider, as: :source_content, inverse_of: :source_content
10
+ has_one :content_provider,
11
+ as: :source_content,
12
+ inverse_of: :source_content,
13
+ dependent: :nullify
11
14
 
12
15
  validates :title, presence: true
13
16
 
14
17
  accepts_nested_attributes_for :slides
18
+
19
+ def add(slide_params)
20
+ slide = slides.build(slide_params)
21
+ slide.position = slides.count + 1
22
+
23
+ slide
24
+ end
25
+
26
+ def remove(slide)
27
+ return false unless slide.destroy
28
+
29
+ (slide.position + 1..slides.last.position).each do |pos|
30
+ slides.find_by_position(pos).update(position: pos - 1)
31
+ end
32
+
33
+ true
34
+ end
35
+
36
+ def sort(ordered_ids)
37
+ self.class.transaction do
38
+ self.class.connection.execute "SET CONSTRAINTS " \
39
+ "bit_core_slide_position DEFERRED"
40
+ ordered_ids.each_with_index do |id, idx|
41
+ slides.find(id).update_attribute(:position, idx + 1)
42
+ end
43
+ end
44
+ end
15
45
  end
16
46
  end
@@ -1,4 +1,4 @@
1
1
  # nodoc
2
2
  module BitCore
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
@@ -58,6 +58,7 @@ development:
58
58
  test:
59
59
  <<: *default
60
60
  database: dummy_test
61
+ username: postgres
61
62
 
62
63
  # As with config/secrets.yml, you never want to store sensitive information,
63
64
  # like your database password, in your source code. If your source code is