Class: AdminModule::Ppms
- Inherits:
-
Object
- Object
- AdminModule::Ppms
- Defined in:
- lib/admin_module/ppms.rb
Instance Attribute Summary collapse
-
#page_factory ⇒ Object
readonly
Returns the value of attribute page_factory.
Instance Method Summary collapse
- #dups ⇒ Object
- #export(file_path) ⇒ Object
-
#import(file_path) ⇒ Object
Import lock configurations into the current environment from a file.
-
#initialize(page_factory) ⇒ Ppms
constructor
A new instance of Ppms.
- #list ⇒ Object
Constructor Details
#initialize(page_factory) ⇒ Ppms
Returns a new instance of Ppms.
16 17 18 |
# File 'lib/admin_module/ppms.rb', line 16 def initialize(page_factory) @page_factory = page_factory end |
Instance Attribute Details
#page_factory ⇒ Object (readonly)
Returns the value of attribute page_factory.
14 15 16 |
# File 'lib/admin_module/ppms.rb', line 14 def page_factory @page_factory end |
Instance Method Details
#dups ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/admin_module/ppms.rb', line 24 def dups all_ppms = ppms_page.get_ppms_with_ids seen = Hash.new duplicates = Array.new all_ppms.each do |pdata| if seen.has_key?(pdata[:name]) duplicates << pdata duplicates << seen[pdata[:name]] end seen[pdata[:name]] = pdata end duplicates.sort! { |a,b| a[:name] <=> b[:name] } end |
#export(file_path) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/admin_module/ppms.rb', line 42 def export file_path File.open(file_path, 'w') do |f| f.write list.to_yaml end rescue Exception => e if e..include? 'No such file or directory' raise IOError, "No such directory - #{file_path}" else raise e end end |
#import(file_path) ⇒ Object
Import lock configurations into the current environment from a file.
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/admin_module/ppms.rb', line 58 def import file_path raise IOError, "File not found: #{file_path}" unless File.exists?(file_path) ppms = Array.new File.open(file_path, 'r') do |f| # Read array of PPM names ppms = YAML.load(f) end ppms_page .set_ppms_data(ppms) .save end |
#list ⇒ Object
20 21 22 |
# File 'lib/admin_module/ppms.rb', line 20 def list ppms_page.get_ppms_data end |