bit_player 0.1.3 → 0.1.4

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: e1e21e39e222450b6deb3c43040e74ee125fff5d
4
- data.tar.gz: caa9274f55cef000e2b711fa7138882afe724b6a
3
+ metadata.gz: 35768c8e530397c5ff3197cdc50628a902056616
4
+ data.tar.gz: 493cf2180856d1cdfa73cb7ccb04f9cbdc532846
5
5
  SHA512:
6
- metadata.gz: b232fa67a975f82361a4c4ae5e2ad1310ce82c3ae7b708d13b190675ed59c8761c939bf762e56a03e2863f01a32ab3c9d8d24bdc2813b8b08bb7bad5768dc81e
7
- data.tar.gz: b00ff8f09a9cd0f07e8e8cea184ff124695738d46bddcc3fca176be8875e70e62dd59578cb171f3930b333918fb2561bea07c895cead9555adacf1f6b1ebd0e7
6
+ metadata.gz: e3b3909f4daa68f27a38a7253931dd13f6ec4d3513b030a5ca513f83d2a0990420af15c0b9dba3904dc5d1dfc1fd5e2829dcadb2462667f4b1fb9e88ae55e6ca
7
+ data.tar.gz: 076f6f351e4f597ba668b53cb55969efec36c9cf9a9d3e17ed6fbb52a8e31a0b368cb3ae1cfa3e6a8a6fe555fcadc490a1cb9c2dc62d5511a7d27af910de8083
data/README.md CHANGED
@@ -5,3 +5,7 @@
5
5
  ## Installation
6
6
 
7
7
  gem install bit-player
8
+
9
+ ## Run tests
10
+
11
+ rake test
data/Rakefile CHANGED
@@ -18,8 +18,11 @@ require 'rspec/core/rake_task'
18
18
 
19
19
  RSpec::Core::RakeTask.new(:spec)
20
20
 
21
- task :default => :spec
21
+ task default: :spec
22
22
 
23
+ task :test do
24
+ puts `cd spec/dummy; RAILS_ENV=test rake db:drop db:create db:migrate; cd ../..; rspec`
25
+ end
23
26
 
24
27
  Bundler::GemHelper.install_tasks
25
28
 
@@ -1,17 +1,18 @@
1
1
  module BitPlayer
2
+ # A logical unit of content, possibly containing mixed provider types.
2
3
  class ContentModule < ActiveRecord::Base
3
4
  has_many :content_providers,
4
- class_name: "BitPlayer::ContentProvider",
5
- foreign_key: :bit_player_content_module_id,
6
- inverse_of: :content_module
5
+ class_name: "BitPlayer::ContentProvider",
6
+ foreign_key: :bit_player_content_module_id,
7
+ inverse_of: :content_module
7
8
 
8
9
  validates :title, :context, :position, presence: true
9
- validates_numericality_of :position, greater_than_or_equal_to: 1
10
- validates_uniqueness_of :position, scope: :context
10
+ validates :position, numericality: { greater_than_or_equal_to: 1 }
11
+ validates :position, uniqueness: { scope: :context }
11
12
 
12
13
  def provider(position)
13
14
  content_providers.where(position: position).first ||
14
- BitPlayer::ContentProviders::Null.new(self)
15
+ BitPlayer::ContentProviders::Null.new(self, position)
15
16
  end
16
17
 
17
18
  def provider_exists?(position)
@@ -1,15 +1,16 @@
1
1
  module BitPlayer
2
+ # Modeled after the presenter pattern. Ties data layer to view layer.
2
3
  class ContentProvider < ActiveRecord::Base
3
4
  include BitPlayer::ContentProviders::ViewProvider
4
5
 
5
6
  belongs_to :content_module,
6
- class_name: "BitPlayer::ContentModule",
7
- foreign_key: :bit_player_content_module_id,
8
- inverse_of: :content_providers
7
+ class_name: "BitPlayer::ContentModule",
8
+ foreign_key: :bit_player_content_module_id,
9
+ inverse_of: :content_providers
9
10
  belongs_to :source_content, polymorphic: true
10
11
 
11
12
  validates :content_module, :position, presence: true
12
- validates_numericality_of :position, greater_than_or_equal_to: 1
13
+ validates :position, numericality: { greater_than_or_equal_to: 1 }
13
14
 
14
15
  delegate :context, to: :content_module, prefix: false
15
16
 
@@ -1,13 +1,19 @@
1
+ require "active_support/concern"
2
+
1
3
  module BitPlayer
2
- module ContentProviders::FormViewProvider
3
- def self.included(base)
4
- base.class_eval do
4
+ module ContentProviders
5
+ # Presentation logic for a "new" or "edit" view on a data model.
6
+ module FormViewProvider
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
5
10
  def self.data_class(klass)
6
11
  @source_class = klass
7
12
  end
8
13
 
9
14
  def self.source_class
10
- @source_class || fail("Classes inheriting from #{ self } must define a source class with `data_class <class>`")
15
+ @source_class || fail("Classes inheriting from #{ self } must define
16
+ a source classwith `data_class <class>`")
11
17
  end
12
18
 
13
19
  def self.show_nav_link
@@ -33,20 +39,20 @@ module BitPlayer
33
39
  @view_type
34
40
  end
35
41
  end
36
- end
37
42
 
38
- def show_nav_link?
39
- self.class.show_nav_link?
40
- end
43
+ def show_nav_link?
44
+ self.class.show_nav_link?
45
+ end
41
46
 
42
- def template
43
- "#{ plural_name }/#{ self.class.get_view_type }"
44
- end
47
+ def template
48
+ "#{ plural_name }/#{ self.class.get_view_type }"
49
+ end
45
50
 
46
- private
51
+ private
47
52
 
48
- def plural_name
49
- self.class.source_class.to_s.underscore.pluralize
53
+ def plural_name
54
+ self.class.source_class.to_s.underscore.pluralize
55
+ end
50
56
  end
51
57
  end
52
58
  end
@@ -1,15 +1,22 @@
1
1
  module BitPlayer
2
- class ContentProviders::Null
3
- def initialize(content_module)
4
- @content_module = content_module
5
- end
2
+ module ContentProviders
3
+ # The default provider.
4
+ class Null
5
+ attr_reader :position
6
6
 
7
- def render_current(options)
8
- "Content Module #{ @content_module.title }: Oops, did you expect a content provider here?"
9
- end
7
+ def initialize(content_module, position)
8
+ @content_module = content_module
9
+ @position = position
10
+ end
11
+
12
+ def render_current(options)
13
+ "Content Module #{ @content_module.title }: Oops, did you expect a
14
+ content provider here?"
15
+ end
10
16
 
11
- def show_nav_link?
12
- true
17
+ def show_nav_link?
18
+ true
19
+ end
13
20
  end
14
21
  end
15
22
  end
@@ -1,28 +1,32 @@
1
1
  module BitPlayer
2
- class ContentProviders::SlideshowProvider < ContentProvider
3
- def slideshow
4
- source_content
5
- end
2
+ module ContentProviders
3
+ # Defines presentation logic for a Slideshow.
4
+ class SlideshowProvider < ContentProvider
5
+ def slideshow
6
+ source_content
7
+ end
6
8
 
7
- def render_current(options)
8
- options.view_context.render(
9
- template: "slides/show",
10
- locals: {
11
- slide: slide(options.position)
12
- }
13
- )
14
- end
9
+ def render_current(options)
10
+ options.view_context.render(
11
+ template: "slides/show",
12
+ locals: {
13
+ slide: slide(options.position)
14
+ }
15
+ )
16
+ end
15
17
 
16
- def slide(position)
17
- slideshow.slides.where(position: position).first || BitPlayer::Slide.new(body: "no slides")
18
- end
18
+ def slide(position)
19
+ slideshow.slides.where(position: position).first ||
20
+ BitPlayer::Slide.new(body: "no slides")
21
+ end
19
22
 
20
- def exists?(position)
21
- slideshow.slides.exists?(position: position)
22
- end
23
+ def exists?(position)
24
+ slideshow.slides.exists?(position: position)
25
+ end
23
26
 
24
- def show_nav_link?
25
- true
27
+ def show_nav_link?
28
+ true
29
+ end
26
30
  end
27
31
  end
28
32
  end
@@ -1,13 +1,19 @@
1
+ require "active_support/concern"
2
+
1
3
  module BitPlayer
2
- module ContentProviders::ViewProvider
3
- def self.included(base)
4
- base.class_eval do
4
+ module ContentProviders
5
+ # Presentation logic for a "show" or "index" view on a data model.
6
+ module ViewProvider
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
5
10
  def self.data_class(klass)
6
11
  @source_class = klass
7
12
  end
8
13
 
9
14
  def self.source_class
10
- @source_class || fail("Classes inheriting from #{ self } must define a source class with `data_class <class>`")
15
+ @source_class || fail("Classes inheriting from #{ self } must define
16
+ a source class with `data_class <class>`")
11
17
  end
12
18
 
13
19
  def self.show_nav_link
@@ -33,20 +39,20 @@ module BitPlayer
33
39
  @view_type
34
40
  end
35
41
  end
36
- end
37
42
 
38
- def show_nav_link?
39
- self.class.show_nav_link?
40
- end
43
+ def show_nav_link?
44
+ self.class.show_nav_link?
45
+ end
41
46
 
42
- def template
43
- "#{ plural_name }/#{ self.class.get_view_type }"
44
- end
47
+ def template
48
+ "#{ plural_name }/#{ self.class.get_view_type }"
49
+ end
45
50
 
46
- private
51
+ private
47
52
 
48
- def plural_name
49
- self.class.source_class.to_s.underscore.pluralize
53
+ def plural_name
54
+ self.class.source_class.to_s.underscore.pluralize
55
+ end
50
56
  end
51
57
  end
52
58
  end
@@ -1,6 +1,9 @@
1
1
  module BitPlayer
2
+ # Business rules for proceeding statefully through an application.
2
3
  class Navigator
3
- RenderOptions = Struct.new(:view_context, :app_context, :position, :participant)
4
+ RenderOptions = Struct.new(
5
+ :view_context, :app_context, :position, :participant
6
+ )
4
7
 
5
8
  def initialize(participant)
6
9
  @participant = participant
@@ -24,7 +27,9 @@ module BitPlayer
24
27
  end
25
28
 
26
29
  def render_current_content(view_context)
27
- options = RenderOptions.new(view_context, context, content_position, @participant)
30
+ options = RenderOptions.new(
31
+ view_context, context, content_position, @participant
32
+ )
28
33
 
29
34
  current_content_provider.render_current(options)
30
35
  end
@@ -55,10 +60,10 @@ module BitPlayer
55
60
  content_module = ContentModule.find(options[:module_id])
56
61
  @status.context = content_module.context
57
62
  @status.module_position = content_module.position
63
+ @status.provider_position = 1
58
64
  if options[:provider_id]
59
- @status.provider_position = content_module.content_providers.find(options[:provider_id]).position
60
- else
61
- @status.provider_position = 1
65
+ @status.provider_position = content_module.content_providers
66
+ .find(options[:provider_id]).position
62
67
  end
63
68
  @status.content_position = [options[:content_position].to_i, 1].max
64
69
  @status.save
@@ -1,27 +1,26 @@
1
1
  module BitPlayer
2
+ # Persistent data representing the Participant's navigation state.
2
3
  class ParticipantStatus < ActiveRecord::Base
3
4
  belongs_to :participant
4
5
 
5
6
  def initialize_context(name)
6
- self.context = name
7
- self.module_position = 1
8
- self.provider_position = 1
9
- self.content_position = 1
10
-
11
- save
7
+ update(
8
+ context: name,
9
+ module_position: 1,
10
+ provider_position: 1,
11
+ content_position: 1
12
+ )
12
13
  end
13
14
 
14
15
  def increment_content_position
15
- self.content_position += 1
16
-
17
- save
16
+ update(content_position: content_position + 1)
18
17
  end
19
18
 
20
19
  def increment_provider_position
21
- self.provider_position += 1
22
- self.content_position = 1
23
-
24
- save
20
+ update(
21
+ provider_position: provider_position + 1,
22
+ content_position: 1
23
+ )
25
24
  end
26
25
  end
27
26
  end
@@ -1,40 +1,36 @@
1
1
  require "redcarpet"
2
2
 
3
3
  module BitPlayer
4
+ # A page of "static" or presentational content (as opposed to data capture).
4
5
  class Slide < ActiveRecord::Base
5
6
  belongs_to :slideshow,
6
- class_name: "BitPlayer::Slideshow",
7
- foreign_key: :bit_player_slideshow_id,
8
- inverse_of: :slides
7
+ class_name: "BitPlayer::Slideshow",
8
+ foreign_key: :bit_player_slideshow_id,
9
+ inverse_of: :slides
9
10
 
10
11
  validates :title, :body, :position, presence: true
11
- validates_numericality_of :position, greater_than_or_equal_to: 1
12
- validates_uniqueness_of :position, scope: :bit_player_slideshow_id
13
-
14
- def render_body
15
- rendered = ""
16
-
17
- if !body.nil?
18
- markdown = Redcarpet::Markdown.new(
19
- Redcarpet::Render::HTML.new(
20
- filter_html: true,
21
- safe_links_only: true
22
- ),
23
- space_after_headers: true,
24
- )
25
- rendered += markdown.render(body)
26
- end
27
-
28
- rendered.html_safe
29
- end
12
+ validates :position, numericality: { greater_than_or_equal_to: 1 }
13
+ validates :position, uniqueness: { scope: :bit_player_slideshow_id }
30
14
 
31
15
  def self.update_positions(ids)
32
16
  transaction do
33
- connection.execute "SET CONSTRAINTS slide_position DEFERRED"
17
+ connection.execute "SET CONSTRAINTS bit_player_slide_position DEFERRED"
34
18
  ids.each_with_index do |id, index|
35
19
  where(id: id).update_all(position: index + 1)
36
20
  end
37
21
  end
38
22
  end
23
+
24
+ def render_body
25
+ return "" if body.nil?
26
+
27
+ Redcarpet::Markdown.new(
28
+ Redcarpet::Render::HTML.new(
29
+ filter_html: true,
30
+ safe_links_only: true
31
+ ),
32
+ space_after_headers: true
33
+ ).render(body).html_safe
34
+ end
39
35
  end
40
36
  end
@@ -1,11 +1,12 @@
1
1
  module BitPlayer
2
+ # A collection of ordered Slides.
2
3
  class Slideshow < ActiveRecord::Base
3
4
  has_many :slides,
4
- -> { order "position" },
5
- class_name: "BitPlayer::Slide",
6
- foreign_key: :bit_player_slideshow_id,
7
- dependent: :destroy,
8
- inverse_of: :slideshow
5
+ -> { order "position" },
6
+ class_name: "BitPlayer::Slide",
7
+ foreign_key: :bit_player_slideshow_id,
8
+ dependent: :destroy,
9
+ inverse_of: :slideshow
9
10
  has_one :content_provider, as: :source_content, inverse_of: :source_content
10
11
 
11
12
  validates :title, presence: true
@@ -1,4 +1,5 @@
1
1
  module BitPlayer
2
+ # A Slide with video content.
2
3
  class VideoSlide < Slide
3
4
  serialize :options
4
5
  end
@@ -12,8 +12,6 @@ class CreateBitPlayerSlides < ActiveRecord::Migration
12
12
  t.timestamps
13
13
  end
14
14
 
15
- add_index :bit_player_slides, [:position, :bit_player_slideshow_id]
16
-
17
15
  reversible do |dir|
18
16
  dir.up do
19
17
  execute <<-SQL
@@ -27,7 +25,7 @@ class CreateBitPlayerSlides < ActiveRecord::Migration
27
25
  # updated
28
26
  execute <<-SQL
29
27
  ALTER TABLE bit_player_slides
30
- ADD CONSTRAINT slide_position UNIQUE (bit_player_slideshow_id, position)
28
+ ADD CONSTRAINT bit_player_slide_position UNIQUE (bit_player_slideshow_id, position)
31
29
  DEFERRABLE INITIALLY IMMEDIATE
32
30
  SQL
33
31
  end
@@ -40,7 +38,7 @@ class CreateBitPlayerSlides < ActiveRecord::Migration
40
38
 
41
39
  execute <<-SQL
42
40
  ALTER TABLE bit_player_slides
43
- DROP CONSTRAINT IF EXISTS slide_position
41
+ DROP CONSTRAINT IF EXISTS bit_player_slide_position
44
42
  SQL
45
43
  end
46
44
  end
@@ -1,3 +1,3 @@
1
1
  module BitPlayer
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -13,8 +13,6 @@ class CreateBitPlayerSlides < ActiveRecord::Migration
13
13
  t.timestamps
14
14
  end
15
15
 
16
- add_index :bit_player_slides, [:position, :bit_player_slideshow_id]
17
-
18
16
  reversible do |dir|
19
17
  dir.up do
20
18
  execute <<-SQL
@@ -28,7 +26,7 @@ class CreateBitPlayerSlides < ActiveRecord::Migration
28
26
  # updated
29
27
  execute <<-SQL
30
28
  ALTER TABLE bit_player_slides
31
- ADD CONSTRAINT slide_position UNIQUE (bit_player_slideshow_id, position)
29
+ ADD CONSTRAINT bit_player_slide_position UNIQUE (bit_player_slideshow_id, position)
32
30
  DEFERRABLE INITIALLY IMMEDIATE
33
31
  SQL
34
32
  end
@@ -41,7 +39,7 @@ class CreateBitPlayerSlides < ActiveRecord::Migration
41
39
 
42
40
  execute <<-SQL
43
41
  ALTER TABLE bit_player_slides
44
- DROP CONSTRAINT IF EXISTS slide_position
42
+ DROP CONSTRAINT IF EXISTS bit_player_slide_position
45
43
  SQL
46
44
  end
47
45
  end
@@ -60,9 +60,8 @@ ActiveRecord::Schema.define(version: 20140306000537) do
60
60
  t.datetime "updated_at"
61
61
  end
62
62
 
63
- add_index "bit_player_slides", ["bit_player_slideshow_id", "position"], name: "slide_position", unique: true, using: :btree
63
+ add_index "bit_player_slides", ["bit_player_slideshow_id", "position"], name: "bit_player_slide_position", unique: true, using: :btree
64
64
  add_index "bit_player_slides", ["bit_player_slideshow_id"], name: "index_bit_player_slides_on_bit_player_slideshow_id", using: :btree
65
- add_index "bit_player_slides", ["position", "bit_player_slideshow_id"], name: "index_bit_player_slides_on_position_and_bit_player_slideshow_id", using: :btree
66
65
 
67
66
  create_table "bit_player_slideshows", force: true do |t|
68
67
  t.string "title", null: false