README.md in inherited_class_var-0.1.0 vs README.md in inherited_class_var-0.1.1

- old
+ new

@@ -1,16 +1,16 @@ # InheritedClassVar Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/inherited_class_var`. To experiment with that code, run `bin/console` for an interactive prompt. -[![Code Climate](https://codeclimate.com/github/joel/inherited_class_var.png)](https://codeclimate.com/github/joel/inherited_class_var) +[![Code Climate](https://codeclimate.com/github/FinalCAD/inherited_class_var.png)](https://codeclimate.com/github/FinalCAD/inherited_class_var) -[![Dependency Status](https://gemnasium.com/joel/inherited_class_var.svg)](https://gemnasium.com/joel/inherited_class_var) +[![Dependency Status](https://gemnasium.com/FinalCAD/inherited_class_var.svg)](https://gemnasium.com/FinalCAD/inherited_class_var) -[![Build Status](https://travis-ci.org/joel/inherited_class_var.svg?branch=master)](https://travis-ci.org/joel/inherited_class_var) (Travis CI) +[![Build Status](https://travis-ci.org/FinalCAD/inherited_class_var.svg?branch=master)](https://travis-ci.org/FinalCAD/inherited_class_var) (Travis CI) -[![Coverage Status](https://coveralls.io/repos/joel/inherited_class_var/badge.svg?branch=master&service=github)](https://coveralls.io/github/joel/inherited_class_var?branch=master) +[![Coverage Status](https://coveralls.io/repos/FinalCAD/inherited_class_var/badge.svg?branch=master&service=github)](https://coveralls.io/github/FinalCAD/inherited_class_var?branch=master) [![Gem Version](https://badge.fury.io/rb/inherited_class_var.svg)](http://badge.fury.io/rb/inherited_class_var) ## Installation @@ -29,10 +29,61 @@ $ gem install inherited_class_var ## Usage -TODO: Write usage instructions here +You can follow this example, if you want to create Models with columns information and these informations still available after inheritance + +Create a Model module with `inherited_class_var` + +``` +require 'inherited_class_var' + +module Model + extend ActiveSupport::Concern + + included do + include InheritedClassVar + inherited_class_hash :columns + end + + module ClassMethods + + protected + + def column(column_name, options={}) + merge_columns(column_name.to_sym => options) + end + end +end +``` + +`merge_columns` it's bring by `inherited_class_var` + +``` +class ModelBase + include Model + + column :id, type: Integer +end +``` + +Gives +``` +ModelBase.columns # => {:id=>{:type=>Integer}} +``` + +``` +class UserModel < ModelBase + + column :name, type: String +end +``` + +Gives +``` +UserModel.columns # => {:id=>{:type=>Integer}, :name=>{:type=>String}} +``` ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.