Class: DataMapper::Reflection::Builders::Source::Property

Inherits:
Object
  • Object
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

Methods included from OptionBuilder

#backend_options, #rest_options

Instance Attribute Details

#backendObject

Returns the value of attribute backend.



157
158
159
# File 'lib/dm-reflection/builders/source_builder.rb', line 157

def backend
  @backend
end

Class Method Details

.for(backend) ⇒ Object



159
160
161
# File 'lib/dm-reflection/builders/source_builder.rb', line 159

def self.for(backend)
  new(backend)
end

Instance Method Details

#irrelevant_optionsObject



195
196
197
# File 'lib/dm-reflection/builders/source_builder.rb', line 195

def irrelevant_options
  []
end

#nameObject



167
168
169
# File 'lib/dm-reflection/builders/source_builder.rb', line 167

def name
  backend.name
end

#option_prioritiesObject



180
181
182
# File 'lib/dm-reflection/builders/source_builder.rb', line 180

def option_priorities
  [ :key, :required, :unique, :unique_index ]
end

#optionsObject



176
177
178
# File 'lib/dm-reflection/builders/source_builder.rb', line 176

def options
  backend.type == DataMapper::Types::Serial ? '' : super
end

#prioritized_optionsObject



184
185
186
187
188
189
190
191
192
193
# File 'lib/dm-reflection/builders/source_builder.rb', line 184

def prioritized_options
  option_priorities.inject([]) do |memo, name|
    if name == :required
      memo << [ name, backend_options[name] ] if backend_options[name] && !backend_options[:key]
    else
      memo << [ name, backend_options[name] ] if backend_options[name]
    end
    memo
  end
end

#to_rubyObject



163
164
165
# File 'lib/dm-reflection/builders/source_builder.rb', line 163

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

#typeObject



171
172
173
# File 'lib/dm-reflection/builders/source_builder.rb', line 171

def type
  ActiveSupport::Inflector.demodulize(backend.type)
end