Sha256: ceafc3279bc983f5c5f74f85bdfc0c41c879393d391fff28e7daa39a5849db2f

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

#!/usr/bin/env ruby

require "bundler/setup"
require "usable"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start

module VersionMixin
  def save_version
    "Saving up to #{self.class.usable_config.max_versions} versions to #{self.class.usable_config.table_name}"
  end

  def destroy_version
    "Deleting versions from #{self.class.usable_config.table_name}"
  end
end

module Mixin
  def name
    "defined by Mixin"
  end

  def from_mixin
    "always here"
  end

  # @description Usable will apply the :only to just the methods defined by this module
  module UsableSpec
    def from_spec
      "can be excluded"
    end

    def name
      "defined by UsableSpec"
    end
  end
end

class Model
  extend Usable

  usable VersionMixin, only: :save_version do |config|
    config.max_versions = 10
    config.table_name = 'custom_versions'
  end

  def save
    self.class.usable_method(self, :save_version).call
  end
end

module PersistenceOverride
  def save
    'nope'
  end
end

class Example
  extend Usable
  usable Mixin, only: [:name, :from_spec]
end

Model.usable PersistenceOverride, method: 'prepend'

require "irb"

IRB.start

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
usable-1.3.0 bin/console