Module: Katello::LazyAccessor::ClassMethods
- Defined in:
- app/lib/katello/lazy_accessor.rb
Instance Attribute Summary collapse
-
#lazy_attributes ⇒ Object
Returns the value of attribute lazy_attributes.
Instance Method Summary collapse
Instance Attribute Details
#lazy_attributes ⇒ Object
Returns the value of attribute lazy_attributes.
9 10 11 |
# File 'app/lib/katello/lazy_accessor.rb', line 9 def lazy_attributes @lazy_attributes end |
Instance Method Details
#lazy_accessor(*args) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/lib/katello/lazy_accessor.rb', line 24 def lazy_accessor(*args) = args. @lazy_attributes = [] if @lazy_attributes.nil? @lazy_attributes.concat args @lazy_attributes_options ||= {} fail ArgumentError, "Attribute names must be symbols" if args.any? { |attribute| !attribute.is_a?(Symbol) } redefined_attr = args.find { |attribute| instance_methods.include?(attribute.to_s) } Rails.logger.warn "Remote attribute '#{redefined_attr}' has already been defined" if redefined_attr fail ArgumentError, "Please provide an initializer" if [:initializer].nil? args.each do |symbol| [:in_group] = args.size > 1 @lazy_attributes_options[symbol.to_s] = send :define_method, "#{symbol.to_s}=" do |val| lazy_attribute_set(symbol, val) end send :define_method, symbol do lazy_attribute_get(symbol) end end end |
#lazy_attributes_options(attr) ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'app/lib/katello/lazy_accessor.rb', line 11 def (attr) if @lazy_attributes_options&.key?(attr) @lazy_attributes_options.fetch(attr.to_s) elsif superclass.respond_to?(:lazy_attributes_options) superclass.(attr.to_s) else fail "lazy attribute #{attr} not defined" end end |