Class: Quik::OpenConfig
- Inherits:
-
Object
- Object
- Quik::OpenConfig
- Defined in:
- lib/quik/config.rb
Overview
c.quik.last_updated = Time.now
c.quik.title = 'title'
c.quik.name = 'name'
c.quik.theme = 'theme'
Instance Method Summary collapse
-
#initialize ⇒ OpenConfig
constructor
A new instance of OpenConfig.
- #method_missing(m, *args, &block) ⇒ Object
- #to_h ⇒ Object
Constructor Details
#initialize ⇒ OpenConfig
Returns a new instance of OpenConfig.
22 23 24 |
# File 'lib/quik/config.rb', line 22 def initialize @h = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/quik/config.rb', line 38 def method_missing( m, *args, &block) if m.to_s =~ /^(.*)=$/ ## setter puts "config lookup (setter) >#{m}< #{m.class.name}, #{args.inspect}" key = m[0..-2].to_s ## cut off trailing = @h[ key ] = args[0].to_s # note: assume first arg is value for setter # note: for now all values are strings (always use to_s) else ## assume getter ## fix: add check for args?? must be 0 for getters?? ## use else super to delegate non-getters?? puts "config lookup (getter) >#{m}< #{m.class.name}" key = m.to_s value = @h[ key ] if value.nil? puts " config add (nested) hash" value = @h[ key ] = OpenConfig.new end value end end |
Instance Method Details
#to_h ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/quik/config.rb', line 26 def to_h h = {} @h.each do |k,v| if v.is_a? OpenConfig h[ k ] = v.to_h else h[ k ] = v ## just pass along as is end end h end |