class ParlourDataMapper

Constants

PROPERTIES_TO_TYPES
VERSION

Public Instance Methods

generate(root) click to toggle source
# File lib/parlour-datamapper.rb, line 7
def generate(root)
  # Get all resources
  resources = ObjectSpace.each_object(Class).select do |x|
    x.included_modules.include?(DataMapper::Resource)
  end

  # Generate namespaces for each
  resources.each do |resource|
    root.path(resource) do |klass|
      # Iterate over each object property for this resource
      resource.properties.each do |prop|
        type_string = PROPERTIES_TO_TYPES[prop.class]

        # Define the getter
        klass.create_method(
          name: prop.name.to_s,
          returns: type_string
        )

        # Define the setter
        klass.create_method(
          name: "#{prop.name}=",
          parameters: [
            Parlour::RbiGenerator::Parameter.new(
              name: 'value',
              type: type_string
            )
          ],
          returns: type_string
        )
      end
    end
  end
end