Class: IronAdmin::Adapters::Http::ModelProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/iron_admin/adapters/http/model_proxy.rb

Overview

Lightweight stand-in for a Ruby model class when a Resource uses the HTTP adapter. The HTTP adapter pulls fields from the remote API at request time, so there's no Ruby model to introspect — but Resource.adapter still needs an object that responds to the minimal ActiveModel::Naming interface (.model_name.plural, .model_name.human) so URLs and labels work.

The proxy is built from the resource class name: IronAdmin::Resources::ExternalCustomerResourcemodel_name.plural = "external_customers", model_name.human = "External customer".

Examples:

IronAdmin::Adapters::Http::ModelProxy.new(MyResource).model_name.plural
#=> "my_resources"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource_class) ⇒ ModelProxy

Returns a new instance of ModelProxy.

Parameters:

  • resource_class (Class)

    The IronAdmin::Resource subclass.



28
29
30
# File 'lib/iron_admin/adapters/http/model_proxy.rb', line 28

def initialize(resource_class)
  @resource_class = resource_class
end

Instance Attribute Details

#resource_classClass (readonly)

Returns The Resource class this proxy stands in for.

Returns:

  • (Class)

    The Resource class this proxy stands in for.



25
26
27
# File 'lib/iron_admin/adapters/http/model_proxy.rb', line 25

def resource_class
  @resource_class
end

Instance Method Details

#column_namesArray<String>

HTTP resources have no Ruby-side schema; columns are discovered from the first API response. Return an empty list so any column-introspection checks (e.g. soft-delete detection) decide the column is absent rather than crashing.

Returns:

  • (Array<String>)


46
47
48
# File 'lib/iron_admin/adapters/http/model_proxy.rb', line 46

def column_names
  []
end

#model_nameActiveModel::Name

ActiveModel::Naming-compatible name object derived from the resource class name.

Returns:

  • (ActiveModel::Name)


36
37
38
# File 'lib/iron_admin/adapters/http/model_proxy.rb', line 36

def model_name
  @model_name ||= ActiveModel::Name.new(self, nil, demodulized_name)
end

#nameString Also known as: to_s

Mirror Class#name so anything logging the model class doesn't show #<Adapters::Http::ModelProxy:0x...>.

Returns:

  • (String)


54
55
56
# File 'lib/iron_admin/adapters/http/model_proxy.rb', line 54

def name
  demodulized_name
end