Identitee
Provides methods for building and retrieving instances of a class. Identify is intended to replace persisting data that is tightly tied to domain logic.
Many times you might see a database structure that will always remain static until the codebase changes. This is a headache to seed the proper data for the objects to work. Instead use identify to write these classes in code.
Likewise, many classes may be constructed that do the same thing... just a little bit differently. Like a use case. Identitee allows easy retrieval of data.
Finding
Find an identifiable through the find_identifiable
(aliased also to find) class method. (See the Basic Example)
class Activity
include Identitee
attr_reader :title
def titled title
@title = title
end
end
Activity.identify :new_activity do
titled "Created something new"
end
Activity.find_identifiable(:new_activity).title # => "Created something new"
Activity.find(:new_activity).title # => "Created something new"
Loading identifiables
Identitee will try to autoload the identifiables if it doesn't already know about them. By default it will use the pluralize class_name of the identifiable from the folder that the source file is in. The load path can explicitly be set with the set_identitee_root
method call.
class LazyLoadingTest
include Identitee
attr_accessor :successful
set_identitee_root File.("../lazy_loading_tests/", __FILE__)
def initialize
@successful = false
end
def successful?
@successful
end
end
Installation
Add this line to your application's Gemfile:
gem 'identitee'
And then execute:
$ bundle
Or install it yourself as:
$ gem install identify
Contributing
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request