Sha256: 8b902ca21e69e7f6d75527dd245f11254d69391bbf14e0bad1b2117feae77255

Contents?: true

Size: 807 Bytes

Versions: 4

Compression:

Stored size: 807 Bytes

Contents

module Cistern::Singular
  def self.service_singular(service, klass, name)
    service.const_get(:Collections).module_eval <<-EOS, __FILE__, __LINE__
      def #{name}(attributes={})
        #{klass.name}.new(attributes.merge(service: self))
      end
    EOS
  end

  def self.included(klass)
    klass.send(:extend, Cistern::Attributes::ClassMethods)
    klass.send(:include, Cistern::Attributes::InstanceMethods)
    klass.send(:extend, Cistern::Model::ClassMethods)
  end

  attr_accessor :service

  def inspect
    Cistern.formatter.call(self)
  end

  def initialize(options)
    merge_attributes(options)
    reload
  end

  def reload
    new_attributes = fetch_attributes

    merge_attributes(new_attributes) if new_attributes
  end

  def fetch_attributes
    fail NotImplementedError
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cistern-2.2.7 lib/cistern/singular.rb
cistern-2.2.6 lib/cistern/singular.rb
cistern-2.2.5 lib/cistern/singular.rb
cistern-2.2.4 lib/cistern/singular.rb