class Amber::StaticPage::PropertySet
Public Class Methods
new()
click to toggle source
# File lib/amber/static_page/property_set.rb, line 18 def initialize @this = ThisPropertySet.new end
Public Instance Methods
get(property_name, inheritable_only=false)
click to toggle source
get the value of a property
the @this properties are non-inheritable. If `inheritable_only` is true, we don't consider them when returning the property value.
# File lib/amber/static_page/property_set.rb, line 40 def get(property_name, inheritable_only=false) if inheritable_only || @this.nil? safe_instance_get("@#{property_name}") else value = @this.get(property_name) if value.nil? value = safe_instance_get("@#{property_name}") end value end end
method_missing(method, *args)
click to toggle source
# File lib/amber/static_page/property_set.rb, line 22 def method_missing(method, *args) if method =~ /=$/ set(method, args.first) else get(method) end end
set(property_name, value)
click to toggle source
set the value of a property
if the property has a non-nil value set in the @this prop set, then we set it there. otherwise, it is set in the inheritable set.
# File lib/amber/static_page/property_set.rb, line 58 def set(property_name, value) property_name = property_name.to_s.sub(/=$/, '') instance_variable = "@" + property_name if @this.nil? || @this.get(property_name).nil? instance_variable_set(instance_variable, value) else @this.instance_variable_set(instance_variable, value) end end
textile(str)
click to toggle source
# File lib/amber/static_page/property_set.rb, line 30 def textile(str) RedCloth.new(str).to_html end
to_s()
click to toggle source
# File lib/amber/static_page/property_set.rb, line 68 def to_s "<" + instance_variables.map{|v| "#{v}=#{instance_variable_get(v)}"}.join(', ') + ">" end
Private Instance Methods
safe_instance_get(prop_name)
click to toggle source
# File lib/amber/static_page/property_set.rb, line 74 def safe_instance_get(prop_name) if !instance_variable_defined?(prop_name) instance_variable_set(prop_name, nil) end instance_variable_get(prop_name) end