Class: Representable::Definition
- Inherits:
-
Declarative::Definitions::Definition
- Object
- Declarative::Definitions::Definition
- Representable::Definition
- Defined in:
- lib/representable/definition.rb
Overview
Created at class compile time. Keeps configuration options for one property.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #array? ⇒ Boolean
- #create_binding(*args) ⇒ Object
- #delete!(name) ⇒ Object
- #has_default? ⇒ Boolean
- #hash? ⇒ Boolean
-
#initialize(sym, options = {}, &block) ⇒ Definition
constructor
A new instance of Definition.
- #inspect ⇒ Object
- #merge!(options, &block) ⇒ Object
- #name ⇒ Object (also: #getter)
- #representable? ⇒ Boolean
- #representer_module ⇒ Object
- #setter ⇒ Object
-
#typed? ⇒ Boolean
TODO: remove.
Constructor Details
#initialize(sym, options = {}, &block) ⇒ Definition
Returns a new instance of Definition.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/representable/definition.rb', line 11 def initialize(sym, ={}, &block) [:extend] = [:nested] if [:nested] super # defaults: [:parse_filter] = Pipeline[*[:parse_filter]] [:render_filter] = Pipeline[*[:render_filter]] setup!(, &block) end |
Instance Method Details
#[](name) ⇒ Object
44 45 46 47 48 |
# File 'lib/representable/definition.rb', line 44 def [](name) # return nil if name==:extend && self[:nested].nil? # return Uber::Options::Value.new(self[:nested]) if name==:extend @runtime_options[name] end |
#array? ⇒ Boolean
64 65 66 |
# File 'lib/representable/definition.rb', line 64 def array? self[:collection] end |
#create_binding(*args) ⇒ Object
80 81 82 |
# File 'lib/representable/definition.rb', line 80 def create_binding(*args) self[:binding].call(self, *args) end |
#delete!(name) ⇒ Object
38 39 40 41 42 |
# File 'lib/representable/definition.rb', line 38 def delete!(name) @runtime_options.delete(name) @options.delete(name) self end |
#has_default? ⇒ Boolean
72 73 74 |
# File 'lib/representable/definition.rb', line 72 def has_default? @options.has_key?(:default) end |
#hash? ⇒ Boolean
68 69 70 |
# File 'lib/representable/definition.rb', line 68 def hash? self[:hash] end |
#inspect ⇒ Object
84 85 86 87 |
# File 'lib/representable/definition.rb', line 84 def inspect state = (instance_variables-[:@runtime_options, :@name]).collect { |ivar| "#{ivar}=#{instance_variable_get(ivar)}" } "#<Representable::Definition ==>#{name} #{state.join(" ")}>" end |
#merge!(options, &block) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/representable/definition.rb', line 28 def merge!(, &block) = .clone [:parse_filter] = @options[:parse_filter].push(*[:parse_filter]) [:render_filter] = @options[:render_filter].push(*[:render_filter]) setup!(, &block) # FIXME: this doesn't yield :as etc. self end |
#name ⇒ Object Also known as: getter
23 24 25 |
# File 'lib/representable/definition.rb', line 23 def name self[:name] end |
#representable? ⇒ Boolean
58 59 60 61 62 |
# File 'lib/representable/definition.rb', line 58 def representable? return if self[:representable] == false self[:representable] or typed? end |
#representer_module ⇒ Object
76 77 78 |
# File 'lib/representable/definition.rb', line 76 def representer_module @options[:extend] end |
#setter ⇒ Object
50 51 52 |
# File 'lib/representable/definition.rb', line 50 def setter :"#{name}=" end |
#typed? ⇒ Boolean
TODO: remove.
54 55 56 |
# File 'lib/representable/definition.rb', line 54 def typed? # TODO: remove. self[:class] or self[:extend] or self[:instance] end |