Class: RedisCounters::Dumpers::Dsl::Base
- Inherits:
-
Object
- Object
- RedisCounters::Dumpers::Dsl::Base
- Defined in:
- lib/redis_counters/dumpers/dsl/base.rb
Overview
Базовый класс для создания DSL к другим классам. Класс обертка, который имеет все свойства, включая callbacks, который просто настраивает целевой класс через его стандартные свойства. Профит в простоте реализации DSL, в его изоляции от основного класса, в разделении логики основного класса и DSL к нему.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#target ⇒ Object
Returns the value of attribute target.
Class Method Summary collapse
- .callback_setter(*method_names) ⇒ Object
- .setter(*method_names) ⇒ Object
- .varags_setter(*method_names) ⇒ Object
Instance Method Summary collapse
-
#initialize(target, &block) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(target, &block) ⇒ Base
Returns a new instance of Base.
38 39 40 41 |
# File 'lib/redis_counters/dumpers/dsl/base.rb', line 38 def initialize(target, &block) @target = target instance_eval(&block) end |
Instance Attribute Details
#target ⇒ Object
Returns the value of attribute target.
10 11 12 |
# File 'lib/redis_counters/dumpers/dsl/base.rb', line 10 def target @target end |
Class Method Details
.callback_setter(*method_names) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/redis_counters/dumpers/dsl/base.rb', line 29 def callback_setter(*method_names) method_names.each do |name| send :define_method, name do |method = nil, &block| target.send "#{name}=".to_sym, method, &block end end end |
.setter(*method_names) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/redis_counters/dumpers/dsl/base.rb', line 13 def setter(*method_names) method_names.each do |name| send :define_method, name do |data| target.send "#{name}=".to_sym, data end end end |
.varags_setter(*method_names) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/redis_counters/dumpers/dsl/base.rb', line 21 def varags_setter(*method_names) method_names.each do |name| send :define_method, name do |*data| target.send "#{name}=".to_sym, data.flatten end end end |