Class: MotionAL::Assets
- Inherits:
-
Object
- Object
- MotionAL::Assets
- Defined in:
- lib/motional/assets.rb
Overview
A collection of assets in the group. Assets has to belong to the group.
Instance Attribute Summary collapse
-
#group ⇒ Object
readonly
Returns the value of attribute group.
Instance Method Summary collapse
-
#count(filter = :all) ⇒ Fixnum
Count of assets in the group.
-
#create(source, metadata = nil) {|asset, error| ... } ⇒ nil
Create an asset and add it to the group.
-
#each(options = {}) {|asset, error| ... } ⇒ nil
(also: #find_all)
Enumrate assets in the group.
-
#initialize(group) ⇒ Assets
constructor
A new instance of Assets.
-
#push(asset) ⇒ Object
(also: #<<)
Add an asset to the group.
Constructor Details
#initialize(group) ⇒ Assets
Returns a new instance of Assets.
12 13 14 |
# File 'lib/motional/assets.rb', line 12 def initialize(group) @group = group end |
Instance Attribute Details
#group ⇒ Object (readonly)
Returns the value of attribute group.
9 10 11 |
# File 'lib/motional/assets.rb', line 9 def group @group end |
Instance Method Details
#count(filter = :all) ⇒ Fixnum
Returns Count of assets in the group.
78 79 80 81 82 83 84 |
# File 'lib/motional/assets.rb', line 78 def count(filter = :all) AssetsFilter.set(@group, filter) filtered_count = @group.al_asset_group.numberOfAssets AssetsFilter.reset(@group) filtered_count end |
#create(source, metadata = nil) {|asset, error| ... } ⇒ nil
Create an asset and add it to the group.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/motional/assets.rb', line 33 def create(source, = nil, &block) Asset.create(source, ) do |asset, error| if asset block.call(asset, error) self << asset else raise "Asset creation failed. #{error}" end end end |
#each(options = {}) {|asset, error| ... } ⇒ nil Also known as: find_all
Enumrate assets in the group.
61 62 63 64 65 66 67 68 69 |
# File 'lib/motional/assets.rb', line 61 def each( = {}, &block) raise "MotionAL::Assets.each does not support :group option. Use MotionAL::Asset.find_all to get other group assets." if [:group] [:group] = @group MotionAL::Asset.find_all() do |asset, error| block.call(asset, error) end end |
#push(asset) ⇒ Object Also known as: <<
Add an asset to the group.
89 90 91 92 |
# File 'lib/motional/assets.rb', line 89 def push(asset) @group.add_asset(asset) self end |