Class: PolicyManager::Script

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Serialization
Defined in:
lib/policy_manager/script.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Script

Returns a new instance of Script.



13
14
15
16
17
18
19
20
21
22
# File 'lib/policy_manager/script.rb', line 13

def initialize(opts={})
  self.name = opts[:name]
  self.script = opts[:script]
  self.cookies = opts[:cookies]
  self.environments = opts[:environments]
  self.description = opts[:description]
  self.permanent = opts[:permanent]
  self.domain = opts[:domain]
  self
end

Instance Attribute Details

#cookiesObject

Returns the value of attribute cookies.



5
6
7
# File 'lib/policy_manager/script.rb', line 5

def cookies
  @cookies
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/policy_manager/script.rb', line 5

def description
  @description
end

#domainObject

Returns the value of attribute domain.



5
6
7
# File 'lib/policy_manager/script.rb', line 5

def domain
  @domain
end

#environmentsObject

Returns the value of attribute environments.



5
6
7
# File 'lib/policy_manager/script.rb', line 5

def environments
  @environments
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/policy_manager/script.rb', line 5

def name
  @name
end

#permanentObject

Returns the value of attribute permanent.



5
6
7
# File 'lib/policy_manager/script.rb', line 5

def permanent
  @permanent
end

#scriptObject

Returns the value of attribute script.



5
6
7
# File 'lib/policy_manager/script.rb', line 5

def script
  @script
end

Class Method Details

.cookiesObject



39
40
41
42
43
# File 'lib/policy_manager/script.rb', line 39

def self.cookies
  PolicyManager::Config
                .scripts
                .select{|o| o.cookies.present? }
end

.cookies_permanentObject



45
46
47
48
49
# File 'lib/policy_manager/script.rb', line 45

def self.cookies_permanent
  PolicyManager::Config
                .scripts
                .select{|o| o.cookies.present? && o.permanent? }
end

.scriptsObject



51
52
53
# File 'lib/policy_manager/script.rb', line 51

def self.scripts
  PolicyManager::Config.scripts.select{|o| o.script.present?}
end

Instance Method Details

#as_json(opts = {}) ⇒ Object



32
33
34
35
36
37
# File 'lib/policy_manager/script.rb', line 32

def as_json(opts={})
  data = {}
  fields = [:script, :name, :cookies, :description]
  fields.each { |k| data[k] = send(k) }
  data
end

#can_render?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/policy_manager/script.rb', line 24

def can_render?
  self.environments.map(&:to_s).include?(Rails.env)
end