Class: Amber::StaticPage::PropertySet

Inherits:
Object
  • Object
show all
Defined in:
lib/amber/static_page/property_set.rb

Direct Known Subclasses

ThisPropertySet

Instance Method Summary collapse

Constructor Details

#initializePropertySet

Returns a new instance of PropertySet.



18
19
20
# File 'lib/amber/static_page/property_set.rb', line 18

def initialize
  @this = ThisPropertySet.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object



22
23
24
25
26
27
28
# 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

Instance Method Details

#get(property_name, inheritable_only = false) ⇒ Object

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.



40
41
42
43
44
45
46
47
48
49
50
# 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

#set(property_name, value) ⇒ Object

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.



58
59
60
61
62
63
64
65
66
# 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) ⇒ Object



30
31
32
# File 'lib/amber/static_page/property_set.rb', line 30

def textile(str)
  RedCloth.new(str).to_html
end

#to_sObject



68
69
70
# File 'lib/amber/static_page/property_set.rb', line 68

def to_s
  "<" + instance_variables.map{|v| "#{v}=#{instance_variable_get(v)}"}.join(', ') + ">"
end