Module: BeautifiedUrl::ClassMethods
- Defined in:
- lib/beautified_url.rb
Instance Attribute Summary collapse
-
#bu_attributes_hset ⇒ Object
Returns the value of attribute bu_attributes_hset.
-
#bu_callback_event ⇒ Object
Returns the value of attribute bu_callback_event.
-
#bu_scope_set ⇒ Object
Returns the value of attribute bu_scope_set.
-
#bu_token ⇒ Object
Returns the value of attribute bu_token.
Instance Method Summary collapse
-
#beautify_on(event) ⇒ Object
Signifies on what ‘before’ event should the beautification take palce.
-
#beautify_url_with_scope(options) ⇒ Object
Accepts scope parameter for beautified_url Eg => beautify_url_with_scope :company_id #For universal scope of all attributes with beautified_url capabilities.
-
#is_beautifiable? ⇒ Boolean
Checks if model is well equipped to use beautified_url capability by checking up attribute names, if it is paired with attribute starting with name ‘bu’.
Instance Attribute Details
#bu_attributes_hset ⇒ Object
Returns the value of attribute bu_attributes_hset.
13 14 15 |
# File 'lib/beautified_url.rb', line 13 def bu_attributes_hset @bu_attributes_hset end |
#bu_callback_event ⇒ Object
Returns the value of attribute bu_callback_event.
15 16 17 |
# File 'lib/beautified_url.rb', line 15 def bu_callback_event @bu_callback_event end |
#bu_scope_set ⇒ Object
Returns the value of attribute bu_scope_set.
14 15 16 |
# File 'lib/beautified_url.rb', line 14 def bu_scope_set @bu_scope_set end |
#bu_token ⇒ Object
Returns the value of attribute bu_token.
12 13 14 |
# File 'lib/beautified_url.rb', line 12 def bu_token @bu_token end |
Instance Method Details
#beautify_on(event) ⇒ Object
Signifies on what ‘before’ event should the beautification take palce. Valid values are :create (default value), :save, :update, :validate
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/beautified_url.rb', line 40 def beautify_on(event) begin event = event.to_sym unless event.is_a?(Symbol) @bu_callback_event = [:create, :save, :update, :validate].include?(event) ? event : :create rescue Exception => e Rails.logger.debug e. Rails.logger.debug e.backtrace.join("\n") @bu_callback_event = :create end @bu_callback_event end |
#beautify_url_with_scope(options) ⇒ Object
Accepts scope parameter for beautified_url Eg => beautify_url_with_scope :company_id #For universal scope of all attributes with beautified_url capabilities. Eg => beautify_url_with_scope => :company_id, :title => :subdomain
33 34 35 36 |
# File 'lib/beautified_url.rb', line 33 def beautify_url_with_scope() = .to_s if .is_a?(Symbol) @bu_scope_set = if .is_a?(Hash) or .is_a?(String) end |
#is_beautifiable? ⇒ Boolean
Checks if model is well equipped to use beautified_url capability by checking up attribute names, if it is paired with attribute starting with name ‘bu’
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/beautified_url.rb', line 18 def is_beautifiable? @bu_token ||= "_bu_" @bu_attributes_hset = {} attribute_names.each do |attribute_name| if attribute_name.starts_with?(@bu_token) p_attr = attribute_name.gsub(@bu_token, "") #parent attribute name @bu_attributes_hset[p_attr] = attribute_name if attribute_names.include?(p_attr) end end (not @bu_attributes_hset.empty?) end |