Class: Godwit::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/godwit/config.rb

Overview

Application configuration.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



11
12
13
# File 'lib/godwit/config.rb', line 11

def configuration
  @configuration
end

Class Method Details

.[](key) ⇒ Object

Returns the config value at the specified key.



44
45
46
# File 'lib/godwit/config.rb', line 44

def [](key)
  (@configuration||={})[key]
end

.[]=(key, val) ⇒ Object

Set the config value at the specified key.



50
51
52
# File 'lib/godwit/config.rb', line 50

def []=(key,val)
  @configuration[key] = val
end

.defaultsObject

Default configuration details.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/godwit/config.rb', line 14

def defaults
  @defaults ||= {
    :godwit_root                => Dir.pwd,
    :active_record_log          => nil,
    :active_record_log_level    => nil,
    :active_migration_log       => nil,
    :active_migration_log_level => nil,
    :rails_root                 => nil,
    :key_mapper_path            => File.join(Dir.pwd, 'data', 'keymaps'),
    :skip_dependencies          => false,
    :skip_migrations            => [],
    :specific_migration         => nil,
    :silence                    => false,
    :debug                      => false
  }
end

.delete(key) ⇒ Object

Deletes the config element by key.



56
57
58
# File 'lib/godwit/config.rb', line 56

def delete(key)
  @configuration.delete(key)
end

.parse_args(argv = ARGV) ⇒ Object

Parses command line arguments and stores them in the config.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/godwit/config.rb', line 73

def parse_args(argv = ARGV)
  options = {}
  opts = OptionParser.new do |opts|

    opts.program_name = "Godwit"
    opts.version = Godwit::VERSION::STRING
    opts.banner  = "Usage: migrate [OPTIONS]\n"
    opts.separator ""

    opts.on("-D", "--debug", "Debug mode.") do |n|
      options[:debug] = true
    end

    opts.on("-s", "--silent", "Silence, no output, good for scripts. Silence overrides Debug(you can't debug silently)") do |n|
      options[:silence] = true
    end

    opts.on("-m", "--skip-migrations X,Y,Z", Array, "Use underscores. Won't skip it if it's a dependency, make sure you use -d too if you need that.") do |migrations|
      options[:skip_migrations] = migrations
    end

    opts.on("-d", "--skip-dependencies", "Skip Dependencies") do |n|
      options[:skip_dependencies] = true
    end

    opts.on("-S", "--specific-migration MIGRATION", "Specific Migration. Use underscores. Ex. products_migration.") do |migration|
      options[:specific_migration] = migration
    end

    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end

    opts.on_tail("-v", "--version", "Show version") do
      puts 'Godwit ' + Godwit::VERSION::STRING
      exit
    end

  end
  opts.parse!(argv)
  Godwit::Config.setup(options)
end

.setup(settings = {}) ⇒ Object

Sets up the configuration by storing the given settings.



62
63
64
65
66
67
68
69
# File 'lib/godwit/config.rb', line 62

def setup(settings = {})
  @configuration ||= {}
  if @configuration == {}
    @configuration = defaults.merge(settings)
  else
    @configuration.merge!(settings)
  end
end

.use {|@configuration| ... } ⇒ Object

Yields the configuration.

Godwit::Config.use do |config|
  config[:keymapper_path] = 'some/other/path'
end

Yields:



37
38
39
40
# File 'lib/godwit/config.rb', line 37

def use
  @configuration ||= {}
  yield @configuration
end