class Kartograph::Sculptor
Attributes
map[R]
object[R]
Public Class Methods
new(object, map)
click to toggle source
# File lib/kartograph/sculptor.rb, line 5 def initialize(object, map) @object = object @map = map end
Public Instance Methods
properties()
click to toggle source
# File lib/kartograph/sculptor.rb, line 10 def properties map.properties end
sculpt(scope = nil)
click to toggle source
# File lib/kartograph/sculptor.rb, line 27 def sculpt(scope = nil) return nil if @object.nil? scoped_properties = scope ? properties.filter_by_scope(scope) : properties scoped_properties.each_with_object(sculpted_object) do |property, mutable| setter_method = "#{property.name}=" value = property.value_from(object, scope) mutable.send(setter_method, value) end end
sculpted_object()
click to toggle source
# File lib/kartograph/sculptor.rb, line 14 def sculpted_object # Fallback initialization of the object we're extracting into @sculpted_object ||= map.mapping.new end
sculpted_object=(object)
click to toggle source
Set this to pass in an object to extract into. Must @param object must be of the same class as the map#mapping
# File lib/kartograph/sculptor.rb, line 21 def sculpted_object=(object) raise ArgumentError unless object.is_a?(map.mapping) @sculpted_object = object end