Sha256: 2fb37933ebafea9b199bf13b9b6d601a856b6c491f31084764cef7a8a689af4f

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

module Ixtlan
  module Babel
    class Context

      def initialize( options )
        @only = options[ :only ].collect { |o| o.to_s } if options[ :only ]
        @except = ( options[:except] || [] ).collect { |e| e.to_s }

        opts = options[ :include ]
        @include = case opts
                   when Array
                     opts.collect { |i| i.to_s }
                   when Hash
                     Hash[ opts.collect { |k,v| [ k.to_s, v ] } ]
                   else
                     []
                   end
        @methods = (options[:methods] || []).collect { |m| m.to_s }
      end

      def methods
        @methods + ( @include.is_a?( Array ) ? @include : @include.keys ) 
      end

      def allowed?( key )
        ( @only && @only.include?( key ) ) || ( @only.nil? && !@except.include?( key ) ) || @methods.include?( key )
      end

      def include?( key )
        @include.include? key
      end

      def array?
        @include.is_a?( Array )
      end

      def []( key )
        self.class.new( @include.is_a?( Array ) ? {} : @include[ key ] )
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ixtlan-babel-0.3.0 lib/ixtlan/babel/context.rb
ixtlan-babel-0.2.1 lib/ixtlan/babel/context.rb
ixtlan-babel-0.2.0 lib/ixtlan/babel/context.rb