README.md in code-box-0.0.1 vs README.md in code-box-0.0.2
- old
+ new
@@ -4,22 +4,73 @@
## Installation
Add this line to your application's Gemfile:
- gem 'code-attr'
+ gem 'code-box'
And then execute:
$ bundle
Or install it yourself as:
- $ gem install code-attr
+ $ gem install code-box
## Usage
-TODO: Write usage instructions here
+### Specifying attributes as codes
+
+There are cases you want to store 'named codes' instead artificial keys.
+Codes make sense for stable references and better readability of the raw data.
+
+There are several options to specify an attribute as a code:
+ 1. Attribute is a code. There is no associated object involved, but simple I18n translation of the code
+ 1. Attribute is a code. There exists a code object that is looked up on access.
+ 1. Attribute is a code. There exists an AR code object that is looked up through AR association.
+
+#### Lookup through I18n
+
+Example
+
+ class Person
+ iclude CodeBox::CodeAttribute
+
+ attr_accessor :nationality_code
+ end
+
+The include will create the following methods in Person:
+
+ #nationality Will return the nationality looked up through I18n on key: 'activerecord.values.person.nationality_code.de: Germany', where de would 'de' the nationality code.
+
+
+
+#### Lookup through code object
+
+Example
+
+ class Person
+ iclude CodeBox::CodeAttribute
+
+ attr_accessor :nationality_code, :lookup_type => :lookup
+ end
+
+ class Code::Nationality
+ attr_accessor :code, :name
+
+ def lookup(code)
+ return the correct Code::Nationality for the passed code
+ end
+ end
+
+The include will create the following methods in Person:
+
+ #nationality Will return the nationality looked through lookup on the associated code object.
+
+
+#### Lookup through associated AR Code Object
+to be completed ...
+
## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)