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.
21 22 23 24 25 |
# File 'lib/hippo/screen/definition.rb', line 21 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.
19 20 21 |
# File 'lib/hippo/screen/definition.rb', line 19 def extension_id @extension_id end |
Instance Method Details
#as_json ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/hippo/screen/definition.rb', line 54 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
50 51 52 |
# File 'lib/hippo/screen/definition.rb', line 50 def asset_path (asset && asset =~ /\//) ? asset : "#{@extension_id}/screens/#{asset || identifier}" end |
#group ⇒ Object
27 28 29 |
# File 'lib/hippo/screen/definition.rb', line 27 def group GROUPS[@group_id] end |
#has_file_matching?(pattern) ⇒ Boolean
31 32 33 |
# File 'lib/hippo/screen/definition.rb', line 31 def has_file_matching?(pattern) Pathname.glob(root_path.join(pattern)).any? end |
#model ⇒ Object
41 42 43 44 |
# File 'lib/hippo/screen/definition.rb', line 41 def model return nil if @model_class.blank? @model_class.safe_constantize || (@extension_id.camelize + '::' + @model_class).safe_constantize end |
#root_path ⇒ Object
35 36 37 38 39 |
# File 'lib/hippo/screen/definition.rb', line 35 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
69 70 71 |
# File 'lib/hippo/screen/definition.rb', line 69 def to_json Oj.dump(as_json, mode: :compat) end |
#viewable_by?(user) ⇒ Boolean
46 47 48 |
# File 'lib/hippo/screen/definition.rb', line 46 def viewable_by?(user) model.nil? || user.can_read?(self) end |