Class: Hippo::Screen::Definition

Inherits:
Object
  • Object
show all
Includes:
Concerns::AttrAccessorWithDefault
Defined in:
lib/hippo/screen/definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_idObject

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_jsonObject



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_pathObject



50
51
52
# File 'lib/hippo/screen/definition.rb', line 50

def asset_path
    (asset && asset =~ /\//) ? asset : "#{@extension_id}/screens/#{asset || identifier}"
end

#groupObject



27
28
29
# File 'lib/hippo/screen/definition.rb', line 27

def group
    GROUPS[@group_id]
end

#has_file_matching?(pattern) ⇒ Boolean

Returns:

  • (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

#modelObject



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_pathObject



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_jsonObject



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

Returns:

  • (Boolean)


46
47
48
# File 'lib/hippo/screen/definition.rb', line 46

def viewable_by?(user)
    model.nil? || user.can_read?(self)
end