Class: Build2Spec::StandIn

Inherits:
Object show all
Defined in:
lib/build2spec.rb

Direct Known Subclasses

UnknownStandIn

Constant Summary collapse

Indent =
" " * 2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ StandIn

Returns a new instance of StandIn.



197
198
199
200
201
202
203
# File 'lib/build2spec.rb', line 197

def initialize(klass)
  @covering_for = klass
  @faked_instance_methods = {}
  @faked_module_methods = {}
  @nested = {}
  @i_am_module = nil
end

Instance Attribute Details

#covering_forObject (readonly)

Returns the value of attribute covering_for.



205
206
207
# File 'lib/build2spec.rb', line 205

def covering_for
  @covering_for
end

#faked_instance_methodsObject (readonly)

Returns the value of attribute faked_instance_methods.



205
206
207
# File 'lib/build2spec.rb', line 205

def faked_instance_methods
  @faked_instance_methods
end

#faked_module_methodsObject (readonly)

Returns the value of attribute faked_module_methods.



205
206
207
# File 'lib/build2spec.rb', line 205

def faked_module_methods
  @faked_module_methods
end

#nestedObject (readonly)

Returns the value of attribute nested.



205
206
207
# File 'lib/build2spec.rb', line 205

def nested
  @nested
end

Instance Method Details

#argument_text(spec) ⇒ Object



220
221
222
223
224
225
226
227
228
229
230
# File 'lib/build2spec.rb', line 220

def argument_text(spec)
  required = spec[0].begin > 0 ? Range.new("a",(?a + spec[0].begin - 1).chr).to_a : []
  optional = spec[0].end - spec[0].begin > 0 ? 
    Range.new((?a + spec[0].begin).chr,(?a + spec[0].end - 1).chr).to_a.map{|a| "#{a}=nil"} : []

  args = required + optional
  if spec[1]
    args << "&block"
  end
  return args.length > 0 ? "( #{args.join(", ")} )" : ""
end

#empty?Boolean

Returns:

  • (Boolean)


257
258
259
260
261
# File 'lib/build2spec.rb', line 257

def empty?
  return faked_instance_methods.values.empty? &&
    faked_module_methods.values.empty? &&
    nested.empty?
end

#is_classObject



236
237
238
# File 'lib/build2spec.rb', line 236

def is_class
  @i_am_module = "class"
end

#is_moduleObject



232
233
234
# File 'lib/build2spec.rb', line 232

def is_module
  @i_am_module = "module"
end

#method_text(name, spec, indent) ⇒ Object



209
210
211
212
213
214
215
216
217
218
# File 'lib/build2spec.rb', line 209

def method_text(name, spec, indent)
  args = argument_text(spec)

  result = spec[2].inspect
  if spec[2].respond_to?(:guess)
    result = spec[2].guess
  end

  return "def #{name}#{args}\n#{indent}return #{result}\nend\n"
end

#mod_text(nesting = "") ⇒ Object



240
241
242
243
244
245
246
247
# File 'lib/build2spec.rb', line 240

def mod_text(nesting="")
  return "" if empty?
  body = body_text(nesting)

  text = mod_opener(nesting)
  text << body
  text << "end\n"
end

#nameObject



253
254
255
# File 'lib/build2spec.rb', line 253

def name
  covering_for.name
end

#nest_standin(other) ⇒ Object



249
250
251
# File 'lib/build2spec.rb', line 249

def nest_standin(other)
  @nested[other] = nil
end