Module: Inkwell::Common
- Included in:
- ActsAsInkwellCategory::ClassMethods, ActsAsInkwellCategory::InstanceMethods, ActsAsInkwellCommunity::InstanceMethods, ActsAsInkwellUser::InstanceMethods, Comment
- Defined in:
- lib/common/base.rb
Instance Method Summary collapse
- #category_class ⇒ Object
- #check_post(obj) ⇒ Object
- #check_user(obj) ⇒ Object
- #community_class ⇒ Object
- #community_id_attr ⇒ Object
- #get_class_for_item_type(type) ⇒ Object
- #get_item_type(obj) ⇒ Object
- #get_owner_type(obj) ⇒ Object
- #post_class ⇒ Object
- #user_class ⇒ Object
- #user_id_attr ⇒ Object
Instance Method Details
#category_class ⇒ Object
68 69 70 |
# File 'lib/common/base.rb', line 68 def category_class Object.const_get ::Inkwell::Engine::config.category_table.to_s.singularize.capitalize end |
#check_post(obj) ⇒ Object
43 44 45 46 |
# File 'lib/common/base.rb', line 43 def check_post(obj) post_class = Object.const_get ::Inkwell::Engine::config.post_table.to_s.singularize.capitalize raise "post should be a #{user_class.to_s}" unless obj.is_a? post_class end |
#check_user(obj) ⇒ Object
38 39 40 41 |
# File 'lib/common/base.rb', line 38 def check_user(obj) user_class = Object.const_get ::Inkwell::Engine::config.user_table.to_s.singularize.capitalize raise "user should be a #{user_class.to_s}" unless obj.is_a? user_class end |
#community_class ⇒ Object
64 65 66 |
# File 'lib/common/base.rb', line 64 def community_class Object.const_get ::Inkwell::Engine::config.community_table.to_s.singularize.capitalize end |
#community_id_attr ⇒ Object
60 61 62 |
# File 'lib/common/base.rb', line 60 def community_id_attr "#{::Inkwell::Engine::config.community_table.to_s.singularize}_id" end |
#get_class_for_item_type(type) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/common/base.rb', line 15 def get_class_for_item_type(type) case type when ::Inkwell::Constants::ItemTypes::COMMENT result = ::Inkwell::Comment when ::Inkwell::Constants::ItemTypes::POST result = post_class else raise "obj type #{type} is unknown" end result end |
#get_item_type(obj) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/common/base.rb', line 3 def get_item_type(obj) case obj when ::Inkwell::Comment result = ::Inkwell::Constants::ItemTypes::COMMENT when post_class result = ::Inkwell::Constants::ItemTypes::POST else raise "obj should be Comment or #{post_class.to_s}" end result end |
#get_owner_type(obj) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/common/base.rb', line 26 def get_owner_type(obj) case obj when user_class result = ::Inkwell::Constants::OwnerTypes::USER when community_class result = ::Inkwell::Constants::OwnerTypes::COMMUNITY else raise "obj should be #{user_class.to_s} or #{community_class.to_s}" end result end |
#post_class ⇒ Object
56 57 58 |
# File 'lib/common/base.rb', line 56 def post_class Object.const_get ::Inkwell::Engine::config.post_table.to_s.singularize.capitalize end |