Class: Linguist::Models::Project
- Inherits:
-
Object
- Object
- Linguist::Models::Project
- Defined in:
- lib/linguist_ruby/models/project.rb
Class Method Summary collapse
Instance Method Summary collapse
- #collaborators ⇒ Object
- #create!(attributes = {}) ⇒ Object
- #destroy ⇒ Object
-
#initialize(client, link) ⇒ Project
constructor
A new instance of Project.
- #invite_collaborator(email) ⇒ Object
- #pull_resource(dir, file_name) ⇒ Object
- #push_resource(path, locale) ⇒ Object
- #resources ⇒ Object
- #update(attributes = {}) ⇒ Object
Constructor Details
#initialize(client, link) ⇒ Project
Returns a new instance of Project.
23 24 25 26 |
# File 'lib/linguist_ruby/models/project.rb', line 23 def initialize(client, link) @client = client @link = link end |
Class Method Details
.lazy_attr_accessor(*params) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/linguist_ruby/models/project.rb', line 7 def self.lazy_attr_accessor(*params) params.each do |sym| define_method(sym) do unless defined? @fetched fetch end self.instance_variable_get("@#{sym}") end define_method("#{sym}=") do |value| self.instance_variable_set("@#{sym}", value) end end end |
Instance Method Details
#collaborators ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/linguist_ruby/models/project.rb', line 57 def collaborators unless defined? @collaborators @collaborators = [] response = @client.get(self.collaborators_url) resource_hash = JSON.parse(response) members = resource_hash["collaborators"]["members"] members.each do |member| link = member["link"]["href"] rescue "" collaborator = Linguist::Models::Collaborator.new(@client, link) collaborator.email = member["email"] collaborator.display_name = member["display_name"] collaborator.roles = member["roles"] @collaborators << collaborator end end @collaborators end |
#create!(attributes = {}) ⇒ Object
28 29 30 |
# File 'lib/linguist_ruby/models/project.rb', line 28 def create!(attributes={}) self.title = attribtes[:title] end |
#destroy ⇒ Object
32 33 34 |
# File 'lib/linguist_ruby/models/project.rb', line 32 def destroy @client.delete self.link end |
#invite_collaborator(email) ⇒ Object
40 41 42 |
# File 'lib/linguist_ruby/models/project.rb', line 40 def invite_collaborator(email) @client.post(self.invitations_url, :invitation => {:email => email}) end |
#pull_resource(dir, file_name) ⇒ Object
75 76 77 78 |
# File 'lib/linguist_ruby/models/project.rb', line 75 def pull_resource(dir, file_name) raise "Project does not contain that file." unless self.resources.has_key?(file_name) save_to_file(File.join(dir, file_name), self.resources[file_name].content) end |
#push_resource(path, locale) ⇒ Object
80 81 82 83 84 85 |
# File 'lib/linguist_ruby/models/project.rb', line 80 def push_resource(path, locale) raise "Path #{path} does not exists" unless File.exists?(path) request = { :file => File.new(path, "rb") } request.merge!({ :iso2_slug => locale }) if locale @client.post(self.resources_url, request) end |
#resources ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/linguist_ruby/models/project.rb', line 44 def resources unless defined? @resources @resources = {} response = @client.get(self.resources_url) resource_hash = JSON.parse(response) members = resource_hash["resources"]["members"] members.each do |member| @resources[member["name"]] = Linguist::Models::Resource.new(@client, member["link"]["href"]) end end @resources end |
#update(attributes = {}) ⇒ Object
36 37 38 |
# File 'lib/linguist_ruby/models/project.rb', line 36 def update(attributes={}) @client.put self.link, {:project => attributes} end |