Sha256: 273e05203a206dc67af0aee761deb085888f24a45779404b6ff9ae9a80a3933c

Contents?: true

Size: 1.99 KB

Versions: 25

Compression:

Stored size: 1.99 KB

Contents

module Exlibris
  module Primo
    module WebService
      module Request
        module BaseElements
          def self.included(klass)
            klass.class_eval do
              extend ClassAttributes
            end
          end

          module ClassAttributes
            def base_elements
              @base_elements ||= self.superclass.respond_to?(:base_elements) ?
                self.superclass.base_elements.dup : []
            end

            def add_base_elements *elements
              elements.each do |element|
                base_elements << element unless base_elements.include? element
              end
            end
            protected :add_base_elements

            def remove_base_elements *elements
              base_elements.delete_if do |element|
                elements.include? element
              end
            end
            protected :remove_base_elements
          end

          def base_elements
            @base_element ||= self.class.base_elements
          end
          protected :base_elements

          def base_elements_xml
            (base_elements.collect { |opt|
              value = send(opt)
              name = opt.id2name.camelize(:lower)
              build_xml do |xml|
                xml.send(name, value) unless value.nil?
              end
            }).join
          end
          protected :base_elements_xml

          #
          # Dynamically sets attr_accessors for base_elements
          #
          def method_missing(method, *args, &block)
            if base_elements.include?(attributize(method))
              self.class.send :attr_accessor, attributize(method)
              send method, *args, &block
            else
              super
            end
          end

          #
          # Tell users that we respond to base elements accessors.
          #
          def respond_to?(method, include_private = false)
            (base_elements.include?(attributize method)) ? true : super
          end
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
exlibris-primo-2.1.1 lib/exlibris/primo/web_service/request/base/base_elements.rb
exlibris-primo-2.1.0 lib/exlibris/primo/web_service/request/base/base_elements.rb
exlibris-primo-2.0.0 lib/exlibris/primo/web_service/request/base/base_elements.rb
exlibris-primo-1.1.9 lib/exlibris/primo/web_service/request/base/base_elements.rb
exlibris-primo-1.1.8 lib/exlibris/primo/web_service/request/base/base_elements.rb
exlibris-primo-1.1.7 lib/exlibris/primo/web_service/request/base/base_elements.rb
exlibris-primo-1.1.6 lib/exlibris/primo/web_service/request/base/base_elements.rb
exlibris-primo-1.1.5 lib/exlibris/primo/web_service/request/base/base_elements.rb
exlibris-primo-1.1.4 lib/exlibris/primo/web_service/request/base/base_elements.rb
exlibris-primo-1.1.3 lib/exlibris/primo/web_service/request/base/base_elements.rb
exlibris-primo-1.1.2 lib/exlibris/primo/web_service/request/base/base_elements.rb
exlibris-primo-1.1.1 lib/exlibris/primo/web_service/request/base/base_elements.rb
exlibris-primo-1.1.0 lib/exlibris/primo/web_service/request/base/base_elements.rb
exlibris-primo-1.0.11 lib/exlibris/primo/web_service/request/base/base_elements.rb
exlibris-primo-1.0.10 lib/exlibris/primo/web_service/request/base/base_elements.rb
exlibris-primo-1.0.9 lib/exlibris/primo/web_service/request/base/base_elements.rb
exlibris-primo-1.0.8 lib/exlibris/primo/web_service/request/base/base_elements.rb
exlibris-primo-1.0.7 lib/exlibris/primo/web_service/request/base/base_elements.rb
exlibris-primo-1.0.6 lib/exlibris/primo/web_service/request/base/base_elements.rb
exlibris-primo-1.0.5 lib/exlibris/primo/web_service/request/base/base_elements.rb