engines/adva_cms/vendor/plugins/stringex/lib/lucky_sneaks/acts_as_url.rb
# :doc:
# Creates a callback to automatically create an url-friendly representation
# of the <tt>attribute</tt> argument. Example:
# 
#   act_as_url :title
# 
# will use the string contents of the <tt>title</tt> attribute
# to create the permalink. <strong>Note:</strong> you can also use a non-database-backed
# method to supply the string contents for the permalink. Just use that method's name
# as the argument as you would an attribute.
# 
# The default attribute <tt>acts_as_url</tt> uses to save the permalink is <tt>url</tt>
# but this can be changed in the options hash. Available options are:
# 
# <tt>:url_attribute</tt>:: The name of the attribute to use for storing the generated url string.
#                           Default is <tt>:url</tt>
# <tt>:scope</tt>:: The name of model attribute to scope unique urls to. There is no default here.
# <tt>:only_when_blank</tt>:: If true, the url generation will only happen when <tt>:url_attribute</tt> is 
#                             blank. Default is false (meaning url generation will happen always)
# <tt>:sync_url</tt>:: If set to true, the url field will be updated when changes are made to the
#                      attribute it is based on. Default is false.
:doc:
Creates a callback to automatically create an url-friendly representation
of the attribute argument. Example.



will use the string contents of the title attribute
to create the permalink. Note: you can also use a non-database-backed
method to supply the string contents for the permalink. Just use that method's name
as the argument as you would an attribute.

The default attribute acts_as_url uses to save the permalink is url
but this can be changed in the options hash. Available options are.

:url_attribute:: The name of the attribute to use for storing the generated url string.
Default is :url
:scope:: The name of model attribute to scope unique urls to. There is no default here.
:only_when_blank:: If true, the url generation will only happen when :url_attribute is
blank. Default is false (meaning url generation will happen always)
:sync_url:: If set to true, the url field will be updated when changes are made to the
attribute it is based on. Default is false.
: doc : Creates a callback to automatically create an url - friendly representation of the attribute argument . Example . will use the string contents of the title attribute to create the permalink . Note : you can also use a non - database - backed method to supply the string contents for the permalink . Just use that method ' s name as the argument as you would an attribute . The default attribute acts_as_url uses to save the permalink is url but this can be changed in the options hash . Available options are . : url_attribute :: The name of the attribute to use for storing the generated url string . Default is : url : scope :: The name of model attribute to scope unique urls to . There is no default here . : only_when_blank :: If true the url generation will only happen when : url_attribute is blank . Default is false ( meaning url generation will happen always ) : sync_url :: If set to true the url field will be updated when changes are made to the attribute it is based on . Default is false .
def acts_as_url(attribute, options = {})
        class_inheritable_accessor :attribute_to_urlify
        class_inheritable_accessor :scope_for_url
        class_inheritable_accessor :url_attribute 
        class_inheritable_accessor :only_when_blank
        callback_installed = Proc.new do |callback|
          send(:"#{callback}_callback_chain").detect { |c| c.method == :ensure_unique_url }
        end
        if options[:sync_url]
          before_validation :ensure_unique_url unless callback_installed.call(:before_validation)
        else
          before_validation_on_create :ensure_unique_url unless callback_installed.call(:before_validation_on_create)
        end
        self.attribute_to_urlify = attribute
        self.scope_for_url = options[:scope]
        self.url_attribute = options[:url_attribute] || "url"
        self.only_when_blank = options[:only_when_blank] || false
      end
def acts_as_url ( attribute , options = { } ) class_inheritable_accessor :attribute_to_urlify class_inheritable_accessor :scope_for_url class_inheritable_accessor :url_attribute class_inheritable_accessor :only_when_blank callback_installed = Proc . new do | callback | send ( :" #{ callback } _callback_chain " ) . detect { | c | c . method == :ensure_unique_url } end if options [ :sync_url ] before_validation :ensure_unique_url unless callback_installed . call ( :before_validation ) else before_validation_on_create :ensure_unique_url unless callback_installed . call ( :before_validation_on_create ) end self . attribute_to_urlify = attribute self . scope_for_url = options [ :scope ] self . url_attribute = options [ :url_attribute ] || "url" self . only_when_blank = options [ :only_when_blank ] || false end
:doc:
Creates a callback to automatically create an url-friendly representation
of the <tt>attribute</tt> argument.
: doc : Creates a callback to automatically create an url - friendly representation of the <tt > attribute< / tt > argument .
# The attribute on the DB
attribute
options