Class: Restful::Rails::ActiveRecord::Configuration::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/restful/rails/active_record/configuration.rb

Overview

configures what attributes are exposed to the api. for a single resource.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*fields) ⇒ Config

set; eg :name, :pets => [:name, :species]



116
117
118
# File 'lib/restful/rails/active_record/configuration.rb', line 116

def initialize(*fields) # set; eg :name, :pets => [:name, :species]
  @whitelisted, @restful_options = split_into_whitelist_and_restful_options([fields].flatten.compact)
end

Instance Attribute Details

#restful_optionsObject

Returns the value of attribute restful_options.



114
115
116
# File 'lib/restful/rails/active_record/configuration.rb', line 114

def restful_options
  @restful_options
end

#whitelistedObject

Returns the value of attribute whitelisted.



114
115
116
# File 'lib/restful/rails/active_record/configuration.rb', line 114

def whitelisted
  @whitelisted
end

Instance Method Details

#expanded?(key, nested = false) ⇒ Boolean

if nothing was set, this defaults to true.

Returns:

  • (Boolean)


124
125
126
# File 'lib/restful/rails/active_record/configuration.rb', line 124

def expanded?(key, nested = false) # if nothing was set, this defaults to true. 
  force_expanded?(key) || (@restful_options[:expansion] != :collapsed && !nested)
end

#force_expanded?(key) ⇒ Boolean

Returns:

  • (Boolean)


128
129
130
131
# File 'lib/restful/rails/active_record/configuration.rb', line 128

def force_expanded?(key)
  force = [*@restful_options[:force_expand]]
  force.include?(key)
end

#nested(key) ⇒ Object



137
138
139
140
# File 'lib/restful/rails/active_record/configuration.rb', line 137

def nested(key)
  definition = @whitelisted.select { |field| field.is_a?(Hash)  && field.keys.include?(key) }.first
  Config.new((definition[key] if definition))
end

#nested?Boolean

Returns:

  • (Boolean)


133
134
135
# File 'lib/restful/rails/active_record/configuration.rb', line 133

def nested?
  !!restful_options[:nested]
end

#published?(key) ⇒ Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/restful/rails/active_record/configuration.rb', line 120

def published?(key)
  @whitelisted.include?(key) || !!@whitelisted.select { |field| field.is_a?(Hash)  && field.keys.include?(key) }.first
end