Class: Anony::Selectors
- Inherits:
-
Object
- Object
- Anony::Selectors
- Defined in:
- lib/anony/selectors.rb
Instance Attribute Summary collapse
-
#selectors ⇒ Object
readonly
Returns the value of attribute selectors.
Instance Method Summary collapse
- #for_subject(subject, &block) ⇒ Object
-
#initialize(model_class, &block) ⇒ Selectors
constructor
A new instance of Selectors.
- #select(subject, subject_id) ⇒ Object
Constructor Details
#initialize(model_class, &block) ⇒ Selectors
Returns a new instance of Selectors.
7 8 9 10 11 |
# File 'lib/anony/selectors.rb', line 7 def initialize(model_class, &block) @model_class = model_class @selectors = {} instance_exec(&block) if block end |
Instance Attribute Details
#selectors ⇒ Object (readonly)
Returns the value of attribute selectors.
13 14 15 |
# File 'lib/anony/selectors.rb', line 13 def selectors @selectors end |
Instance Method Details
#for_subject(subject, &block) ⇒ Object
15 16 17 |
# File 'lib/anony/selectors.rb', line 15 def for_subject(subject, &block) selectors[subject] = block end |
#select(subject, subject_id) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/anony/selectors.rb', line 19 def select(subject, subject_id) selector = selectors[subject] raise SelectorNotFoundException.new(subject.to_s, @model_class.name) if selector.nil? @model_class.instance_exec(subject_id, &selector) end |