Class: Hippo::Screen::Definition
- Inherits:
-
Object
- Object
- Hippo::Screen::Definition
- Includes:
- Concerns::AttrAccessorWithDefault
- Defined in:
- lib/hippo/screen/definition.rb
Instance Attribute Summary collapse
-
#extension_id ⇒ Object
Returns the value of attribute extension_id.
Instance Method Summary collapse
- #as_json ⇒ Object
- #asset_path ⇒ Object
- #group ⇒ Object
- #has_file_matching?(pattern) ⇒ Boolean
-
#initialize(id, extension_id) ⇒ Definition
constructor
A new instance of Definition.
- #model ⇒ Object
- #root_path ⇒ Object
- #to_json ⇒ Object
- #viewable_by?(user) ⇒ Boolean
Constructor Details
#initialize(id, extension_id) ⇒ Definition
Returns a new instance of Definition.
22 23 24 25 26 |
# File 'lib/hippo/screen/definition.rb', line 22 def initialize(id, extension_id) self.identifier = id @extension_id = extension_id @extension = extension_id.underscore.camelize end |
Instance Attribute Details
#extension_id ⇒ Object
Returns the value of attribute extension_id.
20 21 22 |
# File 'lib/hippo/screen/definition.rb', line 20 def extension_id @extension_id end |
Instance Method Details
#as_json ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/hippo/screen/definition.rb', line 58 def as_json { id: identifier, title: title, icon: icon, model: model_class, view: view_class, access: model_access, group_id: group_id, extension: extension, description: description, asset: asset_path } end |
#asset_path ⇒ Object
54 55 56 |
# File 'lib/hippo/screen/definition.rb', line 54 def asset_path (asset && asset =~ /\//) ? asset : "#{@extension_id}/screens/#{asset || identifier}" end |
#group ⇒ Object
28 29 30 |
# File 'lib/hippo/screen/definition.rb', line 28 def group GROUPS[@group_id] end |
#has_file_matching?(pattern) ⇒ Boolean
32 33 34 |
# File 'lib/hippo/screen/definition.rb', line 32 def has_file_matching?(pattern) Pathname.glob(root_path.join(pattern)).any? end |
#model ⇒ Object
42 43 44 45 |
# File 'lib/hippo/screen/definition.rb', line 42 def model return nil if @model_class.blank? @model_class.safe_constantize || (@extension_id.camelize + '::' + @model_class).safe_constantize end |
#root_path ⇒ Object
36 37 38 39 40 |
# File 'lib/hippo/screen/definition.rb', line 36 def root_path ext = Hippo::Extensions.for_identifier(@extension_id) raise "Unable to find extension '#{@extension_id}' for screen group" unless ext ext.root_path.join('client', url_prefix, identifier) end |
#to_json ⇒ Object
73 74 75 |
# File 'lib/hippo/screen/definition.rb', line 73 def to_json Oj.dump(as_json, mode: :compat) end |
#viewable_by?(user) ⇒ Boolean
47 48 49 50 51 52 |
# File 'lib/hippo/screen/definition.rb', line 47 def viewable_by?(user) if roles.present? return (roles & user.role_names).any? end model.nil? || user.can_read?(self) end |