Module: RubyLokaliseApi::Concerns::AttrsLoadable

Included in:
RubyLokaliseApi::Collections::Base, Resources::Base
Defined in:
lib/ruby_lokalise_api/concerns/attrs_loadable.rb

Overview

Allows to set supported attributes for classes

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(klass) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/ruby_lokalise_api/concerns/attrs_loadable.rb', line 8

def extended(klass)
  klass.class_exec do
    define_method :supported_attrs do
      that_klass = self.class
      that_klass.const_defined?(:ATTRS) ? that_klass.const_get(:ATTRS) : []
    end
  end
end

Instance Method Details

#inherited(subclass) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ruby_lokalise_api/concerns/attrs_loadable.rb', line 18

def inherited(subclass)
  klass_attributes = attributes_for subclass, const_get(:ATTRS_FILENAME)

  if klass_attributes&.any?
    subclass.class_exec do
      const_set :ATTRS, klass_attributes
      attr_reader(*klass_attributes)
    end
  end

  super
end