Class: Ixtlan::Babel::Context
- Inherits:
-
Object
- Object
- Ixtlan::Babel::Context
- Defined in:
- lib/ixtlan/babel/context.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #allowed?(key) ⇒ Boolean
- #array? ⇒ Boolean
- #include?(key) ⇒ Boolean
-
#initialize(options) ⇒ Context
constructor
A new instance of Context.
- #methods ⇒ Object
Constructor Details
#initialize(options) ⇒ Context
Returns a new instance of Context.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ixtlan/babel/context.rb', line 25 def initialize( ) @only = [ :only ].collect { |o| o.to_s } if [ :only ] @except = ( [:except] || [] ).collect { |e| e.to_s } opts = [ :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 = ([:methods] || []).collect { |m| m.to_s } end |
Instance Method Details
#[](key) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/ixtlan/babel/context.rb', line 57 def []( key ) if @include.include?( key ) self.class.new( @include.is_a?( Array ) ? {} : @include[ key ] ) else self.class.new( @methods.is_a?( Array ) ? {} : @methods[ key ] ) end end |
#allowed?(key) ⇒ Boolean
45 46 47 |
# File 'lib/ixtlan/babel/context.rb', line 45 def allowed?( key ) ( @only && @only.include?( key ) ) || ( @only.nil? && !@except.include?( key ) ) || @methods.include?( key ) end |
#array? ⇒ Boolean
53 54 55 |
# File 'lib/ixtlan/babel/context.rb', line 53 def array? @include.is_a?( Array ) end |
#include?(key) ⇒ Boolean
49 50 51 |
# File 'lib/ixtlan/babel/context.rb', line 49 def include?( key ) @include.include?( key ) || @methods.include?( key ) end |
#methods ⇒ Object
41 42 43 |
# File 'lib/ixtlan/babel/context.rb', line 41 def methods @methods + ( @include.is_a?( Array ) ? @include : @include.keys ) end |