README.md in anchormodel-0.0.2 vs README.md in anchormodel-0.1.0

- old
+ new

@@ -1,5 +1,7 @@ +<img src="logo.svg" height=250 alt="Anchormodel logo"/> + # Introducing Anchormodel This gem provides a simple but powerful alternative to [Rails Enums](https://api.rubyonrails.org/v7.0/classes/ActiveRecord/Enum.html). In contrast to regular Enums, Anchormodels can hold application logic, making them @@ -45,17 +47,20 @@ # Example `app/anchormodels/role.rb`: ```ruby -class Anchormodels::Role < Anchormodel +class Role < Anchormodel + # Make <, > etc. based on <=> operator whic hwe will define below + include Comparable + # Expose the attribute privilege_level attr_reader :privilege_level - # Overload <=> to make user roles comparable based on the privilege level + # Define <=> to make user roles comparable based on the privilege level def <=>(other) - other.privilege_level <=> @privilege_level + @privilege_level <=> other.privilege_level end # Declare all available roles new :guest, privilege_level: 0 new :manager, privilege_level: 1 @@ -74,13 +79,13 @@ You may now use the following methods: ```ruby # Retrieve all user roles: -Anchormodels::Role.all +Role.all # Retrieve a specific role from the String and find its privilege level -Anchormodels::Role.find(:guest).privilege_level +Role.find(:guest).privilege_level # Implement a Rails helper that makes sure users can only edit other users that have a lower privilege level than themselves def user_can_edit?(this_user, other_user) this_user.role.privilege_level > other_user.role.privilege_level end \ No newline at end of file