Sha256: aff8c7a281e4e80cc109cd7017270cb2f37821678c15c5066efbfb379ed95606
Contents?: true
Size: 1.9 KB
Versions: 1
Compression:
Stored size: 1.9 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 default_options.deep_merge custom_options end def default_options @defaults ||= begin options = load_yaml_file File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "config", "x-editable.yml")) format_class_options! options end end def custom_options @custom_options ||= begin options = load_yaml_file ::Rails.root.join("config", "x-editable.yml") format_class_options! 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
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
x-editable-rails-1.5.0 | lib/x-editable-rails/configuration.rb |