Class: Utils::ConfigFile::BlockConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/utils/config_file.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ BlockConfig

Returns a new instance of BlockConfig.



61
62
63
# File 'lib/utils/config_file.rb', line 61

def initialize(&block)
  block and instance_eval(&block)
end

Class Attribute Details

.config_settingsObject

Returns the value of attribute config_settings.



58
59
60
# File 'lib/utils/config_file.rb', line 58

def config_settings
  @config_settings
end

Class Method Details

.config(name, *r, &block) ⇒ Object



51
52
53
54
55
56
# File 'lib/utils/config_file.rb', line 51

def config(name, *r, &block)
  self.config_settings ||= []
  config_settings << name.to_sym
  dsl_accessor name, *r, &block
  self
end

.inherited(modul) ⇒ Object



46
47
48
49
# File 'lib/utils/config_file.rb', line 46

def inherited(modul)
  modul.extend DSLKit::DSLAccessor
  super
end

Instance Method Details

#to_ruby(depth = 0) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/utils/config_file.rb', line 65

def to_ruby(depth = 0)
  result = ''
  result << ' ' * 2 * depth <<
    "#{self.class.name[/::([^:]+)\z/, 1].underscore} do\n"
  for name in self.class.config_settings
    value = __send__(name)
    if value.respond_to?(:to_ruby)
      result << ' ' * 2 * (depth + 1) << value.to_ruby(depth + 1)
    else
      result << ' ' * 2 * (depth + 1) <<
        "#{name} #{Array(value).map(&:inspect) * ', '}\n"
    end
  end
  result << ' ' * 2 * depth << "end\n"
end