Class: Typisch::DSL::ObjectContext

Inherits:
Object
  • Object
show all
Defined in:
lib/typisch/dsl.rb

Direct Known Subclasses

DerivedObjectContext

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#propertiesObject (readonly)

Returns the value of attribute properties.



162
163
164
# File 'lib/typisch/dsl.rb', line 162

def properties
  @properties
end

#property_annotationsObject (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(description_or_options, options=nil)
  if description_or_options.is_a?(::String)
    options ||= {}; options[:description] = description_or_options
  else
    options = description_or_options
  end
  @pending_annotations ||= {}
  @pending_annotations.merge!(options)
end

#property(name, *type_args, &type_block_arg) ⇒ Object

Raises:



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