Sha256: 3b828711dfda45b7fcd7ecad50cb60c02794b865a95042a22a6d23716616a108

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module Personify
  # This specifies the context we can evaluate in 
  class Context
    
    class << self
      def allowed_context_methods
        @allowed_methods ||= []
      end
      
      def context_method(method_name)
        self.allowed_context_methods << method_name.to_sym if self.instance_methods.include?(method_name.to_s) || self.instance_methods.include?(method_name.to_sym)
      end

      def allow_method?(method_name)
        self.allowed_context_methods.include?(method_name.to_sym)
      end
    end

    def allow_method?(method_name)
      self.class.allow_method?(method_name)
    end
    
    def local_assigns=(assigns)
      @local_assigns = assigns
    end
    
    def local_assigns
      @local_assigns ||= {}
    end
    
    def [](k)
      self.local_assigns[k]
    end
    
    def has_key?(k)
      self.local_assigns.has_key?(k)
    end
      
    
    
  end
  
  class DefaultContext < Context
    
    def if(statement, value)    
      if statement
        value
      else
        nil
      end
    end
    context_method :if
    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
personify-1.1.2 lib/personify/context.rb