Class: SimpleObjectSerialization::Attribute

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options, block) ⇒ Attribute

Returns a new instance of Attribute.



7
8
9
10
11
# File 'lib/simple_object_serialization/attribute.rb', line 7

def initialize(name, options, block)
  @name = name
  @options = options
  @block = block
end

Instance Attribute Details

#blockObject (readonly)

Returns the value of attribute block.



5
6
7
# File 'lib/simple_object_serialization/attribute.rb', line 5

def block
  @block
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/simple_object_serialization/attribute.rb', line 5

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/simple_object_serialization/attribute.rb', line 5

def options
  @options
end

Instance Method Details

#skip_for?(serializer) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/simple_object_serialization/attribute.rb', line 13

def skip_for?(serializer)
  options[:if] ? !serializer.instance_eval(&options[:if]) : false
end

#value_for(serializer) ⇒ Object



17
18
19
# File 'lib/simple_object_serialization/attribute.rb', line 17

def value_for(serializer)
  block ? serializer.instance_eval(&block) : serializer.object.public_send(name)
end