Class: EgovUtils::Love

Inherits:
ActiveResource::Base
  • Object
show all
Defined in:
app/resources/egov_utils/love.rb

Direct Known Subclasses

LegalForm, Organization

Class Method Summary collapse

Class Method Details

.configObject



45
46
47
48
# File 'app/resources/egov_utils/love.rb', line 45

def self.config
  file = Rails.root.join('config', 'config.yml')
  File.exist?(file) ? YAML.load_file(file) : {}
end

.inherited(subclass) ⇒ Object

mocking



62
63
64
# File 'app/resources/egov_utils/love.rb', line 62

def self.inherited(subclass)
  mock_subclass(subclass) if @mocking
end

.mock!Object



70
71
72
73
74
75
# File 'app/resources/egov_utils/love.rb', line 70

def self.mock!
  @mocking = true
  EgovUtils::Love.subclasses.each do |cls|
    mock_subclass(cls)
  end
end

.mock_subclass(subclass) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'app/resources/egov_utils/love.rb', line 77

def self.mock_subclass(subclass)
  mock_cls = "#{subclass.name}Mock".safe_constantize
  return unless mock_cls
  mocked_classes[subclass.name] = subclass
  namespaces = subclass.name.split('::')
  namespace = (namespaces[0..-2].join('::').presence || 'Object').safe_constantize
  namespace.send(:remove_const, namespaces[-1])
  namespace.const_set(namespaces[-1], mock_cls)
end

.mocked_classesObject



66
67
68
# File 'app/resources/egov_utils/love.rb', line 66

def self.mocked_classes
  @mocked_classes ||= {}
end

.where(clauses = {}) ⇒ Object

Raises:

  • (ArgumentError)


54
55
56
57
# File 'app/resources/egov_utils/love.rb', line 54

def self.where(clauses = {})
  raise ArgumentError, "expected a clauses Hash, got #{clauses.inspect}" unless clauses.is_a? Hash
  find(:all, params: {f: clauses})
end