Sha256: 4208907718cd06335031cbce0a42f974290351444a71a166530c837095968c09

Contents?: true

Size: 790 Bytes

Versions: 1

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.method_defined?(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

1 entries across 1 versions & 1 rubygems

Version Path
golden_fleece-1.0.1 lib/golden_fleece/context/getters.rb