Class: Avo::Licensing::License

Inherits:
Object
  • Object
show all
Defined in:
lib/avo/licensing/license.rb

Direct Known Subclasses

CommunityLicense, NilLicense, ProLicense

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response = {}) ⇒ License

Returns a new instance of License.



9
10
11
12
13
14
# File 'lib/avo/licensing/license.rb', line 9

def initialize(response = {})
  @response = response
  @id = response["id"]
  @valid = response["valid"]
  @payload = response["payload"]
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/avo/licensing/license.rb', line 4

def id
  @id
end

#payloadObject

Returns the value of attribute payload.



7
8
9
# File 'lib/avo/licensing/license.rb', line 7

def payload
  @payload
end

#responseObject

Returns the value of attribute response.



5
6
7
# File 'lib/avo/licensing/license.rb', line 5

def response
  @response
end

#validObject

Returns the value of attribute valid.



6
7
8
# File 'lib/avo/licensing/license.rb', line 6

def valid
  @valid
end

Instance Method Details

#abilitiesObject



40
41
42
# File 'lib/avo/licensing/license.rb', line 40

def abilities
  []
end

#advanced?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/avo/licensing/license.rb', line 28

def advanced?
  id == "advanced"
end

#can(ability) ⇒ Object Also known as: has



44
45
46
# File 'lib/avo/licensing/license.rb', line 44

def can(ability)
  abilities.include? ability
end

#cant(ability) ⇒ Object Also known as: lacks



48
49
50
# File 'lib/avo/licensing/license.rb', line 48

def cant(ability)
  !can ability
end

#errorObject



32
33
34
# File 'lib/avo/licensing/license.rb', line 32

def error
  @response["error"]
end

#has_with_trial(ability) ⇒ Object

Returns if has ability and if is a valid license or app is in development.



56
57
58
59
60
# File 'lib/avo/licensing/license.rb', line 56

def has_with_trial(ability)
  return can(ability) && valid? if Rails.env.production?

  true
end

#invalid?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/avo/licensing/license.rb', line 20

def invalid?
  !valid?
end

#lacks_with_trial(ability) ⇒ Object

Returns if lacks ability and if is a valid license or app is in development.



63
64
65
# File 'lib/avo/licensing/license.rb', line 63

def lacks_with_trial(ability)
  !has_with_trial ability
end

#nameObject



67
68
69
70
71
72
73
# File 'lib/avo/licensing/license.rb', line 67

def name
  if id.present?
    id.humanize
  else
    self.class.to_s.split("::").last.underscore.humanize.gsub " license", ""
  end
end

#pro?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/avo/licensing/license.rb', line 24

def pro?
  id == "pro"
end

#propertiesObject



36
37
38
# File 'lib/avo/licensing/license.rb', line 36

def properties
  @response.slice("valid", "id", "error").symbolize_keys
end

#valid?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/avo/licensing/license.rb', line 16

def valid?
  valid
end