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

kumadori

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kumadori

  • 0.8.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Kumadori

This is simple decorator for Ruby.

Kumadori mean make-up for Japanese Kabuki.

Installation

Add this line to your application's Gemfile:

gem 'kumadori'

And then execute:

$ bundle

Or install it yourself as:

$ gem install kumadori

Usage

Kumadori decorate your instance by #{instance.class}Decorator class.

#
# Basic ruby class.
#
class User
  attr_accesstor :first_name, :last_name

  def initialize(first_name, last_name)
    self.first_name = first_name
    self.last_name  = last_name
  end
end

#
# Decorator class for User instance.
#
class UserDecorator < Kumadori::BaseDecorator
  def full_name
    "#{self.last_name} #{self.first_name}"
  end
end

user = User.new('Yuji', 'Arakaki')

# user instance decorated by UserDecorator
decorated_user = Kumadori.decorate(user)

decorated_user.full_name # => "Arakaki Yuji"

if you not defined #{instance.class}Decorator class, it's instance decorated by Kumadori::BaseDecorator. So, if you want defined method for every instance, you just override Kumadori::BaseDecorator, and defined method.


class Animal
end

module Kumadori
  class BaseDecorator < ::SimpleDelegator
    def live?
      true
    end
  end
end

animal = Animal.new


# Because of AnimalDecorator class is not defiend,
# it is decorated by Kumadori::BaseDecorator
decorated_animal = Kumadori.decorate(animal)

decorated_animal.live? # => true

if you want to decorate all items in collection, use Kumadori.collection_decorate method.


members = []
members << User.new('Kanoko', 'Higa')
members << User.new('Ai', 'Kawasaki')
members << User.new('Takeo', 'Kikuchi')

decorated_members = Kumadori.collection_decorate(members)

decorated_members.map{ |user| user.full_name} # => ["Higa Kanoko", "Kawasaki Ai", "Kikuchi Takeo"]

Contributing

  1. Fork it ( https://github.com/[my-github-username]/kumadori/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

FAQs

Package last updated on 06 Feb 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