class Godfather::Data

Public Class Methods

new(controller, json) click to toggle source
# File lib/godfather/data.rb, line 3
def initialize(controller, json)
  @controller = controller

  return unless json
  hash = JSON.parse(json) if json.is_a?(String)
  hash = json if json.is_a?(Hash)
  @data = with_overrides(hash)
end

Public Instance Methods

records(model) click to toggle source
# File lib/godfather/data.rb, line 12
def records(model)
  model.where(@data)
end
to_h() click to toggle source
# File lib/godfather/data.rb, line 16
def to_h
  @data
end

Private Instance Methods

with_overrides(hash) click to toggle source
# File lib/godfather/data.rb, line 22
def with_overrides(hash)
  result = {}

  hash.each do |key, val|
    result[key] = @controller.send(:override!, key.to_sym, val, hash)
  end

  result
end