bit_player 0.1.4 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35768c8e530397c5ff3197cdc50628a902056616
4
- data.tar.gz: 493cf2180856d1cdfa73cb7ccb04f9cbdc532846
3
+ metadata.gz: 64517e346ae2b99d41bb8731aa01aa3a47ed9255
4
+ data.tar.gz: 194ca25803915014bfefc594f4a1cadb6b3c3c1b
5
5
  SHA512:
6
- metadata.gz: e3b3909f4daa68f27a38a7253931dd13f6ec4d3513b030a5ca513f83d2a0990420af15c0b9dba3904dc5d1dfc1fd5e2829dcadb2462667f4b1fb9e88ae55e6ca
7
- data.tar.gz: 076f6f351e4f597ba668b53cb55969efec36c9cf9a9d3e17ed6fbb52a8e31a0b368cb3ae1cfa3e6a8a6fe555fcadc490a1cb9c2dc62d5511a7d27af910de8083
6
+ metadata.gz: 7452094d0d59dc7ed3c21f6f03b8356d240d56ed12befe8b65d8dd6c8cff3b769dd8e31e8e59ca648c8a0fbfddcc6fa4988b40bfe3ab84c8c8aa1657cab88a45
7
+ data.tar.gz: b1054468ad2ca6648c1d7b3f52cf4e89949b94241c34e0ee134979dc896b0772cd7895a3b6ea58d4fb15bb9adf0c7611bede2d4443039b1822578e383f6d9106
data/README.md CHANGED
@@ -9,3 +9,7 @@
9
9
  ## Run tests
10
10
 
11
11
  rake test
12
+
13
+ ## Build the gem
14
+
15
+ rake build
@@ -1,18 +1,22 @@
1
1
  module BitPlayer
2
2
  # A logical unit of content, possibly containing mixed provider types.
3
3
  class ContentModule < ActiveRecord::Base
4
+ belongs_to :tool,
5
+ class_name: "BitPlayer::Tool",
6
+ foreign_key: :bit_player_tool_id
4
7
  has_many :content_providers,
5
8
  class_name: "BitPlayer::ContentProvider",
6
9
  foreign_key: :bit_player_content_module_id,
7
- inverse_of: :content_module
10
+ inverse_of: :content_module,
11
+ dependent: :destroy
8
12
 
9
- validates :title, :context, :position, presence: true
13
+ validates :title, :tool, :position, presence: true
10
14
  validates :position, numericality: { greater_than_or_equal_to: 1 }
11
- validates :position, uniqueness: { scope: :context }
15
+ validates :position, uniqueness: { scope: :bit_player_tool_id }
12
16
 
13
17
  def provider(position)
14
18
  content_providers.where(position: position).first ||
15
- BitPlayer::ContentProviders::Null.new(self, position)
19
+ ContentProviders::Null.new(self, position)
16
20
  end
17
21
 
18
22
  def provider_exists?(position)
@@ -17,7 +17,7 @@ module BitPlayer
17
17
 
18
18
  def slide(position)
19
19
  slideshow.slides.where(position: position).first ||
20
- BitPlayer::Slide.new(body: "no slides")
20
+ Slide.new(body: "no slides")
21
21
  end
22
22
 
23
23
  def exists?(position)
@@ -58,7 +58,7 @@ module BitPlayer
58
58
 
59
59
  def initialize_location(options)
60
60
  content_module = ContentModule.find(options[:module_id])
61
- @status.context = content_module.context
61
+ @status.context = content_module.tool.title
62
62
  @status.module_position = content_module.position
63
63
  @status.provider_position = 1
64
64
  if options[:provider_id]
@@ -72,7 +72,10 @@ module BitPlayer
72
72
  def current_module
73
73
  @current_module ||= nil
74
74
 
75
- module_attrs = { context: context, position: module_position }
75
+ module_attrs = {
76
+ bit_player_tool_id: Tool.find_by_title(context).try(:id),
77
+ position: module_position
78
+ }
76
79
 
77
80
  if current_module_stale?
78
81
  @current_module = ContentModule.where(module_attrs).first
@@ -85,7 +88,7 @@ module BitPlayer
85
88
 
86
89
  def current_module_stale?
87
90
  @current_module.nil? ||
88
- (@current_module.context != context ||
91
+ (@current_module.tool.try(:title) != context ||
89
92
  @current_module.position != module_position)
90
93
  end
91
94
  end
@@ -0,0 +1,13 @@
1
+ module BitPlayer
2
+ # A section of an application.
3
+ class Tool < ActiveRecord::Base
4
+ has_many :content_modules,
5
+ class_name: "BitPlayer::ContentModule",
6
+ foreign_key: :bit_player_tool_id,
7
+ inverse_of: :tool,
8
+ dependent: :destroy
9
+ validates :title, presence: true
10
+ validates :position, uniqueness: true
11
+ validates :is_home, inclusion: { in: [true, false] }
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ class CreateBitPlayerTools < ActiveRecord::Migration
2
+ def change
3
+ create_table :bit_player_tools do |t|
4
+ t.string :title, null: false
5
+ t.integer :position
6
+ t.boolean :is_home, default: false, null: false
7
+
8
+ t.timestamps
9
+ end
10
+ add_index :bit_player_tools, :title, unique: true
11
+ add_index :bit_player_tools, :position, unique: true
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ class ChangeModuleContextToTool < ActiveRecord::Migration
2
+ def up
3
+ add_column :bit_player_content_modules, :bit_player_tool_id, :integer
4
+ BitPlayer::ContentModule.reset_column_information
5
+ BitPlayer::ContentModule.all.each do |content_module|
6
+ tool = BitPlayer::Tool.find_or_create_by_title(content_module.context)
7
+ content_module.update!(bit_player_tool_id: tool.id)
8
+ end
9
+ change_column_null :bit_player_content_modules, :bit_player_tool_id, false
10
+ remove_column :bit_player_content_modules, :context
11
+ execute <<-SQL
12
+ ALTER TABLE bit_player_content_modules
13
+ ADD CONSTRAINT fk_content_modules_tools
14
+ FOREIGN KEY (bit_player_tool_id)
15
+ REFERENCES bit_player_tools(id)
16
+ SQL
17
+ end
18
+
19
+ def down
20
+ execute <<-SQL
21
+ ALTER TABLE bit_player_content_modules
22
+ DROP CONSTRAINT fk_content_modules_tools
23
+ SQL
24
+ add_column :bit_player_content_modules, :context, :string, null: false
25
+ BitPlayer::ContentModule.all.each do |content_module|
26
+ content_module.update(context: content_module.tool.title)
27
+ end
28
+ remove_column :bit_player_content_modules, :bit_player_tool_id
29
+ end
30
+ end
@@ -1,3 +1,3 @@
1
1
  module BitPlayer
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -0,0 +1,14 @@
1
+ # This migration comes from bit_player (originally 20140402224913)
2
+ class CreateBitPlayerTools < ActiveRecord::Migration
3
+ def change
4
+ create_table :bit_player_tools do |t|
5
+ t.string :title, null: false
6
+ t.integer :position
7
+ t.boolean :is_home, default: false, null: false
8
+
9
+ t.timestamps
10
+ end
11
+ add_index :bit_player_tools, :title, unique: true
12
+ add_index :bit_player_tools, :position, unique: true
13
+ end
14
+ end
@@ -0,0 +1,31 @@
1
+ # This migration comes from bit_player (originally 20140402225703)
2
+ class ChangeModuleContextToTool < ActiveRecord::Migration
3
+ def up
4
+ add_column :bit_player_content_modules, :bit_player_tool_id, :integer
5
+ BitPlayer::ContentModule.reset_column_information
6
+ BitPlayer::ContentModule.all.each do |content_module|
7
+ tool = BitPlayer::Tool.find_or_create_by_title(content_module.context)
8
+ content_module.update!(bit_player_tool_id: tool.id)
9
+ end
10
+ change_column_null :bit_player_content_modules, :bit_player_tool_id, false
11
+ remove_column :bit_player_content_modules, :context
12
+ execute <<-SQL
13
+ ALTER TABLE bit_player_content_modules
14
+ ADD CONSTRAINT fk_content_modules_tools
15
+ FOREIGN KEY (bit_player_tool_id)
16
+ REFERENCES bit_player_tools(id)
17
+ SQL
18
+ end
19
+
20
+ def down
21
+ execute <<-SQL
22
+ ALTER TABLE bit_player_content_modules
23
+ DROP CONSTRAINT fk_content_modules_tools
24
+ SQL
25
+ add_column :bit_player_content_modules, :context, :string, null: false
26
+ BitPlayer::ContentModule.all.each do |content_module|
27
+ content_module.update(context: content_module.tool.title)
28
+ end
29
+ remove_column :bit_player_content_modules, :bit_player_tool_id
30
+ end
31
+ end
@@ -11,17 +11,17 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20140306000537) do
14
+ ActiveRecord::Schema.define(version: 20140407201525) do
15
15
 
16
16
  # These are extensions that must be enabled in order to support this database
17
17
  enable_extension "plpgsql"
18
18
 
19
19
  create_table "bit_player_content_modules", force: true do |t|
20
- t.string "title", null: false
21
- t.string "context", null: false
22
- t.integer "position", default: 1, null: false
20
+ t.string "title", null: false
21
+ t.integer "position", default: 1, null: false
23
22
  t.datetime "created_at"
24
23
  t.datetime "updated_at"
24
+ t.integer "bit_player_tool_id", null: false
25
25
  end
26
26
 
27
27
  create_table "bit_player_content_providers", force: true do |t|
@@ -69,4 +69,15 @@ ActiveRecord::Schema.define(version: 20140306000537) do
69
69
  t.datetime "updated_at"
70
70
  end
71
71
 
72
+ create_table "bit_player_tools", force: true do |t|
73
+ t.string "title", null: false
74
+ t.integer "position"
75
+ t.boolean "is_home", default: false, null: false
76
+ t.datetime "created_at"
77
+ t.datetime "updated_at"
78
+ end
79
+
80
+ add_index "bit_player_tools", ["position"], name: "index_bit_player_tools_on_position", unique: true, using: :btree
81
+ add_index "bit_player_tools", ["title"], name: "index_bit_player_tools_on_title", unique: true, using: :btree
82
+
72
83
  end