Class: Charisma::Curator
- Inherits:
-
Object
- Object
- Charisma::Curator
- Extended by:
- Forwardable
- Defined in:
- lib/charisma/curator.rb,
lib/charisma/curator/curation.rb
Overview
A Hash-like object that stores computed characteristics about an instance of a characterized class.
Every instance of a characterized class gets a Curator, accessed via #characteristics
.
Defined Under Namespace
Modules: LooseEquality Classes: Curation
Instance Attribute Summary collapse
-
#characteristics ⇒ Object
readonly
The hashed wrapped by the curator that actually stores the computed characteristics’.
-
#subject ⇒ Object
readonly
The curator’s subject–the instance itself’.
Instance Method Summary collapse
-
#[]=(key, value) ⇒ Object
Store a late-defined characteristic, with a Charisma wrapper.
-
#initialize(subject) ⇒ Curator
constructor
Create a Curator.
-
#inspect ⇒ Object
A custom inspection method to enhance IRB and log readability.
- #to_s ⇒ Object
Constructor Details
#initialize(subject) ⇒ Curator
Create a Curator.
Typically this is done automatically when #characteristics
is called on an instance of a characterized class for the first time.
19 20 21 22 23 24 25 26 27 |
# File 'lib/charisma/curator.rb', line 19 def initialize(subject) @characteristics = {}.extend LooseEquality @subject = subject subject.class.characterization.keys.each do |key| if subject.respond_to?(key) and value = subject.send(key) self[key] = value end end end |
Instance Attribute Details
#characteristics ⇒ Object (readonly)
The hashed wrapped by the curator that actually stores the computed characteristics’
12 13 14 |
# File 'lib/charisma/curator.rb', line 12 def characteristics @characteristics end |
#subject ⇒ Object (readonly)
The curator’s subject–the instance itself’
9 10 11 |
# File 'lib/charisma/curator.rb', line 9 def subject @subject end |
Instance Method Details
#[]=(key, value) ⇒ Object
Store a late-defined characteristic, with a Charisma wrapper.
32 33 34 |
# File 'lib/charisma/curator.rb', line 32 def []=(key, value) characteristics[key] = Curation.new value, subject.class.characterization[key] end |
#inspect ⇒ Object
A custom inspection method to enhance IRB and log readability
37 38 39 |
# File 'lib/charisma/curator.rb', line 37 def inspect "<Charisma:Curator #{keys.length} known characteristic(s)>" end |
#to_s ⇒ Object
42 |
# File 'lib/charisma/curator.rb', line 42 def to_s; inspect end |