Module: SData

Defined in:
lib/s_data/namespace_definitions.rb,
lib/s_data.rb,
lib/s_data/payload.rb,
lib/s_data/predicate.rb,
lib/s_data/exceptions.rb,
lib/s_data/formatting.rb,
lib/s_data/route_mapper.rb,
lib/s_data/router_mixin.rb,
lib/s_data/virtual_base.rb,
lib/s_data/controller_mixin.rb,
lib/s_data/diagnosis/diagnosis.rb,
lib/s_data/sync/controller_mixin.rb,
lib/s_data/payload_map/payload_map.rb,
lib/s_data/controller_mixin/actions.rb,
lib/s_data/sync/sdata_syncing_mixin.rb,
lib/s_data/diagnosis/diagnosis_mapper.rb,
lib/s_data/atom_extensions/nodes/digest.rb,
lib/s_data/controller_mixin/s_data_feed.rb,
lib/s_data/payload_map/payload_map_hash.rb,
lib/s_data/active_record_extensions/base.rb,
lib/s_data/atom_extensions/content_mixin.rb,
lib/s_data/atom_extensions/nodes/payload.rb,
lib/s_data/active_record_extensions/mixin.rb,
lib/s_data/atom_extensions/nodes/sync_state.rb,
lib/s_data/controller_mixin/s_data_instance.rb,
lib/s_data/controller_mixin/collection_scope.rb,
lib/s_data/diagnosis/application_controller_mixin.rb,
lib/s_data/active_record_extensions/sdata_uuid_mixin.rb

Overview

The following pre-sets the namespace prefix for simple extensions. It is done this way because the namespace map is lazily created in the Atom::Feed.to_xml method. Could also alias to_xml, and add all the namespaces in extensions_namespaces to this map

Defined Under Namespace

Modules: ActiveRecordExtensions, ApplicationControllerMixin, AtomExtensions, ControllerMixin, Exceptions, NamespaceMapMixin, PayloadMap, RouterMixin, Sync Classes: ApplicationDiagnosis, ApplicationNotFound, ApplicationUnavailable, BadQueryParameter, BadUrlSyntax, BadWhereSyntax, ContractNotFound, DatasetNotFound, Diagnosis, Formatting, Payload, Predicate, ResourceKindNotFound, RouteMapper, VirtualBase

Class Method Summary collapse

Class Method Details

.base_urlObject



74
75
76
# File 'lib/s_data.rb', line 74

def base_url
  config[:base_url].chomp('/')
end

.configObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/s_data.rb', line 26

def config
  unless @config
    @config = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'config','sdata.yml'))
    app_config_file = ENV['SDATA_CONFIG_FILE']
    app_config_file ||= File.join(RAILS_ROOT, 'config','sdata.yml') if defined?(RAILS_ROOT)
    @config = @config.deep_merge(YAML.load_file(app_config_file)) unless app_config_file.nil?
    @config = @config.with_indifferent_access
    @config[:contracts] ||= []
    @config[:defaultContract] ||= @config[:contracts].first
    @config[:defaultContract] ||= "crmErp"
    @config[:contract_namespace] ||= "SData::Contracts"        
  end
  @config
end

.config=(conf) ⇒ Object



41
42
43
# File 'lib/s_data.rb', line 41

def config=(conf)
  @config = conf.with_indifferent_access
end

.contract_namespacesObject



54
55
56
# File 'lib/s_data.rb', line 54

def contract_namespaces
  config[:contracts].map{|contract| "#{config[:contract_namespace]}::#{contract.camelize}"}
end

.endpointObject



78
79
80
# File 'lib/s_data.rb', line 78

def endpoint
  [base_url, store_path].join('/')
end

.reset!Object



82
83
84
# File 'lib/s_data.rb', line 82

def reset!
  @config = nil
end

.resource_class(klassname) ⇒ Object

this is pby expensive and will have to be optimized by using const_get directly RADAR: this assumes resource names are unique across contracts. To change that must refactor sd_uuid to either have a contract attr or pby better just store fully qualified name in sd_class



61
62
63
64
65
66
67
# File 'lib/s_data.rb', line 61

def resource_class(klassname)
  contract_namespaces.each do |ns|
    begin
      return "#{ns}::#{klassname}".constantize
    rescue;end
  end
end

.sdata_collection_url_component(klass) ⇒ Object



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

def sdata_collection_url_component(klass)
  SData.sdata_url_component(klass).pluralize
end

.sdata_contract_name(klassname) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/s_data.rb', line 45

def sdata_contract_name(klassname)
  if (klassname =~ /#{@config[:contract_namespace]}::([^:]*)::/)
    $~[1].camelize(:lower)
  else
    raise "Cannot determine sdata_contract_name for #{klassname}"
  end
end

.sdata_name(klass) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/s_data.rb', line 7

def sdata_name(klass)
  case klass
  when SData::VirtualBase
    klass.sdata_name
  when Class
    klass.respond_to?(:sdata_name) ? klass.sdata_name : nil
  when String
    klass.demodulize
  end
end

.sdata_url_component(klass) ⇒ Object



18
19
20
# File 'lib/s_data.rb', line 18

def sdata_url_component(klass)
  SData.sdata_name(klass).camelize(:lower)
end

.store_pathObject



69
70
71
72
# File 'lib/s_data.rb', line 69

def store_path
  #TODO: remove dataset=nil and modify calls accordingly. dataset should not be implied at this level
  ['sdata', config[:application], config[:defaultContract]].compact.join('/')
end