Sha256: 5928356177b9b576ff8872899b39f62cbe454e02f3c95f4f1bb8f7d53fc1ee24
Contents?: true
Size: 1.8 KB
Versions: 2
Compression:
Stored size: 1.8 KB
Contents
require "active_export/version" require 'active_export/configuration' require 'yaml' require 'erb' module ActiveExport autoload :Base, 'active_export/base' autoload :Csv, 'active_export/csv' class << self # @example # ActiveExportconfigure do |config| # # ActiveExport export configuration files. # config.sources = { default: Rails.root.join('config', 'active_export.yml') } # # # see CSV.new options # config.default_csv_optoins = { col_sep: ',', row_sep: "\n", force_quotes: true } # # # if set 'true', ActiveExport no cached yml data. Every time load yml file. # # if set 'false', ActiveExport cached yml data. # config.always_reload = true # default false # # # if set 'true', not found sources[:source_name] to raise error # config.no_source_raise_error = false # default # end def configure yield configuration end # Accessor for ActiveExport::Configuration def configuration @configuration ||= Configuration.new end alias :config :configuration def [](key) source(key) end def clear! @source = {} true end def load! config.sources.each {|f| source(f) } true end def reload! clear! load! end def source(key) if @configuration.always_reload load!(key) else @sources ||= {} @sources[key] ||= load!(key) end end def include_source?(key) @configuration.sources.has_key?(key) end def load!(key) if include_source?(key) ::ActiveSupport::HashWithIndifferentAccess.new(YAML.load(ERB.new(open(@configuration.sources[key]).read).result).to_hash) else raise "Missing '#{key}' in sources" end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
active_export-0.2.0 | lib/active_export.rb |
active_export-0.1.0 | lib/active_export.rb |