123456789_123456789_123456789_123456789_123456789_

Class: ActionText::AttachmentGallery

Constant Summary

Class Method Summary

::ActiveModel::Callbacks - self

::ActiveModel::Naming - self

param_key

Returns string to use for params names.

plural

Returns the plural class name of a record or class.

route_key

Returns string to use while generating route names.

singular

Returns the singular class name of a record or class.

singular_route_key

Returns string to use while generating route names.

uncountable?

Identifies whether the class name of a record or class is uncountable.

extended, model_name_from_record_or_class

Instance Attribute Summary

::ActiveModel::API - Included

#_validators, #_validators?,
#persisted?

Indicates if the model is persisted.

#validation_context

Returns the context when running validations.

::ActiveModel::AttributeAssignment - Included

Instance Method Summary

::ActiveModel::Access - Included

::ActiveModel::API - Included

#initialize

Initializes a new model with the given params.

::ActiveModel::Conversion - Included

#to_key

Returns an ::Array of all key attributes if any of the attributes is set, whether or not the object is persisted.

#to_model

If your object is already designed to implement all of the Active Model you can use the default :to_model implementation, which simply returns self.

#to_param

Returns a string representing the object’s key suitable for use in URLs, or nil if persisted? is false.

#to_partial_path

Returns a string identifying the path associated with the object.

::ActiveModel::Validations::HelperMethods - Included

#validates_absence_of

Validates that the specified attributes are blank (as defined by Object#present?).

#validates_acceptance_of

Encapsulates the pattern of wanting to validate the acceptance of a terms of service check box (or similar agreement).

#validates_comparison_of

Validates the value of a specified attribute fulfills all defined comparisons with another value, proc, or attribute.

#validates_confirmation_of

Encapsulates the pattern of wanting to validate a password or email address field with a confirmation.

#validates_exclusion_of

Validates that the value of the specified attribute is not in a particular enumerable object.

#validates_format_of

Validates whether the value of the specified attribute is of the correct form, going by the regular expression provided.

#validates_inclusion_of

Validates whether the value of the specified attribute is available in a particular enumerable object.

#validates_length_of

Validates that the specified attributes match the length restrictions supplied.

#validates_numericality_of

Validates whether the value of the specified attribute is numeric by trying to convert it to a float with Kernel.Float (if only_integer is false) or applying it to the regular expression /\A[+\-]?\d+\z/ (if only_integer is set to true).

#validates_presence_of

Validates that the specified attributes are not blank (as defined by Object#blank?).

#validates_size_of
#_merge_attributes

::ActiveModel::Validations - Included

#errors

Returns the Errors object that holds all information about attribute error messages.

#invalid?

Performs the opposite of valid?.

#read_attribute_for_validation

Hook method defining how an attribute value should be retrieved.

#valid?

Runs all the specified validations and returns true if no errors were added otherwise false.

#validate
#validate!

Runs all the validations within the specified context.

#validates_with

Passes the record off to the class or classes specified and allows them to add errors based on more complex conditions.

#init_internals, #raise_validation_error, #run_validations!,
#initialize_dup

Clean the Errors object if instance is duped.

::ActiveModel::AttributeAssignment - Included

#assign_attributes

Allows you to set all the attributes by passing in a hash of attributes with keys matching the attribute names.

#_assign_attribute, #_assign_attributes

::ActiveModel::ForbiddenAttributesProtection - Included

Constructor Details

.new(node) ⇒ AttachmentGallery

[ GitHub ]

  
# File 'actiontext/lib/action_text/attachment_gallery.rb', line 52

def initialize(node)
  @node = node
end

Class Method Details

.attachment_selector

[ GitHub ]

  
# File 'actiontext/lib/action_text/attachment_gallery.rb', line 41

def attachment_selector
  "#{ActionText::Attachment.tag_name}[presentation=gallery]"
end

.fragment_by_canonicalizing_attachment_galleries(content)

[ GitHub ]

  
# File 'actiontext/lib/action_text/attachment_gallery.rb', line 11

def fragment_by_canonicalizing_attachment_galleries(content)
  fragment_by_replacing_attachment_gallery_nodes(content) do |node|
    "<#{TAG_NAME}>#{node.inner_html}</#{TAG_NAME}>"
  end
end

.from_node(node)

[ GitHub ]

  
# File 'actiontext/lib/action_text/attachment_gallery.rb', line 37

def from_node(node)
  new(node)
end

.selector

[ GitHub ]

  
# File 'actiontext/lib/action_text/attachment_gallery.rb', line 45

def selector
  "#{TAG_NAME}:has(#{attachment_selector} + #{attachment_selector})"
end

Instance Attribute Details

#node (readonly)

[ GitHub ]

  
# File 'actiontext/lib/action_text/attachment_gallery.rb', line 50

attr_reader :node

Instance Method Details

#attachments

[ GitHub ]

  
# File 'actiontext/lib/action_text/attachment_gallery.rb', line 56

def attachments
  @attachments ||= node.css(ActionText::AttachmentGallery.attachment_selector).map do |node|
    ActionText::Attachment.from_node(node).with_full_attributes
  end
end

#inspect

[ GitHub ]

  
# File 'actiontext/lib/action_text/attachment_gallery.rb', line 66

def inspect
  "#<#{self.class.name} size=#{size.inspect}>"
end

#size

[ GitHub ]

  
# File 'actiontext/lib/action_text/attachment_gallery.rb', line 62

def size
  attachments.size
end