Class: Pigeon::VerboiceChannel

Inherits:
Channel
  • Object
show all
Defined in:
app/models/pigeon/verboice_channel.rb

Instance Attribute Summary

Attributes inherited from Channel

#attributes, #schema

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Channel

#[], #[]=, all, #assign_attributes, channel_accessor, #destroyed?, find, find_schema, find_type, first, #generate_name, #generate_name!, #human_attribute_name, i18n_scope, #initialize, #known_attributes, last, #method_missing, #new_record?, #persisted?, #read_attribute, #read_attribute_for_validation, #save!, schemas, #type, #write_attribute

Methods included from NestedScopes

#find_attr_recursive, #find_attr_ref_recursive, #fold_scoped_name

Constructor Details

This class inherits a constructor from Pigeon::Channel

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Pigeon::Channel

Class Method Details

.listObject



17
18
19
# File 'app/models/pigeon/verboice_channel.rb', line 17

def list
  verboice.list_channels
end

.typeObject



5
# File 'app/models/pigeon/verboice_channel.rb', line 5

def type() :verboice end

.verboiceObject



21
22
23
# File 'app/models/pigeon/verboice_channel.rb', line 21

def verboice
  @verboice ||= ::Pigeon::Verboice.from_config
end

Instance Method Details

#destroyObject



74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/models/pigeon/verboice_channel.rb', line 74

def destroy
  if !destroyed?
    begin
      if persisted?
        self.class.verboice.delete_channel(name)
      end
      @destroyed = true
    rescue Pigeon::VerboiceException => e
      Rails.logger.warn "error deleting Verboice channel: #{e.message}"
    end
  end
end

#limitObject



44
45
46
# File 'app/models/pigeon/verboice_channel.rb', line 44

def limit
  config[:limit].to_i || 1
end

#saveObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/pigeon/verboice_channel.rb', line 48

def save
  return false unless valid?

  begin
    if !persisted?
      self.class.verboice.create_channel attributes
      @persisted = true
    else
      self.class.verboice.update_channel attributes
    end
    true
  rescue Pigeon::VerboiceException => e
    Rails.logger.warn "error saving Verboice channel: #{e.message}"
    e.properties.each do |name, message|
      if attributes.include? name
        errors.add name, message
      elsif config.include? name
        errors.add "config[#{name}]", message
      else
        errors.add :base, "#{name} #{message}"
      end
    end
    false
  end
end

#schemasObject



8
9
10
# File 'app/models/pigeon/verboice_channel.rb', line 8

def schemas
  load_schemas
end