Class: Kartograph::Artist
- Inherits:
-
Object
- Object
- Kartograph::Artist
- Defined in:
- lib/kartograph/artist.rb
Instance Attribute Summary collapse
-
#map ⇒ Object
readonly
Returns the value of attribute map.
Instance Method Summary collapse
- #build_properties(object, scope) ⇒ Object
- #draw(object, scope = nil) ⇒ Object
-
#initialize(map) ⇒ Artist
constructor
A new instance of Artist.
- #properties ⇒ Object
Constructor Details
#initialize(map) ⇒ Artist
Returns a new instance of Artist.
5 6 7 |
# File 'lib/kartograph/artist.rb', line 5 def initialize(map) @map = map end |
Instance Attribute Details
#map ⇒ Object (readonly)
Returns the value of attribute map.
3 4 5 |
# File 'lib/kartograph/artist.rb', line 3 def map @map end |
Instance Method Details
#build_properties(object, scope) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kartograph/artist.rb', line 22 def build_properties(object, 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(object, scope = nil) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/kartograph/artist.rb', line 13 def draw(object, scope = nil) if map.cache cache_key = map.cache_key.call(object, scope) map.cache.fetch(cache_key) { build_properties(object, scope) } else build_properties(object, scope) end end |
#properties ⇒ Object
9 10 11 |
# File 'lib/kartograph/artist.rb', line 9 def properties map.properties end |