module EasyApiDoc::Configurable
Public Class Methods
included(base)
click to toggle source
# File lib/configurable.rb, line 4 def self.included(base) base.class_eval do attr_accessor :name, :attributes, :parents end base.extend EasyApiDoc::Configurable::ClassMethods end
new(name, attributes, parents = {})
click to toggle source
Instance methods
# File lib/configurable.rb, line 76 def initialize(name, attributes, parents = {}) @name = name @attributes = attributes @parents = parents end
Public Instance Methods
[](key)
click to toggle source
Shortcuts
# File lib/configurable.rb, line 83 def [](key) @attributes[key] end
[]=(key, value)
click to toggle source
# File lib/configurable.rb, line 87 def []=(key, value) @attributes[key] = value end
defaults()
click to toggle source
# File lib/configurable.rb, line 43 def defaults inherited_overridable('defaults') end
inherited_overridable(attr_name, options = {:from => []})
click to toggle source
# File lib/configurable.rb, line 47 def inherited_overridable(attr_name, options = {:from => []}) if v = @attributes[attr_name] return v end if options[:from] search = options[:from].map {|s| @parents[s] } else search = @parents end search.each do |parent| if parent && v = parent.attributes[attr_name] return v end end nil end
load_children(klass, nodename = nil, options = {})
click to toggle source
# File lib/configurable.rb, line 65 def load_children(klass, nodename = nil, options = {}) ref = (nodename ? @attributes[nodename] : @attributes) || [] parents = @parents.merge(self.class.to_s.split("::").last.downcase => self) ref.map do |name, opts| next if options[:exclude] && options[:exclude].include?(name) opts = opts.merge(options[:extra_attributes]) if options[:extra_attributes] klass.new(name, opts, parents) end.compact end