Class: AssetSync::Config

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/asset_sync/config.rb

Defined Under Namespace

Classes: Invalid

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



16
17
18
19
20
# File 'lib/asset_sync/config.rb', line 16

def initialize
  self.fog_provider = "AWS"
  self.existing_remote_files = "keep"
  load_yml! if yml_exists?
end

Instance Attribute Details

#aws_access_key_idObject

Returns the value of attribute aws_access_key_id.



8
9
10
# File 'lib/asset_sync/config.rb', line 8

def aws_access_key_id
  @aws_access_key_id
end

#aws_secret_access_keyObject

Returns the value of attribute aws_secret_access_key.



8
9
10
# File 'lib/asset_sync/config.rb', line 8

def aws_secret_access_key
  @aws_secret_access_key
end

#existing_remote_filesObject

Returns the value of attribute existing_remote_files.



10
11
12
# File 'lib/asset_sync/config.rb', line 10

def existing_remote_files
  @existing_remote_files
end

#fog_directoryObject

Returns the value of attribute fog_directory.



7
8
9
# File 'lib/asset_sync/config.rb', line 7

def fog_directory
  @fog_directory
end

#fog_providerObject

Returns the value of attribute fog_provider.



7
8
9
# File 'lib/asset_sync/config.rb', line 7

def fog_provider
  @fog_provider
end

#fog_regionObject

Returns the value of attribute fog_region.



7
8
9
# File 'lib/asset_sync/config.rb', line 7

def fog_region
  @fog_region
end

#rackspace_api_keyObject

Returns the value of attribute rackspace_api_key.



9
10
11
# File 'lib/asset_sync/config.rb', line 9

def rackspace_api_key
  @rackspace_api_key
end

#rackspace_usernameObject

Returns the value of attribute rackspace_username.



9
10
11
# File 'lib/asset_sync/config.rb', line 9

def rackspace_username
  @rackspace_username
end

Instance Method Details

#existing_remote_files?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/asset_sync/config.rb', line 22

def existing_remote_files?
  (self.existing_remote_files == "keep")
end

#fog_optionsObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/asset_sync/config.rb', line 49

def fog_options
  if fog_provider == "AWS"
    options = {
      :provider              => fog_provider,
      :aws_access_key_id     => aws_access_key_id,
      :aws_secret_access_key => aws_secret_access_key,
    }
  elsif fog_provider == "Rackspace"
    options = {
      :provider              => fog_provider,
      :rackspace_username    => rackspace_username,
      :rackspace_api_key     => rackspace_api_key
    }
  else
    raise ArgumentError, "Unknown provider: #{fog_provider}"
  end

  options.merge!({:region => fog_region}) if fog_region
  return options
end

#load_yml!Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/asset_sync/config.rb', line 38

def load_yml!
  self.fog_provider          = yml["fog_provider"]
  self.fog_directory         = yml["fog_directory"]
  self.fog_region            = yml["fog_region"]
  self.aws_access_key_id     = yml["aws_access_key_id"]
  self.aws_secret_access_key = yml["aws_secret_access_key"]
  self.rackspace_username    = yml["rackspace_username"]
  self.rackspace_api_key     = yml["rackspace_api_key"]
  self.existing_remote_files = yml["existing_remote_files"]
end

#ymlObject



30
31
32
# File 'lib/asset_sync/config.rb', line 30

def yml
  y ||= YAML.load(ERB.new(IO.read(yml_path)).result)[Rails.env] rescue nil || {}
end

#yml_exists?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/asset_sync/config.rb', line 26

def yml_exists?
  File.exists?(self.yml_path)
end

#yml_pathObject



34
35
36
# File 'lib/asset_sync/config.rb', line 34

def yml_path
  File.join(Rails.root, "config/asset_sync.yml")
end