Module: EasyApiDoc::Configurable

Included in:
Action, ApiVersion, Namespace, Parameter, Resource
Defined in:
lib/configurable.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
9
# 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

Instance Method Details

#[](key) ⇒ Object

Shortcuts



83
84
85
# File 'lib/configurable.rb', line 83

def [](key)
  @attributes[key]
end

#[]=(key, value) ⇒ Object



87
88
89
# File 'lib/configurable.rb', line 87

def []=(key, value)
  @attributes[key] = value
end

#defaultsObject



43
44
45
# File 'lib/configurable.rb', line 43

def defaults
  inherited_overridable('defaults')
end

#inherited_overridable(attr_name, options = {:from => []}) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 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

#initialize(name, attributes, parents = {}) ⇒ Object

Instance methods



76
77
78
79
80
# File 'lib/configurable.rb', line 76

def initialize(name, attributes, parents = {})
  @name = name
  @attributes = attributes
  @parents = parents
end

#load_children(klass, nodename = nil, options = {}) ⇒ Object



65
66
67
68
69
70
71
72
73
# 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