Module: ModMonkey::Item::ActMethods
- Defined in:
- lib/modmonkey_client/item.rb
Instance Attribute Summary collapse
-
#editable_attrs ⇒ Object
Returns the value of attribute editable_attrs.
-
#mandatory_keys ⇒ Object
Returns the value of attribute mandatory_keys.
-
#mm_attr_store ⇒ Object
Returns the value of attribute mm_attr_store.
-
#optional_keys ⇒ Object
Returns the value of attribute optional_keys.
Instance Method Summary collapse
- #default_content_description ⇒ Object
- #find(*args) ⇒ Object
- #find_unmoderated ⇒ Object
- #make_moderatable(options = {}, &block) ⇒ Object
- #resource_url ⇒ Object
- #validate_keys(options) ⇒ Object
Instance Attribute Details
#editable_attrs ⇒ Object
Returns the value of attribute editable_attrs.
6 7 8 |
# File 'lib/modmonkey_client/item.rb', line 6 def editable_attrs @editable_attrs end |
#mandatory_keys ⇒ Object
Returns the value of attribute mandatory_keys.
7 8 9 |
# File 'lib/modmonkey_client/item.rb', line 7 def mandatory_keys @mandatory_keys end |
#mm_attr_store ⇒ Object
Returns the value of attribute mm_attr_store.
5 6 7 |
# File 'lib/modmonkey_client/item.rb', line 5 def mm_attr_store @mm_attr_store end |
#optional_keys ⇒ Object
Returns the value of attribute optional_keys.
8 9 10 |
# File 'lib/modmonkey_client/item.rb', line 8 def optional_keys @optional_keys end |
Instance Method Details
#default_content_description ⇒ Object
59 60 61 |
# File 'lib/modmonkey_client/item.rb', line 59 def default_content_description self.to_s.humanize end |
#find(*args) ⇒ Object
44 45 46 47 48 |
# File 'lib/modmonkey_client/item.rb', line 44 def find(*args) with_scope :find=>{:conditions=>"#{self.to_s.tableize}.mm_approved=1"} do super end end |
#find_unmoderated ⇒ Object
50 51 52 |
# File 'lib/modmonkey_client/item.rb', line 50 def find_unmoderated() find(:all, :conditions => "mm_id is null") end |
#make_moderatable(options = {}, &block) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/modmonkey_client/item.rb', line 10 def make_moderatable(={}, &block) self.mandatory_keys = [:content_type, :profile_info, :item_url] self.optional_keys = [:asset_url, :context_url, :content_description] # Process passed in options # These 'dynamic methods' are stored either as a lambda, proc, symbol for method, or ordinary variable validate_keys() self.editable_attrs = [:editable_attrs] || [] self.mm_attr_store = .select{|k,v| (mandatory_keys+optional_keys).include? k } unless included_modules.include?(Moderatable) before_create :set_default_approval_status after_create :create_mm_item after_update :update_mm_item after_destroy :destroy_mm_item attr_accessor :mm_update named_scope :approved, :conditions => {:mm_approved => true} include Moderatable ModMonkey::Moderatables.add(self) end end |
#resource_url ⇒ Object
54 55 56 57 |
# File 'lib/modmonkey_client/item.rb', line 54 def resource_url # File.join(::ModMonkey::Config.api_domain, 'accounts', ::ModMonkey::Config.api_key, "items") File.join(MM_API_DOMAIN, 'accounts', MM_API_KEY, "items") end |
#validate_keys(options) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/modmonkey_client/item.rb', line 33 def validate_keys() unless (.keys | self.mandatory_keys) == .keys raise ArgumentError, "make_moderatable needs the following mandatory keys: #{(mandatory_keys).join(', ')}" end if [:profile_info] && ![:profile_info].is_a?(Symbol) && [:profile_info][:profile_url].blank? raise ArgumentError, "make_moderatable needs the profile_url to be specified" end end |