Module: Rails::Surrender::ModelAdditions::ClassMethods

Defined in:
lib/rails/surrender/model_additions.rb

Instance Method Summary collapse

Instance Method Details

#surrender_attributesObject



33
34
35
# File 'lib/rails/surrender/model_additions.rb', line 33

def surrender_attributes
  @surrender_attributes ||= %i[id created_at]
end

#surrender_available_attributesObject



37
38
39
# File 'lib/rails/surrender/model_additions.rb', line 37

def surrender_available_attributes
  @surrender_available_attributes ||= []
end

#surrender_available_expandsObject



45
46
47
# File 'lib/rails/surrender/model_additions.rb', line 45

def surrender_available_expands
  @surrender_available_expands ||= []
end

#surrender_callable_attributesObject



49
50
51
# File 'lib/rails/surrender/model_additions.rb', line 49

def surrender_callable_attributes
  @surrender_callable_attributes ||= (surrender_attributes + surrender_available_attributes).flatten
end

#surrender_callable_expandsObject



53
54
55
# File 'lib/rails/surrender/model_additions.rb', line 53

def surrender_callable_expands
  @surrender_callable_expands ||= (surrender_expands + surrender_available_expands).flatten
end

#surrender_expandsObject



41
42
43
# File 'lib/rails/surrender/model_additions.rb', line 41

def surrender_expands
  @surrender_expands ||= []
end

#surrenders(*args) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rails/surrender/model_additions.rb', line 17

def surrenders(*args)
  directives = args.extract_options!

  # Run through the various lists of attributes and assign them to the rendering context
  # If the superclass has attributes then consume those as well.
  %w[attributes expands available_attributes available_expands].each do |directive|
    surrender_directive = "surrender_#{directive}"
    list = []
    if superclass.instance_variable_defined?("@#{surrender_directive}")
      list << superclass.instance_variable_get("@#{surrender_directive}")
    end
    list << directives[directive.to_sym] if directives.key?(directive.to_sym)
    instance_variable_set("@#{surrender_directive}", list.flatten.uniq)
  end
end