Class: Cartograph::Artist
- Inherits:
-
Object
- Object
- Cartograph::Artist
- Defined in:
- lib/cartograph/artist.rb
Instance Attribute Summary collapse
-
#map ⇒ Object
readonly
Returns the value of attribute map.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
Instance Method Summary collapse
- #build_properties(scope) ⇒ Object
- #draw(scope = nil) ⇒ Object
-
#initialize(object, map) ⇒ Artist
constructor
A new instance of Artist.
- #properties ⇒ Object
Constructor Details
#initialize(object, map) ⇒ Artist
Returns a new instance of Artist.
5 6 7 8 |
# File 'lib/cartograph/artist.rb', line 5 def initialize(object, map) @object = object @map = map end |
Instance Attribute Details
#map ⇒ Object (readonly)
Returns the value of attribute map.
3 4 5 |
# File 'lib/cartograph/artist.rb', line 3 def map @map end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
3 4 5 |
# File 'lib/cartograph/artist.rb', line 3 def object @object end |
Instance Method Details
#build_properties(scope) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cartograph/artist.rb', line 23 def build_properties(scope) scoped_properties = scope ? properties.filter_by_scope(scope) : properties scoped_properties.each_with_object({}) do |property, mapped| begin mapped[property.key] = property.value_for(object, scope) rescue NoMethodError => e raise ArgumentError, "#{object} does not respond to #{property.name}, so we can't map it" end end end |
#draw(scope = nil) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/cartograph/artist.rb', line 14 def draw(scope = nil) if map.cache cache_key = map.cache_key.call(object, scope) map.cache.fetch(cache_key) { build_properties(scope) } else build_properties(scope) end end |
#properties ⇒ Object
10 11 12 |
# File 'lib/cartograph/artist.rb', line 10 def properties map.properties end |