Class: APIQL::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/apiql.rb

Instance Method Summary collapse

Constructor Details

#initialize(binder, *fields) ⇒ Context

Returns a new instance of Context.



239
240
241
242
243
244
245
246
# File 'lib/apiql.rb', line 239

def initialize(binder, *fields)
  fields.each do |field|
    instance_variable_set("@#{field}", binder.send(field))
    class_eval do
      attr_accessor field
    end
  end
end

Instance Method Details

#parse_params(list) ⇒ Object



248
249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/apiql.rb', line 248

def parse_params(list)
  list&.split(',')&.map(&:strip)&.map do |name|
    if reg = name.match(/\A[a-zA-Z]\w*\z/)
      params[name]
    else
      begin
        Float(name)
      rescue
        name
      end
    end
  end
end

#render_value(value, schema) ⇒ Object



262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'lib/apiql.rb', line 262

def render_value(value, schema)
  if value.is_a? Hash
    HashEntity.new(value, self).render(schema)
  elsif value.respond_to?(:each) && value.respond_to?(:map)
    value.map do |object|
      "#{object.class.name}::Entity".constantize.new(object, self).render(schema)
    end
  elsif APIQL::simple_class?(value)
    value
  else
    "#{value.class.name}::Entity".constantize.new(value, self).render(schema)
  end
end