Project

expositor

0.0
No commit activity in last 3 years
No release in over 3 years
Expose all object methods to it class
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 3.4.0, ~> 3.4
 Project Readme

Expositor

Description

Gem allow you create class methods which delegate it to objects

Installation & Setup

In console:

gem install expositor

And in your ruby file:

require 'expositor'

Example

You initiating Policy that allow you explicit some 'checks' to special policy class

class NamingPolicy

  def initialize(name)
    @name = name
  end

  def john?
    @name == 'John'
  end

  def jack?
    @name == 'Jack'
  end

  def james?
    @name == 'James'
  end
end

And now for get right answer you need do all this:

m = NamingPolicy.new('John')
m.john? #=> true
m.jack? #=> false

NamingPolicy.new('James').james? #=> true

too boring... not ruby-way...

Much more pretty if...

require 'expositor'

class NamingPolicy
  extend Expositor

  def initialize(name)
    @name = name
  end

  def john?
    @name == 'John'
  end

  def jack?
    @name == 'Jack'
  end

  def james?
    @name == 'James'
  end
end

And now you available:

NamingPolicy.john?('John') #=> true
NamingPolicy.jack('John') #=> false
NamingPolicy.max?('Max') #=> undefined method `max?'

How to use

By default it expose all public method, but you can easy handle this through expose method:

Only some methods:

class NamingPolicy
  extend Expositor

  expose only: [:john?, :jack]
  #...

NamingPolicy.john?('John') #=> true
NamingPolicy.jack('John') #=> false
NamingPolicy.james?('James') #=> undefined method `james?'

All except:

class NamingPolicy
  extend Expositor

  expose except: [:john?]
  #...

NamingPolicy.john?('John')  #=> undefined method `james?'
NamingPolicy.jack('Jack') #=> true
NamingPolicy.james?('John') #=> false

And combie:

class NamingPolicy
  extend Expositor

  expose only: [:jack, :john], except: [:john?]
  #...
NamingPolicy.john?('John')  #=> undefined method `john?'
NamingPolicy.jack('Jack') #=> true
NamingPolicy.james?('James') #=> true

TODO

  • Some improvements ? =)