Class: Statics::Model

Inherits:
Dry::Struct
  • Object
show all
Defined in:
lib/statics/model.rb

Defined Under Namespace

Modules: Types

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Statics::Model

Parameters:

  • key (Symbol)

Returns:

Raises:



19
20
21
# File 'lib/statics/model.rb', line 19

def [](key)
  new(file_contents.fetch(key.to_s) { raise KeyNotFoundError }.merge(key: key.to_sym))
end

.allStatics::Collection

Returns:



24
25
26
# File 'lib/statics/model.rb', line 24

def all
  @all ||= Collection.new(records)
end

.method_missing(method, *args, &block) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/statics/model.rb', line 28

def method_missing(method, *args, &block)
  if Collection.instance_methods.include?(method)
    all.public_send(method, *args, &block)
  else
    super
  end
end

.respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/statics/model.rb', line 36

def respond_to_missing?(method, include_private = false)
  Collection.instance_methods(false).include?(method) || super
end