Class: XDry::OAttribute

Inherits:
Object
  • Object
show all
Defined in:
lib/xdry/parsing/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(oclass, name) ⇒ OAttribute

Returns a new instance of OAttribute.



142
143
144
145
146
147
148
# File 'lib/xdry/parsing/model.rb', line 142

def initialize oclass, name
  @oclass, @name = oclass, name

  @field_def    = nil
  @property_def = nil
  @synthesizes  = []
end

Instance Attribute Details

#field_defObject (readonly)

Returns the value of attribute field_def.



140
141
142
# File 'lib/xdry/parsing/model.rb', line 140

def field_def
  @field_def
end

#nameObject (readonly)

Returns the value of attribute name.



139
140
141
# File 'lib/xdry/parsing/model.rb', line 139

def name
  @name
end

Instance Method Details

#add_field_def!(field_def) ⇒ Object



158
159
160
# File 'lib/xdry/parsing/model.rb', line 158

def add_field_def! field_def
  @field_def = field_def
end

#add_property_def!(property_def) ⇒ Object



162
163
164
# File 'lib/xdry/parsing/model.rb', line 162

def add_property_def! property_def
  @property_def = property_def
end

#add_synthesize!(synthesize) ⇒ Object



166
167
168
# File 'lib/xdry/parsing/model.rb', line 166

def add_synthesize! synthesize
  @synthesizes << synthesize
end

#field_nameObject



150
151
152
153
154
155
156
# File 'lib/xdry/parsing/model.rb', line 150

def field_name
  if @field_def
    @field_def.name
  else
    FIELD_PREFIX + name
  end
end

#getter_selectorObject



210
211
212
213
# File 'lib/xdry/parsing/model.rb', line 210

def getter_selector
  # FIXME: need to account for a possible selector override declared in @property
  @name
end

#has_field_def?Boolean

Returns:

  • (Boolean)


170
171
172
# File 'lib/xdry/parsing/model.rb', line 170

def has_field_def?
  not @field_def.nil?
end

#has_property_def?Boolean

Returns:

  • (Boolean)


174
175
176
# File 'lib/xdry/parsing/model.rb', line 174

def has_property_def?
  not @property_def.nil?
end

#has_synthesize?Boolean

Returns:

  • (Boolean)


178
179
180
# File 'lib/xdry/parsing/model.rb', line 178

def has_synthesize?
  not @synthesizes.empty?
end

#new_field_defObject



186
187
188
# File 'lib/xdry/parsing/model.rb', line 186

def new_field_def
  NFieldDef.new(field_name, type)
end

#new_property_defObject



182
183
184
# File 'lib/xdry/parsing/model.rb', line 182

def new_property_def
  NPropertyDef.new(name, type)
end

#new_synthesizeObject



190
191
192
# File 'lib/xdry/parsing/model.rb', line 190

def new_synthesize
  NSynthesize.new([SynthesizeItem.new(name, (field_name == name ? nil : field_name) )])
end

#persistent?Boolean

Returns:

  • (Boolean)


194
195
196
# File 'lib/xdry/parsing/model.rb', line 194

def persistent?
  @field_def && @field_def.persistent?
end

#to_sObject



225
226
227
228
229
# File 'lib/xdry/parsing/model.rb', line 225

def to_s
  traits = []
  traits << field_name if has_field_def?
  "#{type} #{name}" + (traits.empty? ? "" : " (" + traits.join(", ") + ")")
end

#typeObject



215
216
217
218
219
220
221
222
223
# File 'lib/xdry/parsing/model.rb', line 215

def type
  if @property_def
    @property_def.type
  elsif @field_def
    @field_def.type
  else
    nil
  end
end

#type_known?Boolean

Returns:

  • (Boolean)


198
199
200
# File 'lib/xdry/parsing/model.rb', line 198

def type_known?
  not type.nil?
end

#wants_constructor?Boolean

Returns:

  • (Boolean)


206
207
208
# File 'lib/xdry/parsing/model.rb', line 206

def wants_constructor?
  has_field_def? && field_def.wants_constructor?
end

#wants_property?Boolean

Returns:

  • (Boolean)


202
203
204
# File 'lib/xdry/parsing/model.rb', line 202

def wants_property?
  has_field_def? && field_def.wants_property?
end