class Adminish::Model

Public Class Methods

new(model, crud = {}) click to toggle source
# File lib/adminish.rb, line 21
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 Instance Methods

class_tag(model_name) click to toggle source

used to create a specific tag to keep models organized base on a consistent tag

# File lib/adminish.rb, line 53
def class_tag(model_name)
  # upercase to lowercase
  model_name.downcase.pluralize
end
hm_readable_class(model_name) click to toggle source

generates a human readable title for the model name

# File lib/adminish.rb, line 46
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
is_white_listed(model_name) click to toggle source
# File lib/adminish.rb, line 41
def is_white_listed(model_name)
  true
end