Class: ToFactory::Generation::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/to_factory/generation/attribute.rb

Instance Method Summary collapse

Constructor Details

#initialize(attribute, value) ⇒ Attribute

Returns a new instance of Attribute.



4
5
6
7
# File 'lib/to_factory/generation/attribute.rb', line 4

def initialize(attribute, value)
  @attribute = attribute
  @value = value
end

Instance Method Details

#inspect_value(value, nested = false) ⇒ Object



19
20
21
22
23
24
25
26
27
# File 'lib/to_factory/generation/attribute.rb', line 19

def inspect_value(value, nested=false)
  formatted = format(value, nested)

  if !value.is_a?(Hash) && !nested
    formatted = " #{formatted}"
  end

  formatted
end

#to_sObject



9
10
11
12
13
14
15
16
17
# File 'lib/to_factory/generation/attribute.rb', line 9

def to_s
  setter = "#{@attribute}#{inspect_value(@value)}"

  if ToFactory.new_syntax?
    "    #{setter}"
  else
    "  o.#{setter}"
  end
end