Class: DataMapper::Reflection::Builders::Source::Relationship
- Inherits:
-
Object
- Object
- DataMapper::Reflection::Builders::Source::Relationship
show all
- Includes:
- OptionBuilder
- Defined in:
- lib/dm-reflection/builders/source_builder.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#backend_options, #options, #rest_options
Instance Attribute Details
#backend ⇒ Object
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
#cardinality ⇒ Object
238
239
240
|
# File 'lib/dm-reflection/builders/source_builder.rb', line 238
def cardinality
"#{min}..#{max}"
end
|
#irrelevant_options ⇒ Object
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
|
#max ⇒ Object
246
247
248
|
# File 'lib/dm-reflection/builders/source_builder.rb', line 246
def max
backend.max
end
|
#min ⇒ Object
242
243
244
|
# File 'lib/dm-reflection/builders/source_builder.rb', line 242
def min
backend.min
end
|
#name ⇒ Object
233
234
235
|
# File 'lib/dm-reflection/builders/source_builder.rb', line 233
def name
backend.name
end
|
#option_priorities ⇒ Object
251
252
253
|
# File 'lib/dm-reflection/builders/source_builder.rb', line 251
def option_priorities
[ :through, :constraint ]
end
|
#prioritized_options ⇒ Object
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_ruby ⇒ Object
224
225
226
|
# File 'lib/dm-reflection/builders/source_builder.rb', line 224
def to_ruby
"#{type} #{cardinality}, :#{name}#{options}"
end
|
#type ⇒ Object
229
230
231
|
# File 'lib/dm-reflection/builders/source_builder.rb', line 229
def type
raise NotImplementedError
end
|