Class: Bidi2pdfRails::Configurable::BaseNestedConfig
- Inherits:
-
Object
- Object
- Bidi2pdfRails::Configurable::BaseNestedConfig
- Defined in:
- lib/bidi2pdf_rails/configurable.rb
Instance Method Summary collapse
- #config_options ⇒ Object
- #configure {|_self| ... } ⇒ Object
- #define_accessors! ⇒ Object
-
#initialize(option_defs) ⇒ BaseNestedConfig
constructor
A new instance of BaseNestedConfig.
- #inspect ⇒ Object
- #reset_to_defaults! ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize(option_defs) ⇒ BaseNestedConfig
Returns a new instance of BaseNestedConfig.
13 14 15 16 17 |
# File 'lib/bidi2pdf_rails/configurable.rb', line 13 def initialize(option_defs) @__options = option_defs define_accessors! reset_to_defaults! end |
Instance Method Details
#config_options ⇒ Object
42 43 44 |
# File 'lib/bidi2pdf_rails/configurable.rb', line 42 def @__options end |
#configure {|_self| ... } ⇒ Object
46 47 48 |
# File 'lib/bidi2pdf_rails/configurable.rb', line 46 def configure yield self if block_given? end |
#define_accessors! ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/bidi2pdf_rails/configurable.rb', line 19 def define_accessors! @__options.each do |opt| name = opt[:name] unless respond_to?(name) define_singleton_method(name) { instance_variable_get("@#{name}") } define_singleton_method("#{name}=") { |v| instance_variable_set("@#{name}", v) } define_singleton_method("#{name}_value") do |*args| value = send("#{name}") value.respond_to?(:call) ? value.call(*args) : value end end end end |
#inspect ⇒ Object
56 57 58 |
# File 'lib/bidi2pdf_rails/configurable.rb', line 56 def inspect "#<#{self.class.name || "ConfigSection"} #{to_h.inspect}>" end |
#reset_to_defaults! ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/bidi2pdf_rails/configurable.rb', line 34 def reset_to_defaults! @__options.each do |opt| default = opt[:default] value = default send("#{opt[:name]}=", value) end end |
#to_h ⇒ Object
50 51 52 53 54 |
# File 'lib/bidi2pdf_rails/configurable.rb', line 50 def to_h @__options.to_h do |opt| [opt[:name], send(opt[:name])] end end |