Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

seed_formatter

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

seed_formatter

  • 1.1.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

SeedFormatter

SeedFormatter is a small gem I created while I was working on various projects with terrible, terrible Seed files.

Purpose

The goal of SeedFormatter is to provide some commonly required functionality to be used in Seed files.

Dependencies

SeedFormatter uses the colored gem to present output.

Example: Seed file layout

I like my seed files to follow this format:

class Seed
  class << self
    def create_categories
      # create some categories here
    end

    def create_admin_user
      # create an admin user here
    end
  end
end

Seed.create_categories
Seed.create_admin_user

I find this to be the neatest way to write Seed files.

Example: Output

SeedFormatter provides four methods of showing output:

  • message A general purpose message, generally used as a header. White by default.
  • success Indicates a seed function was successful. Green by default.
  • error Indicates a seed function has failed. Red by default.
  • spacer Just to add a single space to separate groups of functionality.

Using these functions is straight forward (if we use the above example Seed file layout):

class Seed
  class << self
    include SeedFormatter

    def create_categories
      message "Creating some categories"

      ["Sedan", "SUV", "Hatchback"].each do |category_name|
        category = Category.create :name => category_name
        if category.valid?
          success "Created #{category_name}"
        else
          error "Failed to create #{category_name}. Errors: #{category.errors.full_messages}"
        end
      end

      spacer
    end
  end
end

Example: Overriding the display of output

You can override the display of output with the following options:

  • :prefix Pass in a string to prefix the output.
  • :suffix Pass in a string to suffix the output.
  • :color Pass in a symbol representing the color your want the ouput to be. The list of acceptable colors can be found in colored gem's documentation.

So, there are three methods of customizing the output of SeedFormatter.

1: Pass in the options

success "I did it…they're all trees", {:prefix => "!!!", :suffix => "'''", :color => :magenta}

Which will yield the string !!!I did it…they're all trees''' in magenta.

2: Override the default function in your file or similarly,

3: Write your own

def success message, options={}
  options[:prefix] ||= "!!!"
  options[:suffix] ||= "'''"
  options[:color]  ||= :magenta
  output message, options
end

def my_custom_output message, options={}
  options[:prefix] ||= "> "
  options[:suffix] ||= " <"
  options[:color]  ||= :yellow
  output message, options
end

FAQs

Package last updated on 08 Jan 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc