Sha256: 09d4ad4095a3deee187a1f1ffb854371c3d93376deb8813af2522dd6abcb48a3
Contents?: true
Size: 1.5 KB
Versions: 1
Compression:
Stored size: 1.5 KB
Contents
module Adminish class Admin def initialize(models=[]) @models = [] models.each do |model| @models.push(Model.new(model, { index: "/#{model.name.downcase.pluralize}/", show: "/#{model.name.downcase.pluralize}/:id", create: "/#{model.name.downcase.pluralize}/", update: "/#{model.name.downcase.pluralize}/:id", delete: "/#{model.name.downcase.pluralize}/:id" } )) end end end class Model def initialize(model, crud = {}) @title = hm_readable_class(model.name) @tag = class_tag(model.name) # if crud == {} # # generate crud stuff # # @crud = urls_for_model(model) # else @crud = crud # end @attributes = [] model.columns.each do |atr| if is_white_listed(atr.name) @attributes.push({tag: atr.name, title: atr.name.gsub("_", " "), type: atr.type}) end end puts self.to_yaml end private def is_white_listed(model_name) true end # generates a human readable title for the model name def hm_readable_class(model_name) # replace _ with spaces # replace cammal case with something readable PostIt to Post It model_name.gsub("_", " ").gsub(/(?<=[a-z])(?=[A-Z])/, ' ') end # used to create a specific tag to keep models organized base on a consistent tag def class_tag(model_name) # upercase to lowercase model_name.downcase.pluralize end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
adminish-0.0.1 | lib/adminish.rb |