class RailsZen::WriteToFiles

Attributes

attr[R]
model_name[R]

Public Class Methods

new(attr, model_name) click to toggle source
# File lib/rails_zen/write_to_files.rb, line 8
def initialize(attr, model_name)
  @attr = attr
  @model_name = model_name
end

Public Instance Methods

build_file_writers(type) click to toggle source
# File lib/rails_zen/write_to_files.rb, line 13
def build_file_writers(type)
  # When including thor, could not use initialize hence building it
  Object.const_get("RailsZen::#{type}").new.tap do |w|
    w.name                  = attr.name
    w.attr_type             = attr.type
    w.scope_attr            = attr.scope_attr
    w.validator             = attr.validator
    w.type_based_validators = attr.type_based_validators
    w.model_name            = model_name
  end
end
write() click to toggle source
# File lib/rails_zen/write_to_files.rb, line 25
def write
  ["WriteToSpec", "WriteToMigration", "WriteToModel"].each do |type|
    build_file_writers(type).write!
  end
end