Sha256: acb83294583fef6d93e4465d4c4152e982da57b06211e34f102c38847c42b25c

Contents?: true

Size: 595 Bytes

Versions: 3

Compression:

Stored size: 595 Bytes

Contents

module Prezzo
  module Composable
    def self.included(base)
      base.class_eval do
        base.extend(ClassMethods)
      end
    end

    module ClassMethods
      def composed_by(options)
        options.each do |name, klass|
          components << name

          define_method(name) do
            cached_components[name] ||= klass.new(context)

            cached_components[name].calculate
          end
        end
      end

      def components
        @components ||= []
      end
    end

    private

    def cached_components
      @cached_components ||= {}
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
prezzo-0.5.1 lib/prezzo/composable.rb
prezzo-0.5.0 lib/prezzo/composable.rb
prezzo-0.4.1 lib/prezzo/composable.rb