Class: Service

Inherits:
Object
  • Object
show all
Includes:
HasHelpers::Attributes::AttributeAssignment, HasHelpers::UIAttributes
Defined in:
lib/has_helpers/utils/service.rb

Overview

typed: true frozen_string_literal: true

Instance Attribute Summary collapse

Attributes included from HasHelpers::UIAttributes::HTMLAttributes

#data, #skin

Instance Method Summary collapse

Methods included from HasHelpers::Attributes::GuardedAttributes

included

Methods included from HasHelpers::Attributes::AttributeAssignment

#assign_attributes

Constructor Details

#initialize(name, **options) ⇒ Service

Handle options passed to new. Hash args are assigned to attributes like ActiveRecord does.

Examples

Service.new("http://derp.com") Service.new("Derp", :url => "http://derp.com") Service.new("Derp", :url => "http://derp.com", :external => true)



17
18
19
20
# File 'lib/has_helpers/utils/service.rb', line 17

def initialize(name, **options)
  @name = name
  assign_attributes(options)
end

Instance Attribute Details

#externalObject

Returns the value of attribute external.



7
8
9
# File 'lib/has_helpers/utils/service.rb', line 7

def external
  @external
end

#http_methodObject

Returns the value of attribute http_method.



7
8
9
# File 'lib/has_helpers/utils/service.rb', line 7

def http_method
  @http_method
end

#iconObject



51
52
53
# File 'lib/has_helpers/utils/service.rb', line 51

def icon
  @icon && @icon.to_icon
end

#icon_placementObject

:right or :left, default to :left



56
57
58
# File 'lib/has_helpers/utils/service.rb', line 56

def icon_placement
  @icon_placement == :right ? :right : :left
end

#nestedObject

Returns the value of attribute nested.



7
8
9
# File 'lib/has_helpers/utils/service.rb', line 7

def nested
  @nested
end

Instance Method Details

#==(other) ⇒ Object



79
80
81
82
83
84
85
86
# File 'lib/has_helpers/utils/service.rb', line 79

def ==(other)
  case other
  when self.class
    url == other.url && to_s == other.to_s
  else
    super
  end
end

#propsObject



70
71
72
73
74
75
76
77
# File 'lib/has_helpers/utils/service.rb', line 70

def props
  {}.tap do |hash|
    hash[:type] = "Service"
    hash[:icon] = icon
    hash[:url] = url
    hash[:children] = @name
  end.camelize_keys!
end

#raw_html_attrsObject



64
65
66
67
68
# File 'lib/has_helpers/utils/service.rb', line 64

def raw_html_attrs
  super.tap do |raw_attrs|
    raw_attrs.reverse_merge!(external: nil) if external
  end
end

#to_actionObject



43
44
45
# File 'lib/has_helpers/utils/service.rb', line 43

def to_action
  ::Action.new(service: self)
end

#to_partial_pathObject



47
48
49
# File 'lib/has_helpers/utils/service.rb', line 47

def to_partial_path
  "has_helpers/services/service"
end

#to_renderableObject



60
61
62
# File 'lib/has_helpers/utils/service.rb', line 60

def to_renderable
  self
end

#to_sObject



34
35
36
# File 'lib/has_helpers/utils/service.rb', line 34

def to_s
  @name
end

#to_service(**options) ⇒ Object



38
39
40
41
# File 'lib/has_helpers/utils/service.rb', line 38

def to_service(**options)
  assign_attributes(**options) # Apply any given attributes
  self
end

#urlObject

Returns the current url value or falls back to the current object. Note that if url is explicitly set to nil, then no fallback will be used, but rather nil will be returned.



30
31
32
# File 'lib/has_helpers/utils/service.rb', line 30

def url
  @url_cached ? @url : to_s
end

#url=(value) ⇒ Object



22
23
24
25
# File 'lib/has_helpers/utils/service.rb', line 22

def url=(value)
  @url_cached = true
  @url = value
end