Class: DataMapper::Reflection::Builders::Source::Relationship

Inherits:
Object
  • Object
show all
Includes:
OptionBuilder
Defined in:
lib/dm-reflection/builders/source_builder.rb

Direct Known Subclasses

ManyToOne, OneToMany, OneToOne

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OptionBuilder

#backend_options, #options, #rest_options

Instance Attribute Details

#backendObject

Returns the value of attribute backend.



211
212
213
# File 'lib/dm-reflection/builders/source_builder.rb', line 211

def backend
  @backend
end

Class Method Details

.for(backend) ⇒ Object



213
214
215
216
217
218
219
220
221
222
# File 'lib/dm-reflection/builders/source_builder.rb', line 213

def self.for(backend)
  case backend
  when DataMapper::Associations::ManyToOne::Relationship  then ManyToOne. new(backend)
  when DataMapper::Associations::OneToOne::Relationship   then OneToOne.  new(backend)
  when DataMapper::Associations::OneToMany::Relationship  then OneToMany. new(backend)
  when DataMapper::Associations::ManyToMany::Relationship then ManyToMany.new(backend)
  else
    raise ArgumentError, "#{backend.class} is no valid datamapper relationship"
  end
end

Instance Method Details

#cardinalityObject



238
239
240
# File 'lib/dm-reflection/builders/source_builder.rb', line 238

def cardinality
  "#{min}..#{max}"
end

#irrelevant_optionsObject



265
266
267
# File 'lib/dm-reflection/builders/source_builder.rb', line 265

def irrelevant_options
  [ :min, :max, :parent_repository_name, :child_repository_name ]
end

#maxObject



246
247
248
# File 'lib/dm-reflection/builders/source_builder.rb', line 246

def max
  backend.max
end

#minObject



242
243
244
# File 'lib/dm-reflection/builders/source_builder.rb', line 242

def min
  backend.min
end

#nameObject



233
234
235
# File 'lib/dm-reflection/builders/source_builder.rb', line 233

def name
  backend.name
end

#option_prioritiesObject



251
252
253
# File 'lib/dm-reflection/builders/source_builder.rb', line 251

def option_priorities
  [ :through, :constraint ]
end

#prioritized_optionsObject



255
256
257
258
259
260
261
262
263
# File 'lib/dm-reflection/builders/source_builder.rb', line 255

def prioritized_options
  option_priorities.inject([]) do |memo, name|
    if name == :through && through = backend_options[:through]
      value = through.is_a?(Symbol) ? through : ActiveSupport::Inflector.demodulize(through)
      memo << [ :through, value ]
    end
    memo
  end
end

#to_rubyObject



224
225
226
# File 'lib/dm-reflection/builders/source_builder.rb', line 224

def to_ruby
  "#{type} #{cardinality}, :#{name}#{options}"
end

#typeObject

Raises:

  • (NotImplementedError)


229
230
231
# File 'lib/dm-reflection/builders/source_builder.rb', line 229

def type
  raise NotImplementedError
end