Project

groupy

0.0
No commit activity in last 3 years
No release in over 3 years
Categorise Active Records in nested groups with magical scopes, ? methods, and constants.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

 Project Readme

Groupy Build Status

Categorise records into nested groups of values.

Example

Define our groups

class Food
  property :dish, String

  include Groupy
  groupy :dish do
    group :healthy do
      group :fruit do
        value :apple
        value :orange
      end
      value :rice
    end

    group :unhealthy do
      value :fried_egg
      value :bacon
    end
  end
end

We can then ask a particular food:

apple.healthy?
apple.fruit?
apple.apple?

And we can scope the class by any of these groups

Food.apples.count
Food.fruits.all

We also get a magic "all_" method

Food.all_dishes

You can also tell groupy to add the column name as a suffix

class Something
  groupy :size, :suffix => true do
    value :small
    value :medium
    value :large
  end
end

something.small_size?

Or you may want to store all the values as a conveniently named constant.

class Something
  groupy :size, :constants => true do
    value :small
    value :medium
    value :large
  end
end

Something::SMALL
Something::MEDIUM
Something::LARGE

Or of course you can do both together

Something::SMALL_SIZE
Something::MEDIUM_SIZE
Something::LARGE_SIZE

Any values will be lowercased and underscored

class Something
  groupy :type do
    value :SomeClass
    value :"Namespace::KlassName"
  end
end

something.some_class?
something.namespace_klass_name? 

B00m!

Copyright (c) 2010 [Matthew Rudy Jacobs], released under the MIT license