Sha256: 752e1583db82d261bc81a04e76f18f7039f707a7bf8355320a119e1c39e720de

Contents?: true

Size: 790 Bytes

Versions: 7

Compression:

Stored size: 790 Bytes

Contents

module GoldenFleece
  class Context
    module Getters
      def define_getters(*attributes)
        # For each attribute...
        attributes.each do |attribute|
          # ...and each top-level schema of each attribute...
          schemas[attribute.to_sym].each do |schema_name, schema|
            # ...if there isn't already an instance method named after the schema...
            if !model_class.new.respond_to?(schema_name)
              # ...define a getter for that schema's value!
              model_class.class_eval do
                define_method schema_name do
                  self.class.fleece_context.schemas[attribute.to_sym][schema_name].value.compute(self)
                end
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
golden_fleece-1.0.0 lib/golden_fleece/context/getters.rb
golden_fleece-0.1.5 lib/golden_fleece/context/getters.rb
golden_fleece-0.1.4 lib/golden_fleece/context/getters.rb
golden_fleece-0.1.3 lib/golden_fleece/context/getters.rb
golden_fleece-0.1.2 lib/golden_fleece/context/getters.rb
golden_fleece-0.1.1 lib/golden_fleece/context/getters.rb
golden_fleece-0.1.0 lib/golden_fleece/context/getters.rb