Class: Typisch::DSL::ObjectContext
- Inherits:
-
Object
- Object
- Typisch::DSL::ObjectContext
- Defined in:
- lib/typisch/dsl.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#property_annotations ⇒ Object
readonly
Returns the value of attribute property_annotations.
Instance Method Summary collapse
-
#annotate(description_or_options, options = nil) ⇒ Object
property annotations apply to the next declared property.
-
#initialize(parent_context) ⇒ ObjectContext
constructor
A new instance of ObjectContext.
- #method_missing(name, *args, &block) ⇒ Object
- #property(name, *type_args, &type_block_arg) ⇒ Object
Constructor Details
#initialize(parent_context) ⇒ ObjectContext
Returns a new instance of ObjectContext.
164 165 166 167 |
# File 'lib/typisch/dsl.rb', line 164 def initialize(parent_context) @parent_context = parent_context @properties = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
193 194 195 |
# File 'lib/typisch/dsl.rb', line 193 def method_missing(name, *args, &block) @parent_context.respond_to?(name) ? @parent_context.send(name, *args, &block) : super end |
Instance Attribute Details
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
162 163 164 |
# File 'lib/typisch/dsl.rb', line 162 def properties @properties end |
#property_annotations ⇒ Object (readonly)
Returns the value of attribute property_annotations.
162 163 164 |
# File 'lib/typisch/dsl.rb', line 162 def property_annotations @property_annotations end |
Instance Method Details
#annotate(description_or_options, options = nil) ⇒ Object
property annotations apply to the next declared property.
annotate “Some description”, :some_other => ‘annotations’ annotate :description => “Some description”, :some_other => ‘annotations’
173 174 175 176 177 178 179 180 181 |
# File 'lib/typisch/dsl.rb', line 173 def annotate(, =nil) if .is_a?(::String) ||= {}; [:description] = else = end @pending_annotations ||= {} @pending_annotations.merge!() end |
#property(name, *type_args, &type_block_arg) ⇒ Object
183 184 185 186 187 188 189 190 191 |
# File 'lib/typisch/dsl.rb', line 183 def property(name, *type_args, &type_block_arg) raise Error, "property #{name.inspect} declared twice" if @properties[name] @properties[name] = [type_args, type_block_arg] if @pending_annotations @property_annotations ||= {} @property_annotations[name] = @pending_annotations @pending_annotations = nil end end |