Class: ActiveAssets::ActiveExpansions::Asset
- Inherits:
-
Struct
- Object
- Struct
- ActiveAssets::ActiveExpansions::Asset
- Defined in:
- lib/active_assets/active_expansions/asset.rb
Defined Under Namespace
Classes: AmbiguousContext, InvalidAssetType, InvalidContext, ValidationError
Constant Summary collapse
- REQUIRED_PROPS =
[:path, :type, :expansion_name]
- VALID_TYPES =
[:js, :css]
Instance Attribute Summary collapse
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#expansion_name ⇒ Object
Returns the value of attribute expansion_name.
-
#group ⇒ Object
Returns the value of attribute group.
-
#path ⇒ Object
Returns the value of attribute path.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize ⇒ Asset
constructor
A new instance of Asset.
- #valid! ⇒ Object
- #valid? ⇒ Boolean
- #validation_error ⇒ Object
Constructor Details
#initialize ⇒ Asset
Returns a new instance of Asset.
37 38 39 40 41 |
# File 'lib/active_assets/active_expansions/asset.rb', line 37 def initialize(*) super self.group ||= :all self.cache = self.cache == false ? false : true end |
Instance Attribute Details
#cache ⇒ Object
Returns the value of attribute cache
3 4 5 |
# File 'lib/active_assets/active_expansions/asset.rb', line 3 def cache @cache end |
#expansion_name ⇒ Object
Returns the value of attribute expansion_name
3 4 5 |
# File 'lib/active_assets/active_expansions/asset.rb', line 3 def expansion_name @expansion_name end |
#group ⇒ Object
Returns the value of attribute group
3 4 5 |
# File 'lib/active_assets/active_expansions/asset.rb', line 3 def group @group end |
#path ⇒ Object
Returns the value of attribute path
3 4 5 |
# File 'lib/active_assets/active_expansions/asset.rb', line 3 def path @path end |
#type ⇒ Object
Returns the value of attribute type
3 4 5 |
# File 'lib/active_assets/active_expansions/asset.rb', line 3 def type @type end |
Instance Method Details
#valid! ⇒ Object
56 57 58 59 |
# File 'lib/active_assets/active_expansions/asset.rb', line 56 def valid! e = validation_error raise e if e end |
#valid? ⇒ Boolean
52 53 54 |
# File 'lib/active_assets/active_expansions/asset.rb', line 52 def valid? !validation_error end |
#validation_error ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/active_assets/active_expansions/asset.rb', line 43 def validation_error missing_fields = REQUIRED_PROPS.reject { |meth| send(meth) } if missing_fields.any? ValidationError.new(self, missing_fields) elsif !VALID_TYPES.include?(type) InvalidAssetType.new(type) end end |