Method: Symphony::ClassMethods#create_methods

Defined in:
lib/symphony/symphony.rb

#create_methods(defn) ⇒ Object



157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/symphony/symphony.rb', line 157

def create_methods(defn)
  # reader
  class_eval "
    def #{defn[:method_name]}
      puts '#{defn[:method_name]}:' + self.class.symphony_definitions.find{ |d| d[:method_name] == :#{defn[:method_name]} }.inspect
      @#{defn[:method_name]} || self.class.symphony_definitions.find{ |d| d[:method_name] == :#{defn[:method_name]} }[:options][:default]
    end
  "

  # writer
  check_method = (defn[:multiplicity] == :many or defn[:multiplicity] > 1) ? 'check_made_of_only' : 'check_type'
  class_eval "
    def #{defn[:method_name]}=(obj)
      raise TypeError, \"#{defn[:method_name]} is not nillable\" if !#{defn[:options][:nillable]} and obj == nil
      #{check_method}(#{defn[:options][:of]}, obj) if obj != nil or !#{defn[:options][:nillable]}

      @#{defn[:method_name]} = obj
    end
  "
end