Class: CustomFragmentCache::Fragment
- Inherits:
-
Object
- Object
- CustomFragmentCache::Fragment
- Defined in:
- lib/custom_fragment_cache/fragment.rb
Instance Attribute Summary collapse
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#fields_method ⇒ Object
readonly
Returns the value of attribute fields_method.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#initialize(name, opts) ⇒ Fragment
constructor
A new instance of Fragment.
- #set_fields ⇒ Object
- #validate_fields_method ⇒ Object
Constructor Details
#initialize(name, opts) ⇒ Fragment
Returns a new instance of Fragment.
5 6 7 8 9 10 11 |
# File 'lib/custom_fragment_cache/fragment.rb', line 5 def initialize(name, opts) @name = name @opts = opts.with_indifferent_access @fields = {} @fields_method = :none set_fields end |
Instance Attribute Details
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
3 4 5 |
# File 'lib/custom_fragment_cache/fragment.rb', line 3 def fields @fields end |
#fields_method ⇒ Object (readonly)
Returns the value of attribute fields_method.
3 4 5 |
# File 'lib/custom_fragment_cache/fragment.rb', line 3 def fields_method @fields_method end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/custom_fragment_cache/fragment.rb', line 3 def name @name end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
3 4 5 |
# File 'lib/custom_fragment_cache/fragment.rb', line 3 def opts @opts end |
Instance Method Details
#set_fields ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/custom_fragment_cache/fragment.rb', line 13 def set_fields validate_fields_method if @opts[:safe_fields].present? @fields = @opts[:safe_fields].to_a @fields_method = :safe elsif @opts[:trigger_fields].present? @fields = @opts[:trigger_fields].to_a @fields_method = :trigger end end |
#validate_fields_method ⇒ Object
25 26 27 28 29 |
# File 'lib/custom_fragment_cache/fragment.rb', line 25 def validate_fields_method if @opts.key?(:safe_fields) && @opts.key?(:trigger_fields) raise ArgumentError, "Set trigger and safe fields are not allowed together" end end |