active_force 0.0.1.alfa

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_force.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Eloy Espinaco
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # ActiveForce [![Code Climate](https://codeclimate.com/github/eloyesp/active_force.png)](https://codeclimate.com/github/eloyesp/active_force)
2
+ TODO: Write a gem description
3
+
4
+ ## Installation
5
+
6
+ Add this line to your application's Gemfile:
7
+
8
+ gem 'active_force'
9
+
10
+ And then execute:
11
+
12
+ $ bundle
13
+
14
+ Or install it yourself as:
15
+
16
+ $ gem install active_force
17
+
18
+ ## Usage
19
+
20
+ TODO: Write usage instructions here
21
+
22
+ ## Contributing
23
+
24
+ 1. Fork it
25
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
26
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
27
+ 4. Push to the branch (`git push origin my-new-feature`)
28
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_force/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "active_force"
8
+ spec.version = ActiveForce::VERSION
9
+ spec.authors = ["Eloy Espinaco"]
10
+ spec.email = ["eloyesp@gmail.com"]
11
+ spec.description = %q{Use SalesForce as an ActiveModel}
12
+ spec.summary = %q{Help you implement models persisting on Sales Force within Rails using RESTForce}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,26 @@
1
+ require 'active_support'
2
+ require 'active_model/dirty'
3
+ require 'active_attr'
4
+
5
+ module ActiveAttr
6
+ module Dirty
7
+ extend ActiveSupport::Concern
8
+ include ActiveModel::Dirty
9
+
10
+ module ClassMethods
11
+ def attribute!(name, options={})
12
+ super(name, options)
13
+ define_method("#{name}=") do |value|
14
+ send("#{name}_will_change!") unless value == read_attribute(name)
15
+ super(value)
16
+ end
17
+ end
18
+ end
19
+
20
+ def initialize(attributes = nil, options = {})
21
+ super(attributes, options)
22
+ changed_attributes.clear
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,5 @@
1
+ require "active_force/version"
2
+
3
+ module ActiveForce
4
+ # Your code goes here...
5
+ end
@@ -0,0 +1,54 @@
1
+ require 'active_attr/dirty'
2
+
3
+ module ActiveForce
4
+ class SObject
5
+ include ActiveAttr::Model
6
+ include ActiveAttr::Dirty
7
+
8
+ class_attribute :mappings, :fields, :table_name
9
+
10
+ attribute :id
11
+
12
+ def self.build sobject
13
+ return nil if sobject.nil?
14
+ model = new
15
+ mappings.each do |attr, sf_field|
16
+ model[attr] = sobject[sf_field]
17
+ end
18
+ model.changed_attributes.clear
19
+ model
20
+ end
21
+
22
+ def self.find id
23
+ build Client.query(<<-SOQL.strip_heredoc).first
24
+ SELECT #{fields.join(', ')}
25
+ FROM #{table_name}
26
+ WHERE Id = '#{id}'
27
+ SOQL
28
+ end
29
+
30
+ def update_attributes attributes
31
+ assign_attributes attributes
32
+ if valid?
33
+ sobject_hash = { 'Id' => id }
34
+ changed.each do |field|
35
+ sobject_hash[mappings[field.to_sym]] = read_attribute(field)
36
+ end
37
+ result = Client.update table_name, sobject_hash
38
+ changed_attributes.clear if result
39
+ result
40
+ else
41
+ false
42
+ end
43
+ end
44
+
45
+ def to_param
46
+ id
47
+ end
48
+
49
+ def persisted?
50
+ id?
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,3 @@
1
+ module ActiveForce
2
+ VERSION = "0.0.1.alfa"
3
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Generate a model to interact with Sales Force.
3
+
4
+ Example:
5
+ rails generate active_force_model Account
6
+
7
+ This will create:
8
+ app/models/account.rb
@@ -0,0 +1,22 @@
1
+ class ActiveForce::ActiveForceModelGenerator < Rails::Generators::NamedBase
2
+
3
+ Attribute = Struct.new(:local_name, :remote_name)
4
+
5
+ source_root File.expand_path('../templates', __FILE__)
6
+ argument :attributes, type: :array, default: [],
7
+ banner: "field[:sales_force_name] field[:sales_force_name]"
8
+
9
+ def create_model_file
10
+ template "model.rb.erb", "app/models/#{file_name}.rb"
11
+ end
12
+
13
+ protected
14
+
15
+ def parse_attributes! #:nodoc:
16
+ self.attributes = (attributes || []).map do |attr|
17
+ name, sales_force_name = attr.split ':', 2
18
+ remote_name = sales_force_name.presence || name
19
+ Attribute.new name, remote_name
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'active_force/sobject'
2
+
3
+ class <%= class_name %> < ActiveForce::SObject
4
+
5
+ MAPPINGS = {
6
+ <% attributes.each do |attribute| -%>
7
+ <%= attribute.local_name %>: '<%= attribute.remote_name %>',
8
+ <% end -%>
9
+ id: 'Id'
10
+ }
11
+ FIELDS = MAPPINGS.values
12
+ RELATED_LIST_FIELDS = FIELDS
13
+
14
+ self.mappings = MAPPINGS
15
+ self.fields = FIELDS
16
+ self.table_name = '<%= class_name %>'
17
+
18
+ <% attributes.each do |attribute| -%>
19
+ attribute :<%= attribute.local_name %>
20
+ <% end -%>
21
+
22
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe ActiveForce do
4
+ it 'should have a version number' do
5
+ ActiveForce::VERSION.should_not be_nil
6
+ end
7
+
8
+ it 'should do something useful' do
9
+ false.should be_true
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'active_force'
metadata ADDED
@@ -0,0 +1,116 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: active_force
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alfa
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Eloy Espinaco
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Use SalesForce as an ActiveModel
63
+ email:
64
+ - eloyesp@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - .rspec
71
+ - .travis.yml
72
+ - Gemfile
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - active_force.gemspec
77
+ - lib/active_attr/dirty.rb
78
+ - lib/active_force.rb
79
+ - lib/active_force/sobject.rb
80
+ - lib/active_force/version.rb
81
+ - lib/generators/active_force/active_force_model/USAGE
82
+ - lib/generators/active_force/active_force_model/active_force_model_generator.rb
83
+ - lib/generators/active_force/active_force_model/templates/model.rb.erb
84
+ - spec/active_force_spec.rb
85
+ - spec/spec_helper.rb
86
+ homepage: ''
87
+ licenses:
88
+ - MIT
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ segments:
100
+ - 0
101
+ hash: -327734206455115732
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>'
106
+ - !ruby/object:Gem::Version
107
+ version: 1.3.1
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 1.8.24
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Help you implement models persisting on Sales Force within Rails using RESTForce
114
+ test_files:
115
+ - spec/active_force_spec.rb
116
+ - spec/spec_helper.rb