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.
39 40 41 42 |
# File 'lib/redis_counters/dumpers/dsl/base.rb', line 39 def initialize(target, &block) @target = target instance_eval(&block) end |
Instance Attribute Details
#target ⇒ Object
Returns the value of attribute target.
11 12 13 |
# File 'lib/redis_counters/dumpers/dsl/base.rb', line 11 def target @target end |
Class Method Details
.callback_setter(*method_names) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/redis_counters/dumpers/dsl/base.rb', line 30 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
14 15 16 17 18 19 20 |
# File 'lib/redis_counters/dumpers/dsl/base.rb', line 14 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
22 23 24 25 26 27 28 |
# File 'lib/redis_counters/dumpers/dsl/base.rb', line 22 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 |