Sha256: 03f2d64814a08b8c22efa0705eaa1a8fc10fa7068233c767ddc482d1034cddd5
Contents?: true
Size: 1.66 KB
Versions: 7
Compression:
Stored size: 1.66 KB
Contents
module X module Editable module Rails module Configuration def method_options_for(object, method) class_options_for(object).fetch(method, {}) end def class_options_for(object) class_options = options.fetch(:class_options, {}) class_options.fetch(object.class.name, {}) end def class_options options.fetch(:class_options, {}) end def options config_fn = ::Rails.root.join("config", "x-editable.yml") if File.file?(config_fn) @options ||= begin options = load_yaml_file config_fn format_class_options! options end else @options = {} end end def load_yaml_file(path) source = File.read path source = ERB.new(source).result result = YAML.load(source) result = {} if result.blank? result.with_indifferent_access end private # if the specified options are a string, convert to Hash and make the string the title def format_class_options!(options) if class_options = options[:class_options] class_options.each do |class_name, methods| methods.each do |method, method_options| unless method_options.is_a? Hash methods[method] = { title: method_options }.with_indifferent_access end end end end options end extend self end end end end
Version data entries
7 entries across 7 versions & 2 rubygems