Class: HasHelpers::OrganizationLink
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- HasHelpers::OrganizationLink
- Defined in:
- app/models/has_helpers/organization_link.rb
Instance Attribute Summary collapse
-
#placeholder ⇒ Object
Returns the value of attribute placeholder.
Instance Method Summary collapse
-
#available_resources ⇒ Object
instance methods ######.
- #has_access?(user) ⇒ Boolean
-
#placeholders ⇒ Object
overrided on agencies initializer to use webhook placeholders.
- #replaced_placeholder_url(base_resource) ⇒ Object
- #teams ⇒ Object
- #url_value ⇒ Object
Instance Attribute Details
#placeholder ⇒ Object
Returns the value of attribute placeholder.
10 11 12 |
# File 'app/models/has_helpers/organization_link.rb', line 10 def placeholder @placeholder end |
Instance Method Details
#available_resources ⇒ Object
instance methods ######
42 43 44 45 46 47 |
# File 'app/models/has_helpers/organization_link.rb', line 42 def available_resources HasHelpers::Resource.where( resource_type_id: "HasHelpers::ResourceType::::Base", application_id: ::HasHelpers::Application.current_application.id ) end |
#has_access?(user) ⇒ Boolean
58 59 60 |
# File 'app/models/has_helpers/organization_link.rb', line 58 def has_access?(user) persisted? && (try("team").blank? || try("team").users.include?(user) || user.is_super_user?) end |
#placeholders ⇒ Object
overrided on agencies initializer to use webhook placeholders
50 51 52 |
# File 'app/models/has_helpers/organization_link.rb', line 50 def placeholders [{ name: "Id", value: "id" }] end |
#replaced_placeholder_url(base_resource) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'app/models/has_helpers/organization_link.rb', line 68 def replaced_placeholder_url(base_resource) return url if resource.blank? view = Mustache.new view.template = url.gsub(/{{(?<control_char>[\/#!\^]?)\s*(?<key>.+?)\s*}}/) { "{{#{ $~[:control_char] } #{ normalize_key($~[:key]) } }}" } view.template..map do |name| value = base_resource.try(name.to_sym) view[name.to_sym] = value end view.render end |
#teams ⇒ Object
54 55 56 |
# File 'app/models/has_helpers/organization_link.rb', line 54 def teams [] end |
#url_value ⇒ Object
62 63 64 65 66 |
# File 'app/models/has_helpers/organization_link.rb', line 62 def url_value if placeholder.present? self.url += self.url.end_with?("/") ? "{{#{placeholder}}}" : "/{{#{placeholder}}}" end end |