Class: Babel::HashFilter
- Inherits:
-
Object
- Object
- Babel::HashFilter
- Defined in:
- lib/babel/hash_filter.rb
Constant Summary collapse
- NO_MODEL =
Object.new
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, options) ⇒ Object
- #default_context_key(default = nil) ⇒ Object
- #filter(hash = {}, model = NO_MODEL, &block) ⇒ Object
-
#initialize(context_or_options = nil) ⇒ HashFilter
constructor
A new instance of HashFilter.
- #options ⇒ Object
- #use(context_or_options) ⇒ Object
Constructor Details
#initialize(context_or_options = nil) ⇒ HashFilter
Returns a new instance of HashFilter.
4 5 6 |
# File 'lib/babel/hash_filter.rb', line 4 def initialize( = nil) use() end |
Instance Method Details
#[](key) ⇒ Object
25 26 27 |
# File 'lib/babel/hash_filter.rb', line 25 def [](key) context[key.to_sym] if key end |
#[]=(key, options) ⇒ Object
21 22 23 |
# File 'lib/babel/hash_filter.rb', line 21 def []=(key, ) context[key.to_sym] = if key end |
#default_context_key(default = nil) ⇒ Object
16 17 18 19 |
# File 'lib/babel/hash_filter.rb', line 16 def default_context_key(default = nil) @default = default if default @default end |
#filter(hash = {}, model = NO_MODEL, &block) ⇒ Object
50 51 52 |
# File 'lib/babel/hash_filter.rb', line 50 def filter(hash = {}, model = NO_MODEL, &block) filter_data(model, hash, , &block) if hash end |
#options ⇒ Object
54 55 56 |
# File 'lib/babel/hash_filter.rb', line 54 def @options || context[default_context_key] || {} end |
#use(context_or_options) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/babel/hash_filter.rb', line 29 def use() if case when Symbol if opts = context[] @options = opts.dup end when Hash @options = end else @options = nil end self end |